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

aimeos / aimeos-core / 1d022d3b-cd8b-4722-8e0a-9a23a493dd8e

07 Aug 2024 02:44PM UTC coverage: 91.827% (+0.07%) from 91.753%
1d022d3b-cd8b-4722-8e0a-9a23a493dd8e

push

circleci

aimeos
Minor improvements

1 of 1 new or added line in 1 file covered. (100.0%)

36 existing lines in 3 files now uncovered.

10764 of 11722 relevant lines covered (91.83%)

57.92 hits per line

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

72.34
/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 string $domain;
25
        private string $subpath;
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
         */
34
        public function addFilter( string $iface, \Closure $fcn )
35
        {
36
                if( !isset( $this->filterFcn[$iface] ) ) {
1✔
37
                        $this->filterFcn[$iface] = [];
1✔
38
                }
39

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

43

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

54

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

66

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

78

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

90

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

102

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

115

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

129

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

140

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

152

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

165

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

178

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

191

192
        /**
193
         * Searches for all items matching the given critera.
194
         *
195
         * @param \Aimeos\Base\Criteria\Iface $filter Criteria object with conditions, sortations, etc.
196
         * @param string[] $ref List of domains to fetch list items and referenced items for
197
         * @param int &$total Number of items that are available in total
198
         * @return \Aimeos\Map List of items implementing \Aimeos\MShop\Common\Item\Iface with ids as keys
199
         */
200
        public function search( \Aimeos\Base\Criteria\Iface $filter, array $ref = [], int &$total = null ) : \Aimeos\Map
201
        {
UNCOV
202
                return map();
×
203
        }
204

205

206
        /**
207
         * Injects the reference of the outmost object
208
         *
209
         * @param \Aimeos\MShop\Common\Manager\Iface $object Reference to the outmost manager or decorator
210
         * @return \Aimeos\MShop\Common\Manager\Iface Manager object for chaining method calls
211
         */
212
        public function setObject( \Aimeos\MShop\Common\Manager\Iface $object ) : \Aimeos\MShop\Common\Manager\Iface
213
        {
214
                $this->object = $object;
1,197✔
215
                return $this;
1,197✔
216
        }
217

218

219
        /**
220
         * Starts a database transaction on the connection identified by the given name
221
         *
222
         * @return \Aimeos\MShop\Common\Manager\Iface Manager object for chaining method calls
223
         */
224
        public function begin() : \Aimeos\MShop\Common\Manager\Iface
225
        {
UNCOV
226
                return $this;
×
227
        }
228

229

230
        /**
231
         * Commits the running database transaction on the connection identified by the given name
232
         *
233
         * @return \Aimeos\MShop\Common\Manager\Iface Manager object for chaining method calls
234
         */
235
        public function commit() : \Aimeos\MShop\Common\Manager\Iface
236
        {
UNCOV
237
                return $this;
×
238
        }
239

240

241
        /**
242
         * Rolls back the running database transaction on the connection identified by the given name
243
         *
244
         * @return \Aimeos\MShop\Common\Manager\Iface Manager object for chaining method calls
245
         */
246
        public function rollback() : \Aimeos\MShop\Common\Manager\Iface
247
        {
UNCOV
248
                return $this;
×
249
        }
250

251

252
        /**
253
         * Applies the filters for the item type to the item
254
         *
255
         * @param object $item Item to apply the filter to
256
         * @return object|null Object if the item should be used, null if not
257
         */
258
        protected function applyFilter( $item )
259
        {
260
                foreach( $this->filterFcn as $iface => $fcnList )
838✔
261
                {
262
                        if( is_object( $item ) && $item instanceof $iface )
1✔
263
                        {
264
                                foreach( $fcnList as $fcn )
1✔
265
                                {
266
                                        if( $fcn( $item ) === null ) {
1✔
267
                                                return null;
1✔
268
                                        }
269
                                }
270
                        }
271
                }
272

273
                return $item;
838✔
274
        }
275

276

277
        /**
278
         * Creates the criteria attribute items from the list of entries
279
         *
280
         * @param array $list Associative array of code as key and array with properties as values
281
         * @return \Aimeos\Base\Criteria\Attribute\Standard[] List of criteria attribute items
282
         */
283
        protected function createAttributes( array $list ) : array
284
        {
285
                $attr = [];
939✔
286

287
                foreach( $list as $key => $fields )
939✔
288
                {
289
                        $fields['code'] = $fields['code'] ?? $key;
939✔
290
                        $fields['internalcode'] = $fields['internalcode'] ?? $key;
939✔
291
                        $attr[$key] = new \Aimeos\Base\Criteria\Attribute\Standard( $fields );
939✔
292
                }
293

294
                return $attr;
939✔
295
        }
296

297

298
        /**
299
         * Returns the prefix for the item properties and search keys.
300
         *
301
         * @return string Prefix for the item properties and search keys
302
         */
303
        protected function prefix() : string
304
        {
305
                return '';
5✔
306
        }
307

308

309
        /**
310
         * Returns the attribute helper functions for searching defined by the manager.
311
         *
312
         * @param \Aimeos\Base\Criteria\Attribute\Iface[] $attributes List of search attribute items
313
         * @return array Associative array of attribute code and helper function
314
         */
315
        protected function getSearchFunctions( array $attributes ) : array
316
        {
317
                $list = [];
878✔
318

319
                foreach( $attributes as $key => $item ) {
878✔
320
                        $list[$item->getCode()] = $item->getFunction();
878✔
321
                }
322

323
                return $list;
878✔
324
        }
325

326

327
        /**
328
         * Returns the attribute translations for searching defined by the manager.
329
         *
330
         * @param \Aimeos\Base\Criteria\Attribute\Iface[] $attributes List of search attribute items
331
         * @return array Associative array of attribute code and internal attribute code
332
         */
333
        protected function getSearchTranslations( array $attributes ) : array
334
        {
335
                $list = [];
878✔
336

337
                foreach( $attributes as $key => $item ) {
878✔
338
                        $list[$item->getCode()] = $item->getInternalCode();
878✔
339
                }
340

341
                return $list;
878✔
342
        }
343

344

345
        /**
346
         * Returns the attribute types for searching defined by the manager.
347
         *
348
         * @param \Aimeos\Base\Criteria\Attribute\Iface[] $attributes List of search attribute items
349
         * @return array Associative array of attribute code and internal attribute type
350
         */
351
        protected function getSearchTypes( array $attributes ) : array
352
        {
353
                $list = [];
878✔
354

355
                foreach( $attributes as $key => $item ) {
878✔
356
                        $list[$item->getCode()] = $item->getInternalType();
878✔
357
                }
358

359
                return $list;
878✔
360
        }
361

362

363
        /**
364
         * Returns the outmost decorator of the decorator stack
365
         *
366
         * @return \Aimeos\MShop\Common\Manager\Iface Outmost decorator object
367
         */
368
        protected function object() : \Aimeos\MShop\Common\Manager\Iface
369
        {
370
                return $this->object ?? $this;
999✔
371
        }
372
}
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