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

aimeos / aimeos-core / 28ef8f91-4b03-446b-a8d1-d1a6783e5f66

18 Sep 2024 07:45AM UTC coverage: 92.16% (+0.005%) from 92.155%
28ef8f91-4b03-446b-a8d1-d1a6783e5f66

push

circleci

aimeos
Replaced domain() and other helper methods by using type()

21 of 22 new or added lines in 4 files covered. (95.45%)

3 existing lines in 1 file now uncovered.

9780 of 10612 relevant lines covered (92.16%)

74.5 hits per line

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

76.36
/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
        private array $type;
25

26

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

39
                $this->filterFcn[$iface][] = $fcn;
1✔
40
        }
41

42

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

53

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

65

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

77

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

89

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

101

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

114

115
        /**
116
         * Returns the item specified by its ID
117
         *
118
         * @param string $id Id of item
119
         * @param string[] $ref List of domains to fetch list items and referenced items for
120
         * @param bool|null $default Add default criteria or NULL for relaxed default criteria
121
         * @return \Aimeos\MShop\Common\Item\Iface Item object
122
         */
123
        public function get( string $id, array $ref = [], ?bool $default = false ) : \Aimeos\MShop\Common\Item\Iface
124
        {
125
                throw new \LogicException( 'Not implemented' );
×
126
        }
127

128

129
        /**
130
         * Returns the additional column/search definitions
131
         *
132
         * @return array Associative list of column names as keys and items implementing \Aimeos\Base\Criteria\Attribute\Iface
133
         */
134
        public function getSaveAttributes() : array
135
        {
136
                return [];
91✔
137
        }
138

139

140
        /**
141
         * Returns the attributes that can be used for searching.
142
         *
143
         * @param bool $withsub Return also attributes of sub-managers if true
144
         * @return \Aimeos\Base\Criteria\Attribute\Iface[] List of attribute items
145
         */
146
        public function getSearchAttributes( bool $withsub = true ) : array
147
        {
148
                return [];
×
149
        }
150

151

152
        /**
153
         * Returns a new manager for attribute extensions
154
         *
155
         * @param string $manager Name of the sub manager type in lower case
156
         * @param string|null $name Name of the implementation, will be from configuration (or Default) if null
157
         * @return \Aimeos\MShop\Common\Manager\Iface Manager for different extensions, e.g Type, List's etc.
158
         */
159
        public function getSubManager( string $manager, string $name = null ) : \Aimeos\MShop\Common\Manager\Iface
160
        {
161
                throw new \LogicException( 'Not implemented' );
×
162
        }
163

164

165
        /**
166
         * Iterates over all matched items and returns the found ones
167
         *
168
         * @param \Aimeos\MShop\Common\Cursor\Iface $cursor Cursor object with filter, domains and cursor
169
         * @param string[] $ref List of domains whose items should be fetched too
170
         * @return \Aimeos\Map|null List of items implementing \Aimeos\MShop\Common\Item\Iface with ids as keys
171
         */
172
        public function iterate( \Aimeos\MShop\Common\Cursor\Iface $cursor, array $ref = [] ) : ?\Aimeos\Map
173
        {
174
                return null;
×
175
        }
176

177

178
        /**
179
         * Adds or updates an item object or a list of them.
180
         *
181
         * @param \Aimeos\MShop\Common\Item\Iface[]|\Aimeos\MShop\Common\Item\Iface $items Item or list of items whose data should be saved
182
         * @param bool $fetch True if the new ID should be returned in the item
183
         * @return \Aimeos\MShop\Common\Item\Iface[]|\Aimeos\MShop\Common\Item\Iface Saved item or items
184
         */
185
        public function save( $items, bool $fetch = true )
186
        {
187
                return $items;
×
188
        }
189

190

191
        /**
192
         * Saves the dependent items of the item
193
         *
194
         * @param \Aimeos\MShop\Common\Item\Iface $item Item object
195
         * @param bool $fetch True if the new ID should be returned in the item
196
         * @return \Aimeos\MShop\Common\Item\Iface Updated item
197
         */
198
        public function saveRefs( \Aimeos\MShop\Common\Item\Iface $item, bool $fetch = true ) : \Aimeos\MShop\Common\Item\Iface
199
        {
200
                return $item;
89✔
201
        }
202

203

204
        /**
205
         * Searches for all items matching the given critera.
206
         *
207
         * @param \Aimeos\Base\Criteria\Iface $filter Criteria object with conditions, sortations, etc.
208
         * @param string[] $ref List of domains to fetch list items and referenced items for
209
         * @param int &$total Number of items that are available in total
210
         * @return \Aimeos\Map List of items implementing \Aimeos\MShop\Common\Item\Iface with ids as keys
211
         */
212
        public function search( \Aimeos\Base\Criteria\Iface $filter, array $ref = [], int &$total = null ) : \Aimeos\Map
213
        {
214
                return map();
×
215
        }
216

217

218
        /**
219
         * Merges the data from the given map and the referenced items
220
         *
221
         * @param array $entries Associative list of ID as key and the associative list of property key/value pairs as values
222
         * @param array $ref List of referenced items to fetch and add to the entries
223
         * @return array Associative list of ID as key and the updated entries as value
224
         */
225
        public function searchRefs( array $entries, array $ref ) : array
226
        {
227
                return $entries;
780✔
228
        }
229

230

231
        /**
232
         * Injects the reference of the outmost object
233
         *
234
         * @param \Aimeos\MShop\Common\Manager\Iface $object Reference to the outmost manager or decorator
235
         * @return \Aimeos\MShop\Common\Manager\Iface Manager object for chaining method calls
236
         */
