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 |
||
5 | View Code Duplication | trait Properties { |
|
6 | |||
7 | use Implementation; |
||
8 | |||
9 | /** |
||
10 | * @param string $name |
||
11 | * @return bool |
||
12 | */ |
||
13 | 5 | public function __isset(string $name) { |
|
22 | |||
23 | /** |
||
24 | * @param string $name |
||
25 | * @return \FluentDOM\DOM\Element|NULL |
||
26 | */ |
||
27 | 9 | public function __get(string $name) { |
|
36 | |||
37 | /** |
||
38 | * @param string $name |
||
39 | * @param $value |
||
40 | */ |
||
41 | 3 | public function __set(string $name, $value) { |
|
45 | |||
46 | /** |
||
47 | * @param string $name |
||
48 | */ |
||
49 | 1 | public function __unset(string $name) { |
|
53 | |||
54 | /** |
||
55 | * @param string $name |
||
56 | * @throws \BadMethodCallException |
||
57 | */ |
||
58 | 4 | protected function blockReadOnlyProperties(string $name) { |
|
70 | } |
||
71 | |||
72 | } |