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 |
||
21 | class YamlStorage implements Storage |
||
22 | { |
||
23 | /** |
||
24 | * The data collection. |
||
25 | * |
||
26 | * @var array |
||
27 | */ |
||
28 | private $data; |
||
29 | |||
30 | /** |
||
31 | * Constructor. |
||
32 | * |
||
33 | * @param string|null $formType The form type |
||
34 | * @param string|null $yamlFile The dir path of YAML file |
||
35 | */ |
||
36 | public function __construct($formType = null, $yamlFile = null) |
||
56 | |||
57 | /** |
||
58 | * {@inheritdoc} |
||
59 | */ |
||
60 | View Code Duplication | public function findAll($limit, $offset) |
|
73 | |||
74 | /** |
||
75 | * {@inheritdoc} |
||
76 | */ |
||
77 | View Code Duplication | public function query(array $criteria, $limit, $offset) |
|
95 | |||
96 | /** |
||
97 | * {@inheritdoc} |
||
98 | */ |
||
99 | public function properties() |
||
103 | |||
104 | /** |
||
105 | * {@inheritdoc} |
||
106 | */ |
||
107 | public function size() |
||
111 | |||
112 | /** |
||
113 | * Paginates the given collection of data. |
||
114 | * |
||
115 | * @param array $data The collection data |
||
116 | * @param int $limit Logs per page |
||
117 | * @param int $offset The number of the page |
||
118 | * |
||
119 | * @return array |
||
120 | */ |
||
121 | private function paginate($data, $limit, $offset) |
||
125 | |||
126 | /** |
||
127 | * Compares the given two items. |
||
128 | * |
||
129 | * @param mixed $item1 The first item |
||
130 | * @param mixed $item2 The second item |
||
131 | * |
||
132 | * @return int |
||
133 | */ |
||
134 | View Code Duplication | private function sort($item1, $item2) |
|
152 | } |
||
153 |