237
        public function setObject( \Aimeos\MShop\Common\Manager\Iface $object ) : \Aimeos\MShop\Common\Manager\Iface
238
        {
239
                $this->object = $object;
1,337✔
240
                return $this;
1,337✔
241
        }
242

243

244
        /**
245
         * Returns the type of the mananger as separate parts
246
         *
247
         * @return string[] List of manager part names
248
         */
249
        public function type() : array
250
        {
251
                if( !isset( $this->type ) )
1,803✔
252
                {
253
                        $parts = array_slice( explode( '\\', strtolower( get_class( $this ) ) ), 2, -1 );
1,803✔
254
                        unset( $parts[1] );
1,803✔
255
                        $this->type = $parts;
1,803✔
256
                }
257

258
                return $this->type;
1,803✔
259
        }
260

261

262
        /**
263
         * Starts a database transaction on the connection identified by the given name
264
         *
265
         * @return \Aimeos\MShop\Common\Manager\Iface Manager object for chaining method calls
266
         */
267
        public function begin() : \Aimeos\MShop\Common\Manager\Iface
268
        {
UNCOV
269
                return $this;
×
270
        }
271

272

273
        /**
274
         * Commits the running database transaction on the connection identified by the given name
275
         *
276
         * @return \Aimeos\MShop\Common\Manager\Iface Manager object for chaining method calls
277
         */
278
        public function commit() : \Aimeos\MShop\Common\Manager\Iface
279
        {
UNCOV
280
                return $this;
×
281
        }
282

283

284
        /**
285
         * Rolls back the running database transaction on the connection identified by the given name
286
         *
287
         * @return \Aimeos\MShop\Common\Manager\Iface Manager object for chaining method calls
288
         */
289
        public function rollback() : \Aimeos\MShop\Common\Manager\Iface
290
        {
UNCOV
291
                return $this;
×
292
        }
293

294

295
        /**
296
         * Applies the filters for the item type to the item
297
         *
298
         * @param object $item Item to apply the filter to
299
         * @return object|null Object if the item should be used, null if not
300
         */
301
        protected function applyFilter( $item )
302
        {
303
                foreach( $this->filterFcn as $iface => $fcnList )
887✔
304
                {
305
                        if( $item instanceof $iface )
1✔
306
                        {
307
                                foreach( $fcnList as $fcn )
1✔
308
                                {
309
                                        if( $fcn( $item ) === null ) {
1✔
310
                                                return null;
1✔
311
                                        }
312
                                }
313
                        }
314
                }
315

316
                return $item;
887✔
317
        }
318

319

320
        /**
321
         * Creates the criteria attribute items from the list of entries
322
         *
323
         * @param array $list Associative array of code as key and array with properties as values
324
         * @return \Aimeos\Base\Criteria\Attribute\Standard[] List of criteria attribute items
325
         */
326
        protected function createAttributes( array $list ) : array
327
        {
328
                $attr = [];
987✔
329

330
                foreach( $list as $key => $fields )
987✔
331
                {
332
                        $fields['code'] = $fields['code'] ?? $key;
987✔
333
                        $fields['internalcode'] = $fields['internalcode'] ?? $key;
987✔
334
                        $attr[$key] = new \Aimeos\Base\Criteria\Attribute\Standard( $fields );
987✔
335
                }
336

337
                return $attr;
987✔
338
        }
339

340

341
        /**
342
         * Returns the prefix for the item properties and search keys.
343
         *
344
         * @return string Prefix for the item properties and search keys
345
         */
346
        protected function prefix() : string
347
        {
348
                return '';
5✔
349
        }
350

351

352
        /**
353
         * Returns the attribute helper functions for searching defined by the manager.
354
         *
355
         * @param \Aimeos\Base\Criteria\Attribute\Iface[] $attributes List of search attribute items
356
         * @return array Associative array of attribute code and helper function
357
         */
358
        protected function getSearchFunctions( array $attributes ) : array
359
        {
360
                $list = [];
926✔
361

362
                foreach( $attributes as $key => $item ) {
926✔
363
                        $list[$item->getCode()] = $item->getFunction();
926✔
364
                }
365

366
                return $list;
926✔
367
        }
368

369

370
        /**
371
         * Returns the attribute translations 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 internal attribute code
375
         */
376
        protected function getSearchTranslations( array $attributes ) : array
377
        {
378
                $list = [];
926✔
379

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

384
                return $list;
926✔
385
        }
386

387

388
        /**
389
         * Returns the attribute types 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 type
393
         */
394
        protected function getSearchTypes( array $attributes ) : array
395
        {
396
                $list = [];
926✔
397

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

402
                return $list;
926✔
403
        }
404

405

406
        /**
407
         * Checks if the given domain is in the list of domains
408
         *
409
         * @param array $ref List of domains
410
         * @param string $domain Domain to check for
411
         * @return bool True if domain is in the list, false if not
412
         */
413
        protected function hasRef( array $ref, string $domain ) : bool
414
        {
415
                return isset( $ref[$domain] ) || in_array( $domain, $ref );
363✔
416
        }
417

418

419
        /**
420
         * Returns the outmost decorator of the decorator stack
421
         *
422
         * @return \Aimeos\MShop\Common\Manager\Iface Outmost decorator object
423
         */
424
        protected function object() : \Aimeos\MShop\Common\Manager\Iface
425
        {
426
                return $this->object ?? $this;
1,097✔
427
        }
428
}
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