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 |
||
10 | class DaoParametersBehavior extends BaseDaoBehavior |
||
11 | { |
||
12 | protected $variants; |
||
13 | |||
14 | protected $parameters; |
||
15 | |||
16 | protected $parametersName; |
||
17 | |||
18 | /** |
||
19 | * @param string $condition |
||
20 | * @param array $parameters |
||
21 | * @param bool $refresh сбросить кэш |
||
22 | * @param string|null $indexBy использовать это поле в качестве ключа в выходном массиве |
||
23 | * |
||
24 | * @return array |
||
25 | */ |
||
26 | View Code Duplication | public function getVariantsByCondition($condition = '', array $parameters = array(), $refresh = false, $indexBy = 'id') |
|
34 | |||
35 | /** |
||
36 | * @param CDbCriteria $criteria |
||
37 | * @param bool $refresh сбросить кэш |
||
38 | * @param string|null $indexBy использовать это поле в качестве ключа в выходном массиве |
||
39 | * |
||
40 | * @return array |
||
41 | */ |
||
42 | View Code Duplication | public function getVariantsByCriteria(CDbCriteria $criteria, $refresh = false, $indexBy = null) |
|
54 | |||
55 | /** |
||
56 | * @param string $condition |
||
57 | * @param array $parameters |
||
58 | * @param bool $refresh сбросить кэш |
||
59 | * @param string|null $indexBy использовать это поле в качестве ключа в выходном массиве |
||
60 | * |
||
61 | * @return array |
||
62 | */ |
||
63 | View Code Duplication | public function getParametersNameByCondition($condition = '', array $parameters = array(), $refresh = false, $indexBy = 'id') |
|
71 | |||
72 | /** |
||
73 | * @param CDbCriteria $criteria |
||
74 | * @param bool $refresh сбросить кэш |
||
75 | * @param string|null $indexBy использовать это поле в качестве ключа в выходном массиве |
||
76 | * |
||
77 | * @return array |
||
78 | */ |
||
79 | View Code Duplication | public function getParametersNameByCriteria(CDbCriteria $criteria, $refresh = false, $indexBy = null) |
|
91 | |||
92 | /** |
||
93 | * @param CDbCriteria $criteria |
||
94 | * @param bool $refresh сбросить кэш |
||
95 | * @param string|null $indexBy использовать это поле в качестве ключа в выходном массиве |
||
96 | * |
||
97 | * @return array |
||
98 | */ |
||
99 | View Code Duplication | public function getParametersByCriteria(CDbCriteria $criteria, $refresh = false, $indexBy = 'id') |
|
111 | |||
112 | /** |
||
113 | * @param string $condition |
||
114 | * @param array $parameters |
||
115 | * @param bool $refresh сбросить кэш |
||
116 | * @param string|null $indexBy использовать это поле в качестве ключа в выходном массиве |
||
117 | * |
||
118 | * @return array |
||
119 | */ |
||
120 | View Code Duplication | public function getParametersByCriteriaByCondition($condition = '', array $parameters = array(), $refresh = false, $indexBy = null) |
|
128 | } |
The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.
The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.
To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.