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() |
||
54 | { |
||
55 | return $this->getTypeSource(); |
||
56 | } |
||
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) |
||
111 | |||
112 | public function getPropertySource(ReflectionProperty $property) |
||
136 | |||
137 | private function getTypeSource() |
||
141 | |||
142 | } |
||
143 |