• 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

79.03
/src/MShop/Common/Manager/Methods.php
1
<?php
2

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

10

11
namespace Aimeos\MShop\Common\Manager;
12

13

14
/**
15
 * Method trait for managers
16
 *
17
 * @package MShop
18
 * @subpackage Common
19
 */
20
trait Methods
21
{
22
        private ?\Aimeos\MShop\Common\Manager\Iface $object = null;
23
        private array $filterFcn = [];
24
        /** @var string[] */
25
        private array $type;
26

27

28
        /**
29
         * Adds a filter callback for an item type
30
         *
31
         * @param string $iface Interface name of the item to apply the filter to
32
         * @param \Closure $fcn Anonymous function receiving the item to check as first parameter
33
         * @return void
34
         */
35
        public function addFilter( string $iface, \Closure $fcn ) : void
36
        {
37
                if( !isset( $this->filterFcn[$iface] ) ) {
1✔
38
                        $this->filterFcn[$iface] = [];
1✔
39
                }
40

41
                $this->filterFcn[$iface][] = $fcn;
1✔
42
        }
43

44

45
        /**
46
         * Returns the class names of the manager and used decorators.
47
         *
48
         * @return array List of class names
49
         */
50
        public function classes() : array
51
        {
52
                return [get_class( $this )];
1✔
53
        }
54

55

56
        /**
57
         * Removes old entries from the storage
58
         *
59
         * @param iterable $siteids List of IDs for sites whose entries should be deleted
60
         * @return static Manager object for chaining method calls
61
         */
62
        public function clear( iterable $siteids ) : static
63
        {
64
                return $this;
×
65
        }
66

67

68
        /**
69
         * Creates a new empty item instance
70
         *
71
         * @param array $values Values the item should be initialized with
72
         * @return \Aimeos\MShop\Attribute\Item\Iface New attribute item object
73
         */
74
        public function create( array $values = [] ) : \Aimeos\MShop\Common\Item\Iface
75
        {
NEW
76
                return new \Aimeos\MShop\Common\Item\Base( $this->prefix(), $values ); // @phpstan-ignore return.type
×
77
        }
78

79

80
        /**
81
         * Creates a new cursor based on the filter criteria
82
         *
83
         * @param \Aimeos\Base\Criteria\Iface $filter Criteria object with conditions, sortations, etc.
84
         * @return \Aimeos\MShop\Common\Cursor\Iface Cursor object
85
         */
86
        public function cursor( \Aimeos\Base\Criteria\Iface $filter ) : \Aimeos\MShop\Common\Cursor\Iface
87
        {
88
                return new \Aimeos\MShop\Common\Cursor\Standard( $filter );
9✔
89
        }
90

91

92
        /**
93
         * Deletes one or more items.
94
         *
95
         * @param \Aimeos\MShop\Common\Item\Iface|\Aimeos\Map|array|string $items Item object, ID or a list of them
96
         * @return static Manager object for chaining method calls
97
         */
98
        public function delete( $items ) : static
99
        {
100
                return $this;
×
101
        }
102

103

104
        /**
105
         * Creates a filter object.
106
         *
107
         * @param bool|null $default Add default criteria or NULL for relaxed default criteria
108
         * @param bool $site TRUE for adding site criteria to limit items by the site of related items
109
         * @return \Aimeos\Base\Criteria\Iface Returns the filter object
110
         */
111
        public function filter( ?bool $default = false, bool $site = false ) : \Aimeos\Base\Criteria\Iface
112
        {
113
                throw new \LogicException( 'Not implemented' );
×
114
        }
115

116

117
        /**
118
         * Creates objects from the given array
119
         *
120
         * @param iterable $entries List of associative arrays with key/value pairs
121
         * @param array $refs List of domains to retrieve list items and referenced items for
122
         * @param array $excludes List of keys which shouldn't be used when creating the items
123
         * @return \Aimeos\Map List of items implementing \Aimeos\MShop\Common\Item\Iface
124
         */
125
        public function from( iterable $entries, array $refs = [], array $excludes = [] ) : \Aimeos\Map
126
        {
127
                $list = [];
2✔
128
                // @phpstan-ignore argument.type
129
                $keys = array_flip( $excludes );
2✔
130

131
                foreach( $entries as $key => $entry )
2✔
132
                {
133
                        $entry = array_diff_key( (array) $entry, $keys );
2✔
134
                        $list[$key] = $this->create()->fromArray( $entry, true );
2✔
135
                }
136

137
                return map( $list );
2✔
138
        }
139

140

141
        /**
142
         * Returns the item specified by its ID
143
         *
144
         * @param string $id Id of item
145
         * @param string[] $ref List of domains to fetch list items and referenced items for
146
         * @param bool|null $default Add default criteria or NULL for relaxed default criteria
147
         * @return \Aimeos\MShop\Common\Item\Iface Item object
148
         */
149
        public function get( string $id, array $ref = [], ?bool $default = false ) : \Aimeos\MShop\Common\Item\Iface
150
        {
151
                throw new \LogicException( 'Not implemented' );
×
152
        }
153

154

155
        /**
156
         * Returns the additional column/search definitions
157
         *
158
         * @return array Associative list of column names as keys and items implementing \Aimeos\Base\Criteria\Attribute\Iface
159
         */
160
        public function getSaveAttributes() : array
161
        {
162
                return [];
97✔
163
        }
164

165

166
        /**
167
         * Returns the attributes that can be used for searching.
168
         *
169
         * @param bool $withsub Return also attributes of sub-managers if true
170
         * @return \Aimeos\Base\Criteria\Attribute\Iface[] List of attribute items
171
         */
172
        public function getSearchAttributes( bool $withsub = true ) : array
173
        {
174
                return [];
×
175
        }
176

177

178
        /**
179
         * Returns a new manager for attribute extensions
180
         *
181
         * @param string $manager Name of the sub manager type in lower case
182
         * @param string|null $name Name of the implementation, will be from configuration (or Default) if null
183
         * @return \Aimeos\MShop\Common\Manager\Iface Manager for different extensions, e.g Type, List's etc.
184
         */
185
        public function getSubManager( string $manager, ?string $name = null ) : \Aimeos\MShop\Common\Manager\Iface
186
        {
187
                throw new \LogicException( 'Not implemented' );
×
188
        }
189

190

191
        /**
192
         * Iterates over all matched items and returns the found ones
193
         *
194
         * @param \Aimeos\MShop\Common\Cursor\Iface $cursor Cursor object with filter, domains and cursor
195
         * @param string[] $ref List of domains whose items should be fetched too
196
         * @return \Aimeos\Map|null List of items implementing \Aimeos\MShop\Common\Item\Iface with ids as keys
197
         */
198
        public function iterate( \Aimeos\MShop\Common\Cursor\Iface $cursor, array $ref = [] ) : ?\Aimeos\Map
199
        {
200
                return null;
×
201
        }
202

203

204
        /**
205
         * Adds or updates an item object or a list of them.
206
         *
207
         * @param \Aimeos\MShop\Common\Item\Iface[]|\Aimeos\MShop\Common\Item\Iface $items Item or list of items whose data should be saved
208
         * @param bool $fetch True if the new ID should be returned in the item
209
         * @return \Aimeos\MShop\Common\Item\Iface[]|\Aimeos\MShop\Common\Item\Iface Saved item or items
210
         */
211
        public function save( $items, bool $fetch = true )
212
        {
213
                return $items;
×
214
        }
215

216

217
        /**
218
         * Saves the dependent items of the item
219
         *
220
         * @param \Aimeos\MShop\Common\Item\Iface $item Item object
221
         * @param bool $fetch True if the new ID should be returned in the item
222
         * @return \Aimeos\MShop\Common\Item\Iface Updated item
223
         */
224
        public function saveRefs( \Aimeos\MShop\Common\Item\Iface $item, bool $fetch = true ) : \Aimeos\MShop\Common\Item\Iface
225
        {
226
                return $item;
106✔
227
        }
228

229

230
        /**
231
         * Searches for all items matching the given critera.
232
         *
233
         * @param \Aimeos\Base\Criteria\Iface $filter Criteria object with conditions, sortations, etc.
234
         * @param string[] $ref List of domains to fetch list items and referenced items for
235
         * @type int &$total Number of items that are available in total
236
         * @return \Aimeos\Map List of items implementing \Aimeos\MShop\Common\Item\Iface with ids as keys
237
         */
238
        public function search( \Aimeos\Base\Criteria\Iface $filter, array $ref = [], ?int &$total = null ) : \Aimeos\Map
239
        {
240
                return map();
×
241
        }
242

243

244
        /**
245
         * Merges the data from the given map and the referenced items
246
         *
247
         * @param array $entries Associative list of ID as key and the associative list of property key/value pairs as values
248
         * @param array $ref List of referenced items to fetch and add to the entries
249
         * @return array Associative list of ID as key and the updated entries as value
250
         */
251
        public function searchRefs( array $entries, array $ref ) : array
252
        {
253
                return $entries;
837✔
254
        }
255

256

257
        /**
258
         * Injects the reference of the outmost object
259
         *
260
         * @param \Aimeos\MShop\Common\Manager\Iface $object Reference to the outmost manager or decorator
261
         * @return static Manager object for chaining method calls
262
         */
263
        public function setObject( \Aimeos\MShop\Common\Manager\Iface $object ) : static
264
        {
265
                $this->object = $object;
1,389✔
266
                return $this;
1,389✔
267
        }
268

269

270
        /**
271
         * Returns the type of the mananger as separate parts
272
         *
273
         * @return string[] List of manager part names
274
         */
275
        public function type() : array
276
        {
277
                if( !isset( $this->type ) )
1,749✔
278
                {
279
                        $parts = array_slice( explode( '\\', strtolower( get_class( $this ) ) ), 2, -1 );
1,749✔
280
                        unset( $parts[1] );
1,749✔
281
                        $this->type = array_values( $parts );
1,749✔
282
                }
283

284
                return $this->type;
1,749✔
285
        }
286

287

288
        /**
289
         * Starts a database transaction on the connection identified by the given name
290
         *
291
         * @return static Manager object for chaining method calls
292
         */
293
        public function begin() : static
294
        {
295
                return $this;
×
296
        }
297

298

299
        /**
300
         * Commits the running database transaction on the connection identified by the given name
301
         *
302
         * @return static Manager object for chaining method calls
303
         */
304
        public function commit() : static
305
        {
306
                return $this;
×
307
        }
308

309

310
        /**
311
         * Rolls back the running database transaction on the connection identified by the given name
312
         *
313
         * @return static Manager object for chaining method calls
314
         */
315
        public function rollback() : static
316
        {
317
                return $this;
×
318
        }
319

320

321
        /**
322
         * Applies the filters for the item type to the item
323
         *
324
         * @param object $item Item to apply the filter to
325
         * @return object|null Object if the item should be used, null if not
326
         */
327
        protected function applyFilter( $item )
328
        {
329
                foreach( $this->filterFcn as $iface => $fcnList )
896✔
330
                {
331
                        if( is_string( $iface ) && $item instanceof $iface )
1✔
332
                        {
333
                                foreach( $fcnList as $fcn )
1✔
334
                                {
335
                                        if( is_callable( $fcn ) && $fcn( $item ) === null ) {
1✔
336
                                                return null;
1✔
337
                                        }
338
                                }
339
                        }
340
                }
341

342
                return $item;
896✔
343
        }
344

345

346
        /**
347
         * Creates the criteria attribute items from the list of entries
348
         *
349
         * @param array $list Associative array of code as key and array with properties as values
350
         * @return \Aimeos\Base\Criteria\Attribute\Standard[] List of criteria attribute items
351
         */
352
        protected function createAttributes( array $list ) : array
353
        {
354
                $attr = [];
997✔
355

356
                foreach( $list as $key => $fields )
997✔
357
                {
358
                        $fields = (array) $fields;
997✔
359
                        $fields['code'] = $fields['code'] ?? $key;
997✔
360
                        $fields['internalcode'] = $fields['internalcode'] ?? $key;
997✔
361
                        $attr[$key] = new \Aimeos\Base\Criteria\Attribute\Standard( $fields );
997✔
362
                }
363

364
                return $attr;
997✔
365
        }
366

367

368

369

370
        /**
371
         * Returns the attribute helper functions for searching defined by the manager.
372
         *
373
         * @param \Aimeos\Base\Criteria\Attribute\Iface[] $attributes List of search attribute items
374
         * @return array Associative array of attribute code and helper function
375
         */
376
        protected function getSearchFunctions( array $attributes ) : array
377
        {
378
                $list = [];
935✔
379

380
                foreach( $attributes as $key => $item ) {
935✔
381
                        $list[$item->getCode()] = $item->getFunction();
935✔
382
                }
383

384
                return $list;
935✔
385
        }
386

387

388
        /**
389
         * Returns the attribute translations for searching defined by the manager.
390
         *
391
         * @param \Aimeos\Base\Criteria\Attribute\Iface[] $attributes List of search attribute items
392
         * @return array Associative array of attribute code and internal attribute code
393
         */
394
        protected function getSearchTranslations( array $attributes ) : array
395
        {
396
                $list = [];
935✔
397

398
                foreach( $attributes as $key => $item ) {
935✔
399
                        $list[$item->getCode()] = $item->getInternalCode();
935✔
400
                }
401

402
                return $list;
935✔
403
        }
404

405

406
        /**
407
         * Returns the attribute types for searching defined by the manager.
408
         *
409
         * @param \Aimeos\Base\Criteria\Attribute\Iface[] $attributes List of search attribute items
410
         * @return array Associative array of attribute code and internal attribute type
411
         */
412
        protected function getSearchTypes( array $attributes ) : array
413
        {
414
                $list = [];
935✔
415

416
                foreach( $attributes as $key => $item ) {
935✔
417
                        $list[$item->getCode()] = $item->getInternalType();
935✔
418
                }
419

420
                return $list;
935✔
421
        }
422

423

424
        /**
425
         * Checks if the given domain is in the list of domains
426
         *
427
         * @param array $ref List of domains
428
         * @param string $domain Domain to check for
429
         * @return bool True if domain is in the list, false if not
430
         */
431
        protected function hasRef( array $ref, string $domain ) : bool
432
        {
433
                return isset( $ref[$domain] ) || in_array( $domain, $ref );
661✔
434
        }
435

436

437
        /**
438
         * Returns the outmost decorator of the decorator stack
439
         *
440
         * @return \Aimeos\MShop\Common\Manager\Iface Outmost decorator object
441
         */
442
        protected function object() : \Aimeos\MShop\Common\Manager\Iface
443
        {
444
                return $this->object ?? $this; // @phpstan-ignore return.type
1,095✔
445
        }
446

447

448
        /**
449
         * Returns the prefix for the item properties and search keys.
450
         *
451
         * @return string Prefix for the item properties and search keys
452
         */
453
        protected function prefix() : string
454
        {
455
                return '';
6✔
456
        }
457
}
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