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 | final class PropertiesMethodsMutualSpacingSniff implements PHP_CodeSniffer_Sniff |
||
19 | { |
||
20 | |||
21 | /** |
||
22 | * @var int |
||
23 | */ |
||
24 | public $blankLinesInBetween = 2; |
||
25 | |||
26 | |||
27 | /** |
||
28 | * {@inheritdoc} |
||
29 | */ |
||
30 | 1 | public function register() |
|
34 | |||
35 | |||
36 | /** |
||
37 | * {@inheritdoc} |
||
38 | */ |
||
39 | 1 | public function process(PHP_CodeSniffer_File $file, $position) |
|
66 | |||
67 | |||
68 | /** |
||
69 | * @param PHP_CodeSniffer_File $file |
||
70 | * @param int $position |
||
71 | * @return bool |
||
72 | */ |
||
73 | 1 | private function isLastProperty(PHP_CodeSniffer_File $file, $position) |
|
87 | |||
88 | |||
89 | /** |
||
90 | * @param PHP_CodeSniffer_File $file |
||
91 | * @param int $position |
||
92 | * @return bool |
||
93 | */ |
||
94 | 1 | View Code Duplication | private function isInsideMethod(PHP_CodeSniffer_File $file, $position) |
103 | |||
104 | |||
105 | /** |
||
106 | * @param PHP_CodeSniffer_File $file |
||
107 | * @param int $position |
||
108 | * @return bool |
||
109 | */ |
||
110 | 1 | View Code Duplication | private function areMethodsPresent(PHP_CodeSniffer_File $file, $position) |
119 | |||
120 | |||
121 | /** |
||
122 | * @param PHP_CodeSniffer_File $file |
||
123 | * @param int $position |
||
124 | * @return int |
||
125 | */ |
||
126 | 1 | private function getEndOfProperty(PHP_CodeSniffer_File $file, $position) |
|
144 | |||
145 | } |
||
146 |