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 |
||
27 | class Source implements SourceAccessorInterface |
||
28 | { |
||
29 | |||
30 | use Traits\SourceMagic; |
||
31 | |||
32 | /** |
||
33 | * Reflection information |
||
34 | * @var ReflectionClass |
||
35 | */ |
||
36 | private $info = null; |
||
37 | |||
38 | /** |
||
39 | * Source as array |
||
40 | * @var string[] |
||
41 | */ |
||
42 | private $source = []; |
||
43 | |||
44 | public function __construct($className = null) |
||
49 | |||
50 | /** |
||
51 | * Should return source of working class |
||
52 | */ |
||
53 | public function __toString() |
||
57 | |||
58 | public static function __callStatic($name, $arguments) |
||
62 | |||
63 | /** |
||
64 | * Get source code of method |
||
65 | * @param string $name |
||
66 | * @return Wrapper |
||
67 | */ |
||
68 | View Code Duplication | public function method($name) |
|
79 | |||
80 | /** |
||
81 | * Get source code of property |
||
82 | * @param string $name |
||
83 | * @return Wrapper |
||
84 | */ |
||
85 | View Code Duplication | public function property($name) |
|
97 | |||
98 | private function getMethodSource($start, $end) |
||
112 | |||
113 | public function getPropertySource(ReflectionProperty $property) |
||
138 | |||
139 | } |
||
140 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.