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 |
||
12 | class EnforceFQN extends AbstractPass |
||
13 | { |
||
14 | /** |
||
15 | * @var array List of global constants (constant names used as keys) |
||
16 | */ |
||
17 | protected $constants; |
||
18 | |||
19 | /** |
||
20 | * @var array List of internal functions (function names used as keys) |
||
21 | */ |
||
22 | protected $functions; |
||
23 | |||
24 | /** |
||
25 | * Constructor |
||
26 | */ |
||
27 | 15 | public function __construct() |
|
32 | |||
33 | /** |
||
34 | * {@inheritdoc} |
||
35 | */ |
||
36 | 15 | protected function optimizeStream() |
|
49 | |||
50 | /** |
||
51 | * Test whether current token is followed by an object operator or a namespace separator |
||
52 | * |
||
53 | * @return bool |
||
54 | */ |
||
55 | 15 | protected function isFollowedByOperator() |
|
65 | |||
66 | /** |
||
67 | * Test whether current token is followed by a parenthesis |
||
68 | * |
||
69 | * @return bool |
||
70 | */ |
||
71 | 15 | protected function isFollowedByParenthesis() |
|
81 | |||
82 | /** |
||
83 | * Test whether the token at given offset is preceded by a keyword |
||
84 | * |
||
85 | * @return bool |
||
86 | */ |
||
87 | 15 | protected function isPrecededByKeyword() |
|
107 | |||
108 | /** |
||
109 | * Optimize all constants and function calls in given range |
||
110 | * |
||
111 | * @param integer $startOffset |
||
112 | * @param integer $endOffset |
||
113 | * @return void |
||
114 | */ |
||
115 | 15 | protected function optimizeBlock($startOffset, $endOffset) |
|
134 | |||
135 | /** |
||
136 | * Process the constant at current offset |
||
137 | * |
||
138 | * @return void |
||
139 | */ |
||
140 | 15 | View Code Duplication | protected function processConstant() |
150 | |||
151 | /** |
||
152 | * Process the function name at current offset |
||
153 | * |
||
154 | * @return void |
||
155 | */ |
||
156 | 8 | View Code Duplication | protected function processFunctionCall() |
166 | } |