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 |
||
25 | abstract class AbstractPaginationQuery implements FilterInterface |
||
26 | { |
||
27 | /** |
||
28 | * @var array |
||
29 | */ |
||
30 | protected $sortPropertiesMap = array(); |
||
31 | |||
32 | /** |
||
33 | * Store property name and converter to be used |
||
34 | * during result conversion |
||
35 | * |
||
36 | * @var array |
||
37 | */ |
||
38 | protected $propertiesMap = []; |
||
39 | |||
40 | /** |
||
41 | * @var Manager |
||
42 | */ |
||
43 | protected $manager = null; |
||
44 | |||
45 | /** |
||
46 | * AbstractPaginationQuery constructor. |
||
47 | * |
||
48 | * @param Manager $manager |
||
49 | */ |
||
50 | public function __construct(Manager $manager) |
||
54 | |||
55 | /** |
||
56 | * Filter query based on given value |
||
57 | * |
||
58 | * @param mixed $value |
||
59 | * @return \SolrQuery |
||
60 | */ |
||
61 | public function filter($value) |
||
67 | |||
68 | /** |
||
69 | * Returns sort parameter to be used for query |
||
70 | * |
||
71 | * @param $sort |
||
72 | * @return array |
||
73 | */ |
||
74 | protected function filterSort($sort) |
||
94 | |||
95 | /** |
||
96 | * Returs an array key => value for this pagination filter |
||
97 | * to define custom solr result handler |
||
98 | * @return array |
||
99 | * @codeCoverageIgnore |
||
100 | */ |
||
101 | public function getPropertiesMap() |
||
105 | |||
106 | /** |
||
107 | * Creates new instance for this filter |
||
108 | * |
||
109 | * @param ServiceLocatorInterface $sl |
||
110 | * @return static |
||
111 | */ |
||
112 | static public function factory(ServiceLocatorInterface $sl) |
||
117 | |||
118 | /** |
||
119 | * Returns class to be used for entity object creation |
||
120 | * |
||
121 | * @return string |
||
122 | */ |
||
123 | abstract public function getEntityClass(); |
||
124 | |||
125 | /** |
||
126 | * @param array $params |
||
127 | * @param \SolrQuery $query |
||
128 | * @return \SolrQuery |
||
129 | */ |
||
130 | abstract public function createQuery(array $params,$query); |
||
131 | } |
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.