Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
1 | <?php |
||
18 | class Gallery |
||
19 | { |
||
20 | /** @var integer materialFieldId Table materialField identifier */ |
||
21 | protected $materialFieldId = null; |
||
22 | |||
23 | /** @var QueryInterface Database query interface */ |
||
24 | protected $query; |
||
25 | |||
26 | /** |
||
27 | * Constructor Gallery. |
||
28 | * This constructor finds identifier additional field gallery from database record its material and field identifiers. |
||
29 | * |
||
30 | * @param QueryInterface $query Database query interface |
||
31 | * @param integer $materialId material identifier |
||
32 | * @param integer $fieldId field identifier |
||
33 | */ |
||
34 | public function __construct(QueryInterface $query, $materialId, $fieldId) |
||
53 | |||
54 | /** |
||
55 | * Check on empty gallery. If materialFieldId = 0 and quantity images not more 1 then material not has images. |
||
56 | * |
||
57 | * @return boolean |
||
58 | **/ |
||
59 | public function hasImages() |
||
73 | |||
74 | /** |
||
75 | * Get collection of images for material by gallery additional field selector. If none is passed |
||
76 | * all images from gallery table would be returned empty array. |
||
77 | * |
||
78 | * @return array |
||
79 | */ |
||
80 | public function getImages() |
||
96 | } |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.