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 |
||
19 | abstract class AbstractRoute extends AbstractConfig implements |
||
20 | RouteInterface |
||
21 | { |
||
22 | /** |
||
23 | * @var string |
||
24 | */ |
||
25 | private $name; |
||
26 | |||
27 | /** |
||
28 | * @var string |
||
29 | */ |
||
30 | private $path; |
||
31 | |||
32 | /** |
||
33 | * @return bool |
||
34 | */ |
||
35 | public function hasName() |
||
39 | |||
40 | /** |
||
41 | * @return string |
||
42 | */ |
||
43 | public function getName() |
||
47 | |||
48 | /** |
||
49 | * {@inheritdoc} |
||
50 | */ |
||
51 | public function setName($name) |
||
56 | |||
57 | /** |
||
58 | * @return bool |
||
59 | */ |
||
60 | protected function hasPath() |
||
64 | |||
65 | /** |
||
66 | * @return string |
||
67 | */ |
||
68 | protected function getPath() |
||
72 | |||
73 | /** |
||
74 | * {@inheritdoc} |
||
75 | */ |
||
76 | public function setPath($path) |
||
82 | |||
83 | /** |
||
84 | * @param string $route |
||
85 | * @return $this |
||
86 | */ |
||
87 | protected function setRouteOption($route) |
||
92 | |||
93 | /** |
||
94 | * @return string |
||
95 | */ |
||
96 | public function getType() |
||
100 | |||
101 | /** |
||
102 | * {@inheritdoc} |
||
103 | */ |
||
104 | public function setType($type = self::LITERAL) |
||
109 | |||
110 | /** |
||
111 | * {@inheritdoc} |
||
112 | */ |
||
113 | public function setMayTerminate($mayTerminate = true) |
||
118 | |||
119 | /** |
||
120 | * @return array |
||
121 | */ |
||
122 | protected function getDefaults() |
||
126 | |||
127 | /** |
||
128 | * {@inheritdoc} |
||
129 | */ |
||
130 | View Code Duplication | public function setDefaults(array $defaults) |
|
138 | |||
139 | /** |
||
140 | * {@inheritdoc} |
||
141 | */ |
||
142 | public function setChild(array $routes) |
||
149 | |||
150 | /** |
||
151 | * {@inheritdoc} |
||
152 | */ |
||
153 | public function chain(array $routes) |
||
160 | |||
161 | /** |
||
162 | * @param array $handlers |
||
163 | * @return $this |
||
164 | */ |
||
165 | View Code Duplication | protected function setHandlers(array $handlers) |
|
173 | |||
174 | /** |
||
175 | * @param string $section |
||
176 | * @param self $route |
||
177 | * @return $this |
||
178 | */ |
||
179 | protected function appendRoute($section, self $route) |
||
194 | |||
195 | /** |
||
196 | * @param RouteInterface $route |
||
197 | * @return $this |
||
198 | */ |
||
199 | protected function appendChildRoute(RouteInterface $route) |
||
208 | } |
||
209 |
This check looks at variables that have been passed in as parameters and are passed out again to other methods.
If the outgoing method call has stricter type requirements than the method itself, an issue is raised.
An additional type check may prevent trouble.