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 |
||
26 | class ShortNamer implements SourceAccessorInterface |
||
27 | { |
||
28 | |||
29 | use Traits\SourceMagic; |
||
30 | |||
31 | /** |
||
32 | * Working class name |
||
33 | * @var string |
||
34 | */ |
||
35 | private $className = ''; |
||
36 | private $info = null; |
||
37 | |||
38 | public function __construct($className = null) |
||
43 | |||
44 | View Code Duplication | public function __get($name) |
|
55 | |||
56 | public function method($name) |
||
61 | |||
62 | public function property($name) |
||
67 | |||
68 | public static function __callStatic($name, $arguments) |
||
72 | |||
73 | public function __toString() |
||
77 | |||
78 | } |
||
79 |
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.