• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

aimeos / aimeos-core / 4f8b7e8d-5595-43b2-ba5c-df9921830178

17 May 2026 07:32AM UTC coverage: 92.581%. Remained the same
4f8b7e8d-5595-43b2-ba5c-df9921830178

push

circleci

aimeos
Fixed PHPStan issues

896 of 980 new or added lines in 165 files covered. (91.43%)

35 existing lines in 29 files now uncovered.

9734 of 10514 relevant lines covered (92.58%)

80.53 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

96.67
/src/MShop/Order/Manager/Base.php
1
<?php
2

3
/**
4
 * @license LGPLv3, https://opensource.org/licenses/LGPL-3.0
5
 * @copyright Aimeos (aimeos.org), 2015-2026
6
 * @package MShop
7
 * @subpackage Order
8
 */
9

10

11
namespace Aimeos\MShop\Order\Manager;
12

13

14
/**
15
 * Basic methods and constants for order items (shopping basket).
16
 *
17
 * @package MShop
18
 * @subpackage Order
19
 */
20
abstract class Base extends \Aimeos\MShop\Common\Manager\Base
21
{
22
        /**
23
         * Returns the address item map for the given order IDs
24
         *
25
         * @param string[] $ids List of order IDs
26
         * @param array $ref List of referenced domains that should be fetched too
27
         * @return \Aimeos\Map Multi-dimensional associative list of order IDs as keys and order address ID/item pairs as values
28
         */
29
        protected function getAddresses( array $ids, array $ref ) : \Aimeos\Map
30
        {
31
                $manager = $this->object()->getSubManager( 'address' );
34✔
32

33
                $filter = $manager->filter()
34✔
34
                        ->add( 'order.address.parentid', '==', $ids )
34✔
35
                        ->order( ['order.address.type', 'order.address.position', 'order.address.id'] )
34✔
36
                        ->slice( 0, 0x7fffffff );
34✔
37

38
                // @phpstan-ignore argument.type
39
                return $manager->search( $filter, $ref )->groupBy( 'order.address.parentid' );
34✔
40
        }
41

42

43
        /**
44
         * Returns the coupon map for the given order IDs
45
         *
46
         * @param string[] $ids List of order IDs
47
         * @param array $ref List of referenced domains that should be fetched too
48
         * @return \Aimeos\Map Multi-dimensional associative list of order IDs as keys and order coupon ID/item pairs as values
49
         */
50
        protected function getCoupons( array $ids, array $ref ) : \Aimeos\Map
51
        {
52
                $manager = $this->object()->getSubManager( 'coupon' );
28✔
53

54
                $filter = $manager->filter()
28✔
55
                        ->add( 'order.coupon.parentid', '==', $ids )
28✔
56
                        ->order( 'order.coupon.code' )
28✔
57
                        ->slice( 0, 0x7fffffff );
28✔
58

59
                // @phpstan-ignore argument.type
60
                return $manager->search( $filter, $ref )->groupBy( 'order.coupon.parentid' );
28✔
61
        }
62

63

64
        /**
65
         * Retrieves the ordered products from the storage.
66
         *
67
         * @param string[] $ids List of order IDs
68
         * @param array $ref List of referenced domains that should be fetched too
69
         * @return \Aimeos\Map Multi-dimensional associative list of order IDs as keys and order product ID/item pairs as values
70
         */
71
        protected function getProducts( array $ids, array $ref ) : \Aimeos\Map
72
        {
73
                $manager = $this->object()->getSubManager( 'product' );
40✔
74

75
                $filter = $manager->filter()
40✔
76
                        ->add( 'order.product.parentid', '==', $ids )
40✔
77
                        ->order( 'order.product.position' )
40✔
78
                        ->slice( 0, 0x7fffffff );
40✔
79
                // @phpstan-ignore argument.type
80
                $items = $manager->search( $filter, $ref );
40✔
81
                $map = $items->groupBy( 'order.product.orderproductid' );
40✔
82

83
                foreach( $map as $id => $list ) {
40✔
84
                        $items[$id]?->setProducts( $list );
38✔
85
                }
86

87
                return map( $map->get( '' ) )->groupBy( 'order.product.parentid' );
40✔
88
        }
89

90

91
        /**
92
         * Retrieves the order services from the storage.
93
         *
94
         * @param string[] $ids List of order IDs
95
         * @param array $ref List of referenced domains that should be fetched too
96
         * @return \Aimeos\Map Multi-dimensional associative list of order IDs as keys and service ID/item pairs as values
97
         */
98
        protected function getServices( array $ids, array $ref ) : \Aimeos\Map
99
        {
100
                $manager = $this->object()->getSubManager( 'service' );
35✔
101

102
                $filter = $manager->filter()
35✔
103
                        ->add( 'order.service.parentid', '==', $ids )
35✔
104
                        ->order( ['order.service.type', 'order.service.position', 'order.service.id'] )
35✔
105
                        ->slice( 0, 0x7fffffff );
35✔
106

107
                // @phpstan-ignore argument.type
108
                return $manager->search( $filter, $ref )->groupBy( 'order.service.parentid' );
35✔
109
        }
110

111

112
        /**
113
         * Retrieves the order statuses from the storage.
114
         *
115
         * @param string[] $ids List of order IDs
116
         * @param array $ref List of referenced domains that should be fetched too
117
         * @return \Aimeos\Map Multi-dimensional associative list of order IDs as keys and order status ID/item pairs as values
118
         */
119
        protected function getStatuses( array $ids, array $ref ) : \Aimeos\Map
120
        {
121
                $manager = $this->object()->getSubManager( 'status' );
1✔
122

123
                $filter = $manager->filter()
1✔
124
                        ->add( 'order.status.parentid', '==', $ids )
1✔
125
                        ->slice( 0, 0x7fffffff );
1✔
126

127
                // @phpstan-ignore argument.type
128
                return $manager->search( $filter, $ref )->groupBy( 'order.status.parentid' );
1✔
129
        }
130

131

132
        /**
133
         * Saves the addresses of the order to the storage.
134
         *
135
         * @param \Aimeos\MShop\Order\Item\Iface $item Order containing address items
136
         * @return static Manager object for chaining method calls
137
         */
138
        protected function saveAddresses( \Aimeos\MShop\Order\Item\Iface $item ) : static
139
        {
140
                $addresses = $item->getAddresses();
11✔
141

142
                foreach( $addresses as $type => $list )
11✔
143
                {
144
                        $pos = 0;
5✔
145

146
                        foreach( $list as $address )
5✔
147
                        {
148
                                if( $address->getParentId() != $item->getId() ) {
5✔
149
                                        $address->setId( null ); // create new item if copied
5✔
150
                                }
151

152
                                $address->setParentId( $item->getId() )->setPosition( ++$pos );
5✔
153
                        }
154
                }
155

156
                $this->object()->getSubManager( 'address' )->save( $addresses->flat( 1 ) );
11✔
157

158
                return $this;
11✔
159
        }
160

161

162
        /**
163
         * Saves the coupons of the order to the storage.
164
         *
165
         * @param \Aimeos\MShop\Order\Item\Iface $item Order containing coupon items
166
         * @return static Manager object for chaining method calls
167
         */
168
        protected function saveCoupons( \Aimeos\MShop\Order\Item\Iface $item ) : static
169
        {
170
                $list = [];
11✔
171
                $manager = $this->object()->getSubManager( 'coupon' );
11✔
172
                $filter = $manager->filter()->add( 'order.coupon.parentid', '==', $item->getId() )->slice( 0, 0x7fffffff );
11✔
173
                $items = $manager->search( $filter )->groupBy( 'order.coupon.code' );
11✔
174

175
                foreach( $item->getCoupons() as $code => $products )
11✔
176
                {
177
                        if( empty( $products ) )
3✔
178
                        {
NEW
179
                                $list[] = current( (array) $items[$code] ) ?: $manager->create()->setParentId( $item->getId() )->setCode( $code );
×
180
                                continue;
×
181
                        }
182

183
                        foreach( $products as $product )
3✔
184
                        {
185
                                foreach( $items[$code] ?? [] as $prodItem )
3✔
186
                                {
187
                                        if( $product->getId() === $prodItem->getId() ) {
1✔
188
                                                continue 2;
×
189
                                        }
190
                                }
191

192
                                $list[] = $manager->create()->setParentId( $item->getId() )->setCode( $code )->setProductId( $product->getId() );
3✔
193
                        }
194
                }
195

196
                // @phpstan-ignore argument.type
197
                $manager->save( $list );
11✔
198
                return $this;
11✔
199
        }
200

201

202
        /**
203
         * Saves the ordered products to the storage.
204
         *
205
         * @param \Aimeos\MShop\Order\Item\Iface $item Order containing ordered products or bundles
206
         * @return static Manager object for chaining method calls
207
         */
208
        protected function saveProducts( \Aimeos\MShop\Order\Item\Iface $item ) : static
209
        {
210
                $products = $item->getProducts();
11✔
211
                // @phpstan-ignore argument.type
212
                $pos = (int) $products->merge( $products->getProducts()->flat( 1 ) )->max( 'order.product.position' );
11✔
213

214
                foreach( $products as $product )
11✔
215
                {
216
                        if( $product->getParentId() != $item->getId() ) {
5✔
217
                                $product->setId( null ); // create new item if copied
5✔
218
                        }
219

220
                        if( !$product->getPosition() ) {
5✔
221
                                $product->setPosition( ++$pos );
5✔
222
                        }
223

224
                        $product->setParentId( $item->getId() );
5✔
225

226
                        foreach( $product->getProducts() as $subProduct )
5✔
227
                        {
228
                                if( $subProduct->getParentId() != $item->getId() ) {
1✔
229
                                        $subProduct->setId( null ); // create new item if copied
1✔
230
                                }
231

232
                                if( !$subProduct->getPosition() ) {
1✔
233
                                        $subProduct->setPosition( ++$pos );
1✔
234
                                }
235

236
                                $subProduct->setParentId( $item->getId() );
1✔
237
                        }
238
                }
239

240
                $this->object()->getSubManager( 'product' )->save( $products );
11✔
241

242
                return $this;
11✔
243
        }
244

245

246
        /**
247
         * Saves the services of the order to the storage.
248
         *
249
         * @param \Aimeos\MShop\Order\Item\Iface $item Order containing service items
250
         * @return static Manager object for chaining method calls
251
         */
252
        protected function saveServices( \Aimeos\MShop\Order\Item\Iface $item ) : static
253
        {
254
                $services = $item->getServices();
11✔
255

256
                foreach( $services as $type => $list )
11✔
257
                {
258
                        $pos = 0;
5✔
259

260
                        foreach( $list as $service )
5✔
261
                        {
262
                                if( $service->getParentId() != $item->getId() ) {
5✔
263
                                        $service->setId( null ); // create new item if copied
5✔
264
                                }
265

266
                                $service->setParentId( $item->getId() )->setPosition( ++$pos );
5✔
267
                        }
268
                }
269

270
                $this->object()->getSubManager( 'service' )->save( $services->flat( 1 ) );
11✔
271

272
                return $this;
11✔
273
        }
274

275

276
        /**
277
         * Saves the statuses of the order to the storage.
278
         *
279
         * @param \Aimeos\MShop\Order\Item\Iface $item Order containing status items
280
         * @return static Manager object for chaining method calls
281
         */
282
        protected function saveStatuses( \Aimeos\MShop\Order\Item\Iface $item ) : static
283
        {
284
                $statuses = $item->getStatuses();
11✔
285

286
                foreach( $statuses as $type => $list )
11✔
287
                {
288
                        foreach( $list as $status )
3✔
289
                        {
290
                                if( $status->getParentId() != $item->getId() ) {
3✔
291
                                        $status->setId( null ); // create new item if copied
3✔
292
                                }
293

294
                                $status->setParentId( $item->getId() );
3✔
295
                        }
296
                }
297

298
                $this->object()->getSubManager( 'status' )->save( $statuses->flat( 1 ) );
11✔
299

300
                return $this;
11✔
301
        }
302
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc