Total Complexity | 66 |
Total Lines | 496 |
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 |
||
174 | { |
||
175 | return $this->set( 'product.label', $label ); |
||
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 |
||
204 | { |
||
205 | return (string) $this->get( 'product.url' ) ?: \Aimeos\Base\Str::slug( $this->getLabel() ); |
||
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 |
||
227 | { |
||
228 | return $this->get( 'product.config', [] ); |
||
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 | return $this->set( 'product.config', $config ); |
||
241 | } |
||
242 | |||
243 | |||
244 | /** |
||
245 | * Returns the starting point of time, in which the product is available. |
||
246 | * |
||
247 | * @return string|null ISO date in YYYY-MM-DD hh:mm:ss format |
||
248 | */ |
||
249 | public function getDateStart() : ?string |
||
250 | { |
||
251 | $value = $this->get( 'product.datestart' ); |
||
252 | return $value ? substr( $value, 0, 19 ) : null; |
||
253 | } |
||
254 | |||
255 | |||
256 | /** |
||
257 | * Sets a new starting point of time, in which the product is available. |
||
258 | * |
||
259 | * @param string|null $date New ISO date in YYYY-MM-DD hh:mm:ss format |
||
260 | * @return \Aimeos\MShop\Product\Item\Iface Product item for chaining method calls |
||
261 | */ |
||
262 | public function setDateStart( ?string $date ) : \Aimeos\MShop\Common\Item\Iface |
||
263 | { |
||
264 | return $this->set( 'product.datestart', \Aimeos\Utils::datetime( $date ) ); |
||
265 | } |
||
266 | |||
267 | |||
268 | /** |
||
269 | * Returns the ending point of time, in which the product is available. |
||
270 | * |
||
271 | * @return string|null ISO date in YYYY-MM-DD hh:mm:ss format |
||
272 | */ |
||
273 | public function getDateEnd() : ?string |
||
274 | { |
||
275 | $value = $this->get( 'product.dateend' ); |
||
276 | return $value ? substr( $value, 0, 19 ) : null; |
||
277 | } |
||
278 | |||
279 | |||
280 | /** |
||
281 | * Sets a new ending point of time, in which the product is available. |
||
282 | * |
||
283 | * @param string|null $date New ISO date in YYYY-MM-DD hh:mm:ss format |
||
284 | * @return \Aimeos\MShop\Product\Item\Iface Product item for chaining method calls |
||
285 | */ |
||
286 | public function setDateEnd( ?string $date ) : \Aimeos\MShop\Common\Item\Iface |
||
287 | { |
||
288 | return $this->set( 'product.dateend', \Aimeos\Utils::datetime( $date ) ); |
||
289 | } |
||
290 | |||
291 | |||
292 | /** |
||
293 | * Returns the rating of the item |
||
294 | * |
||
295 | * @return string Decimal value of the item rating |
||
296 | */ |
||
297 | public function getRating() : string |
||
298 | { |
||
299 | return (string) $this->get( 'product.rating', 0 ); |
||
300 | } |
||
301 | |||
302 | |||
303 | /** |
||
304 | * Returns the total number of ratings for the item |
||
305 | * |
||
306 | * @return int Total number of ratings for the item |
||
307 | */ |
||
308 | public function getRatings() : int |
||
309 | { |
||
310 | return (int) $this->get( 'product.ratings', 0 ); |
||
311 | } |
||
312 | |||
313 | |||
314 | /** |
||
315 | * Returns the quantity scale of the product item. |
||
316 | * |
||
317 | * @return float Quantity scale |
||
318 | */ |
||
319 | public function getScale() : float |
||
320 | { |
||
321 | return (float) $this->get( 'product.scale', 1 ) ?: 1; |
||
322 | } |
||
323 | |||
324 | |||
325 | /** |
||
326 | * Sets a new quantity scale of the product item. |
||
327 | * |
||
328 | * @param float $value New quantity scale |
||
329 | * @return \Aimeos\MShop\Product\Item\Iface Product item for chaining method calls |
||
330 | */ |
||
331 | public function setScale( float $value ) : \Aimeos\MShop\Product\Item\Iface |
||
332 | { |
||
333 | return $this->set( 'product.scale', $value > 0 ? $value : 1 ); |
||
334 | } |
||
335 | |||
336 | |||
337 | /** |
||
338 | * Returns the URL target specific for that product |
||
339 | * |
||
340 | * @return string URL target specific for that product |
||
341 | */ |
||
342 | public function getTarget() : string |
||
343 | { |
||
344 | return $this->get( 'product.target', '' ); |
||
345 | } |
||
346 | |||
347 | |||
348 | /** |
||
349 | * Sets a new URL target specific for that product |
||
350 | * |
||
351 | * @param string $value New URL target specific for that product |
||
352 | * @return \Aimeos\MShop\Product\Item\Iface Product item for chaining method calls |
||
353 | */ |
||
354 | public function setTarget( ?string $value ) : \Aimeos\MShop\Product\Item\Iface |
||
355 | { |
||
356 | return $this->set( 'product.target', (string) $value ); |
||
357 | } |
||
358 | |||
359 | |||
360 | /** |
||
361 | * Returns the create date of the item |
||
362 | * |
||
363 | * @return string|null ISO date in YYYY-MM-DD hh:mm:ss format |
||
364 | */ |
||
365 | public function getTimeCreated() : ?string |
||
366 | { |
||
367 | return $this->get( 'product.ctime' ); |
||
368 | } |
||
369 | |||
370 | |||
371 | /** |
||
372 | * Sets the create date of the item |
||
373 | * |
||
374 | * @param string|null $value ISO date in YYYY-MM-DD hh:mm:ss format |
||
375 | * @return \Aimeos\MShop\Product\Item\Iface Product item for chaining method calls |
||
376 | */ |
||
377 | public function setTimeCreated( ?string $value ) : \Aimeos\MShop\Product\Item\Iface |
||
380 | } |
||
381 | |||
382 | |||
383 | /** |
||
384 | * Returns the type of the product item. |
||
385 | * Overwritten for different default value. |
||
386 | * |
||
387 | * @return string Type of the product item |
||
388 | */ |
||
389 | public function getType() : string |
||
390 | { |
||
391 | return $this->get( 'product.type', 'default' ); |
||
392 | } |
||
393 | |||
394 | |||
395 | /** |
||
396 | * Tests if the item is available based on status, time, language and currency |
||
397 | * |
||
398 | * @return bool True if available, false if not |
||
399 | */ |
||
400 | public function isAvailable() : bool |
||
401 | { |
||
402 | $date = $this->get( '.date' ) ?: date( 'Y-m-d H:i:s' ); |
||
403 | |||
404 | return parent::isAvailable() && $this->getStatus() > 0 |
||
405 | && ( $this->getDateEnd() === null || $this->getDateEnd() > $date ) |
||
406 | && ( $this->getDateStart() === null || $this->getDateStart() < $date || $this->getType() === 'event' ); |
||
407 | } |
||
408 | |||
409 | |||
410 | /** |
||
411 | * Returns the flag if stock is available for that product. |
||
412 | * |
||
413 | * @return int "1" if product is in stock, "0" if product is out of stock |
||
414 | */ |
||
415 | public function inStock() : int |
||
418 | } |
||
419 | |||
420 | |||
421 | /** |
||
422 | * Sets the flag if stock is available for that product. |
||
423 | * |
||
424 | * @param int $value "1" if product is in stock, "0" if product is out of stock |
||
425 | * @return \Aimeos\MShop\Product\Item\Iface Product item for chaining method calls |
||
426 | */ |
||
427 | public function setInStock( int $value ) : \Aimeos\MShop\Product\Item\Iface |
||
428 | { |
||
429 | return $this->set( 'product.instock', $value ); |
||
430 | } |
||
431 | |||
432 | /** |
||
433 | * Returns the boost factor for that product. |
||
434 | * |
||
435 | * @return float Boost factor |
||
436 | */ |
||
437 | public function boost() : float |
||
438 | { |
||
439 | return (float) $this->get( 'product.boost', 1 ); |
||
440 | } |
||
441 | |||
442 | /** |
||
443 | * Sets the boost factor for that product. |
||
444 | * |
||
445 | * @param float $value Boost factor |
||
446 | * @return \Aimeos\MShop\Product\Item\Iface Product item for chaining method calls |
||
447 | */ |
||
448 | public function setBoost( float $value ) : \Aimeos\MShop\Product\Item\Iface |
||
451 | } |
||
452 | |||
453 | |||
454 | /* |
||
455 | * Sets the item values from the given array and removes that entries from the list |
||
456 | * |
||
457 | * @param array &$list Associative list of item keys and their values |
||
458 | * @param bool True to set private properties too, false for public only |
||
459 | * @return \Aimeos\MShop\Product\Item\Iface Product item for chaining method calls |
||
460 | */ |
||
461 | public function fromArray( array &$list, bool $private = false ) : \Aimeos\MShop\Common\Item\Iface |
||
490 | } |
||
491 | |||
492 | |||
493 | /** |
||
494 | * Returns the item values as array. |
||
495 | * |
||
496 | * @param bool True to return private properties, false for public only |
||
497 | * @return array Associative list of item properties and their values |
||
498 | */ |
||
499 | public function toArray( bool $private = false ) : array |
||
500 | { |
||
521 | } |
||
522 | } |
||
523 |
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