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 |
||
10 | class Collection |
||
11 | { |
||
12 | /** |
||
13 | * @var array |
||
14 | */ |
||
15 | protected $types = []; |
||
16 | |||
17 | /** |
||
18 | * Nested constructor. |
||
19 | * @param array $types |
||
20 | */ |
||
21 | 11 | public function __construct(array $types) |
|
25 | |||
26 | /** |
||
27 | * @return array |
||
28 | */ |
||
29 | 7 | public function properties(): array |
|
33 | |||
34 | /** |
||
35 | * @param $key |
||
36 | * @return bool |
||
37 | */ |
||
38 | 9 | public function has($key): bool |
|
42 | |||
43 | /** |
||
44 | * @param $key |
||
45 | * @return string |
||
46 | */ |
||
47 | 8 | public function get($key): string |
|
55 | } |
||
56 |