Total Complexity | 67 |
Total Lines | 500 |
Duplicated Lines | 0 % |
Changes | 0 |
Complex classes like Standard often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use Standard, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
25 | class Standard |
||
26 | extends \Aimeos\MShop\Common\Item\Base |
||
27 | implements \Aimeos\MShop\Product\Item\Iface |
||
28 | { |
||
29 | use Stock, Config\Traits, ListsRef\Traits, PropertyRef\Traits, TypeRef\Traits { |
||
30 | PropertyRef\Traits::__clone as __cloneProperty; |
||
31 | ListsRef\Traits::__clone as __cloneList; |
||
32 | ListsRef\Traits::getName as getNameList; |
||
33 | Stock::__clone as __cloneStock; |
||
34 | } |
||
35 | |||
36 | |||
37 | /** |
||
38 | * Initializes the item object. |
||
39 | * |
||
40 | * @param string $prefix Domain specific prefix string |
||
41 | * @param array $values Parameter for initializing the basic properties |
||
42 | */ |
||
43 | public function __construct( string $prefix, array $values = [] ) |
||
44 | { |
||
45 | parent::__construct( $prefix, $values ); |
||
46 | |||
47 | $this->initPropertyItems( $values['.propitems'] ?? [] ); |
||
48 | $this->initListItems( $values['.listitems'] ?? [] ); |
||
49 | $this->initStockItems( $values['.stock'] ?? [] ); |
||
50 | } |
||
51 | |||
52 | |||
53 | /** |
||
54 | * Creates a deep clone of all objects |
||
55 | */ |
||
56 | public function __clone() |
||
57 | { |
||
58 | parent::__clone(); |
||
59 | $this->__cloneList(); |
||
60 | $this->__cloneStock(); |
||
61 | $this->__cloneProperty(); |
||
62 | } |
||
63 | |||
64 | |||
65 | /** |
||
66 | * Returns the parent product items referencing the product |
||
67 | * |
||
68 | * @return \Aimeos\Map Associative list of items implementing \Aimeos\MShop\Product\Item\Iface |
||
69 | */ |
||
70 | public function getParentItems() : \Aimeos\Map |
||
71 | { |
||
72 | return map( $this->get( '.parent' ) ); |
||
73 | } |
||
74 | |||
75 | |||
76 | /** |
||
77 | * Returns the supplier items referencing the product |
||
78 | * |
||
79 | * @return \Aimeos\Map Associative list of items implementing \Aimeos\MShop\Supplier\Item\Iface |
||
80 | */ |
||
81 | public function getSiteItem() : ?\Aimeos\MShop\Locale\Item\Site\Iface |
||
82 | { |
||
83 | return $this->get( '.locale/site' ); |
||
84 | } |
||
85 | |||
86 | |||
87 | /** |
||
88 | * Returns the status of the product item. |
||
89 | * |
||
90 | * @return int Status of the product item |
||
91 | */ |
||
92 | public function getStatus() : int |
||
93 | { |
||
94 | return $this->get( 'product.status', 1 ); |
||
95 | } |
||
96 | |||
97 | |||
98 | /** |
||
99 | * Sets the new status of the product item. |
||
100 | * |
||
101 | * @param int $status New status of the product item |
||
102 | * @return \Aimeos\MShop\Product\Item\Iface Product item for chaining method calls |
||
103 | */ |
||
104 | public function setStatus( int $status ) : \Aimeos\MShop\Common\Item\Iface |
||
105 | { |
||
106 | return $this->set( 'product.status', $status ); |
||
107 | } |
||
108 | |||
109 | |||
110 | /** |
||
111 | * Returns the code of the product item. |
||
112 | * |
||
113 | * @return string Code of the product item |
||
114 | */ |
||
115 | public function getCode() : string |
||
116 | { |
||
117 | return $this->get( 'product.code', '' ); |
||
118 | } |
||
119 | |||
120 | |||
121 | /** |
||
122 | * Sets the new code of the product item. |
||
123 | * |
||
124 | * @param string $code New code of product item |
||
125 | * @return \Aimeos\MShop\Product\Item\Iface Product item for chaining method calls |
||
126 | */ |
||
127 | public function setCode( string $code ) : \Aimeos\MShop\Product\Item\Iface |
||
128 | { |
||
129 | return $this->set( 'product.code', \Aimeos\Utils::code( $code ) ); |
||
130 | } |
||
131 | |||
132 | |||
133 | /** |
||
134 | * Returns the data set name assigned to the product item. |
||
135 | * |
||
136 | * @return string Data set name |
||
137 | */ |
||
138 | public function getDataset() : string |
||
139 | { |
||
140 | return $this->get( 'product.dataset', '' ); |
||
141 | } |
||
142 | |||
143 | |||
144 | /** |
||
145 | * Sets a new data set name assignd to the product item. |
||
146 | * |
||
147 | * @param string $name New data set name |
||
148 | * @return \Aimeos\MShop\Product\Item\Iface Product item for chaining method calls |
||
149 | */ |
||
150 | public function setDataset( ?string $name ) : \Aimeos\MShop\Product\Item\Iface |
||
151 | { |
||
152 | return $this->set( 'product.dataset', \Aimeos\Utils::code( (string) $name ) ); |
||
153 | } |
||
154 | |||
155 | |||
156 | /** |
||
157 | * Returns the label of the product item. |
||
158 | * |
||
159 | * @return string Label of the product item |
||
160 | */ |
||
161 | public function getLabel() : string |
||
162 | { |
||
163 | return $this->get( 'product.label', '' ); |
||
164 | } |
||
165 | |||
166 | |||
167 | /** |
||
168 | * Sets a new label of the product item. |
||
169 | * |
||
170 | * @param string $label New label of the product item |
||
171 | * @return \Aimeos\MShop\Product\Item\Iface Product item for chaining method calls |
||
172 | */ |
||
173 | public function setLabel( string $label ) : \Aimeos\MShop\Product\Item\Iface |
||
176 | } |
||
177 | |||
178 | |||
179 | /** |
||
180 | * Returns the localized text type of the item or the internal label if no name is available. |
||
181 | * |
||
182 | * @param string $type Text type to be returned |
||
183 | * @param string|null $langId Two letter ISO Language code of the text |
||
184 | * @return string Specified text type or label of the item |
||
185 | */ |
||
186 | public function getName( string $type = 'name', ?string $langId = null ) : string |
||
187 | { |
||
188 | $name = $this->getNameList( $type, $langId ); |
||
189 | |||
190 | if( $type === 'url' && $name === $this->getLabel() ) { |
||
191 | return $this->getUrl(); |
||
192 | } |
||
193 | |||
194 | return $name; |
||
195 | } |
||
196 | |||
197 | |||
198 | /** |
||
199 | * Returns the URL segment for the product item. |
||
200 | * |
||
201 | * @return string URL segment of the product item |
||
202 | */ |
||
203 | public function getUrl() : string |
||
206 | } |
||
207 | |||
208 | |||
209 | /** |
||
210 | * Sets a new URL segment for the product. |
||
211 | * |
||
212 | * @param string|null $url New URL segment of the product item |
||
213 | * @return \Aimeos\MShop\Product\Item\Iface Product item for chaining method calls |
||
214 | */ |
||
215 | public function setUrl( ?string $url ) : \Aimeos\MShop\Product\Item\Iface |
||
216 | { |
||
217 | return $this->set( 'product.url', \Aimeos\Base\Str::slug( $url ) ); |
||
218 | } |
||
219 | |||
220 | |||
221 | /** |
||
222 | * Returns the configuration values of the item |
||
223 | * |
||
224 | * @return array Configuration values |
||
225 | */ |
||
226 | public function getConfig() : array |
||
229 | } |
||
230 | |||
231 | |||
232 | /** |
||
233 | * Sets the configuration values of the item. |
||
234 | * |
||
235 | * @param array $config Configuration values |
||
236 | * @return \Aimeos\MShop\Product\Item\Iface Product item for chaining method calls |
||
237 | */ |
||
238 | public function setConfig( array $config ) : \Aimeos\MShop\Common\Item\Iface |
||
239 | { |
||
240 | if( !$this->compareConfig( $this->getConfig(), $config ) ) { |
||
241 | $this->set( 'product.config', $config ); |
||
242 | } |
||
243 | |||
244 | return $this; |
||
245 | } |
||
246 | |||
247 | |||
248 | /** |
||
249 | * Returns the starting point of time, in which the product is available. |
||
250 | * |
||
251 | * @return string|null ISO date in YYYY-MM-DD hh:mm:ss format |
||
252 | */ |
||
253 | public function getDateStart() : ?string |
||
254 | { |
||
255 | $value = $this->get( 'product.datestart' ); |
||
256 | return $value ? substr( $value, 0, 19 ) : null; |
||
257 | } |
||
258 | |||
259 | |||
260 | /** |
||
261 | * Sets a new starting point of time, in which the product is available. |
||
262 | * |
||
263 | * @param string|null $date New ISO date in YYYY-MM-DD hh:mm:ss format |
||
264 | * @return \Aimeos\MShop\Product\Item\Iface Product item for chaining method calls |
||
265 | */ |
||
266 | public function setDateStart( ?string $date ) : \Aimeos\MShop\Common\Item\Iface |
||
267 | { |
||
268 | return $this->set( 'product.datestart', \Aimeos\Utils::datetime( $date ) ); |
||
269 | } |
||
270 | |||
271 | |||
272 | /** |
||
273 | * Returns the ending point of time, in which the product is available. |
||
274 | * |
||
275 | * @return string|null ISO date in YYYY-MM-DD hh:mm:ss format |
||
276 | */ |
||
277 | public function getDateEnd() : ?string |
||
278 | { |
||
279 | $value = $this->get( 'product.dateend' ); |
||
280 | return $value ? substr( $value, 0, 19 ) : null; |
||
281 | } |
||
282 | |||
283 | |||
284 | /** |
||
285 | * Sets a new ending point of time, in which the product is available. |
||
286 | * |
||
287 | * @param string|null $date New ISO date in YYYY-MM-DD hh:mm:ss format |
||
288 | * @return \Aimeos\MShop\Product\Item\Iface Product item for chaining method calls |
||
289 | */ |
||
290 | public function setDateEnd( ?string $date ) : \Aimeos\MShop\Common\Item\Iface |
||
291 | { |
||
292 | return $this->set( 'product.dateend', \Aimeos\Utils::datetime( $date ) ); |
||
293 | } |
||
294 | |||
295 | |||
296 | /** |
||
297 | * Returns the rating of the item |
||
298 | * |
||
299 | * @return string Decimal value of the item rating |
||
300 | */ |
||
301 | public function getRating() : string |
||
302 | { |
||
303 | return (string) $this->get( 'product.rating', 0 ); |
||
304 | } |
||
305 | |||
306 | |||
307 | /** |
||
308 | * Returns the total number of ratings for the item |
||
309 | * |
||
310 | * @return int Total number of ratings for the item |
||
311 | */ |
||
312 | public function getRatings() : int |
||
313 | { |
||
314 | return (int) $this->get( 'product.ratings', 0 ); |
||
315 | } |
||
316 | |||
317 | |||
318 | /** |
||
319 | * Returns the quantity scale of the product item. |
||
320 | * |
||
321 | * @return float Quantity scale |
||
322 | */ |
||
323 | public function getScale() : float |
||
324 | { |
||
325 | return (float) $this->get( 'product.scale', 1 ) ?: 1; |
||
326 | } |
||
327 | |||
328 | |||
329 | /** |
||
330 | * Sets a new quantity scale of the product item. |
||
331 | * |
||
332 | * @param float $value New quantity scale |
||
333 | * @return \Aimeos\MShop\Product\Item\Iface Product item for chaining method calls |
||
334 | */ |
||
335 | public function setScale( float $value ) : \Aimeos\MShop\Product\Item\Iface |
||
336 | { |
||
337 | return $this->set( 'product.scale', $value > 0 ? $value : 1 ); |
||
338 | } |
||
339 | |||
340 | |||
341 | /** |
||
342 | * Returns the URL target specific for that product |
||
343 | * |
||
344 | * @return string URL target specific for that product |
||
345 | */ |
||
346 | public function getTarget() : string |
||
347 | { |
||
348 | return $this->get( 'product.target', '' ); |
||
349 | } |
||
350 | |||
351 | |||
352 | /** |
||
353 | * Sets a new URL target specific for that product |
||
354 | * |
||
355 | * @param string $value New URL target specific for that product |
||
356 | * @return \Aimeos\MShop\Product\Item\Iface Product item for chaining method calls |
||
357 | */ |
||
358 | public function setTarget( ?string $value ) : \Aimeos\MShop\Product\Item\Iface |
||
359 | { |
||
360 | return $this->set( 'product.target', (string) $value ); |
||
361 | } |
||
362 | |||
363 | |||
364 | /** |
||
365 | * Returns the create date of the item |
||
366 | * |
||
367 | * @return string|null ISO date in YYYY-MM-DD hh:mm:ss format |
||
368 | */ |
||
369 | public function getTimeCreated() : ?string |
||
370 | { |
||
371 | return $this->get( 'product.ctime' ); |
||
372 | } |
||
373 | |||
374 | |||
375 | /** |
||
376 | * Sets the create date of the item |
||
377 | * |
||
378 | * @param string|null $value ISO date in YYYY-MM-DD hh:mm:ss format |
||
379 | * @return \Aimeos\MShop\Product\Item\Iface Product item for chaining method calls |
||
380 | */ |
||
381 | public function setTimeCreated( ?string $value ) : \Aimeos\MShop\Product\Item\Iface |
||
384 | } |
||
385 | |||
386 | |||
387 | /** |
||
388 | * Returns the type of the product item. |
||
389 | * Overwritten for different default value. |
||
390 | * |
||
391 | * @return string Type of the product item |
||
392 | */ |
||
393 | public function getType() : string |
||
394 | { |
||
395 | return $this->get( 'product.type', 'default' ); |
||
396 | } |
||
397 | |||
398 | |||
399 | /** |
||
400 | * Tests if the item is available based on status, time, language and currency |
||
401 | * |
||
402 | * @return bool True if available, false if not |
||
403 | */ |
||
404 | public function isAvailable() : bool |
||
405 | { |
||
406 | $date = $this->get( '.date' ) ?: date( 'Y-m-d H:i:s' ); |
||
407 | |||
408 | return parent::isAvailable() && $this->getStatus() > 0 |
||
409 | && ( $this->getDateEnd() === null || $this->getDateEnd() > $date ) |
||
410 | && ( $this->getDateStart() === null || $this->getDateStart() < $date || $this->getType() === 'event' ); |
||
411 | } |
||
412 | |||
413 | |||
414 | /** |
||
415 | * Returns the flag if stock is available for that product. |
||
416 | * |
||
417 | * @return int "1" if product is in stock, "0" if product is out of stock |
||
418 | */ |
||
419 | public function inStock() : int |
||
422 | } |
||
423 | |||
424 | |||
425 | /** |
||
426 | * Sets the flag if stock is available for that product. |
||
427 | * |
||
428 | * @param int $value "1" if product is in stock, "0" if product is out of stock |
||
429 | * @return \Aimeos\MShop\Product\Item\Iface Product item for chaining method calls |
||
430 | */ |
||
431 | public function setInStock( int $value ) : \Aimeos\MShop\Product\Item\Iface |
||
432 | { |
||
433 | return $this->set( 'product.instock', $value ); |
||
434 | } |
||
435 | |||
436 | /** |
||
437 | * Returns the boost factor for that product. |
||
438 | * |
||
439 | * @return float Boost factor |
||
440 | */ |
||
441 | public function boost() : float |
||
442 | { |
||
443 | return (float) $this->get( 'product.boost', 1 ); |
||
444 | } |
||
445 | |||
446 | /** |
||
447 | * Sets the boost factor for that product. |
||
448 | * |
||
449 | * @param float $value Boost factor |
||
450 | * @return \Aimeos\MShop\Product\Item\Iface Product item for chaining method calls |
||
451 | */ |
||
452 | public function setBoost( float $value ) : \Aimeos\MShop\Product\Item\Iface |
||
455 | } |
||
456 | |||
457 | |||
458 | /* |
||
459 | * Sets the item values from the given array and removes that entries from the list |
||
460 | * |
||
461 | * @param array &$list Associative list of item keys and their values |
||
462 | * @param bool True to set private properties too, false for public only |
||
463 | * @return \Aimeos\MShop\Product\Item\Iface Product item for chaining method calls |
||
464 | */ |
||
465 | public function fromArray( array &$list, bool $private = false ) : \Aimeos\MShop\Common\Item\Iface |
||
494 | } |
||
495 | |||
496 | |||
497 | /** |
||
498 | * Returns the item values as array. |
||
499 | * |
||
500 | * @param bool True to return private properties, false for public only |
||
501 | * @return array Associative list of item properties and their values |
||
502 | */ |
||
503 | public function toArray( bool $private = false ) : array |
||
525 | } |
||
526 | } |
||
527 |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths