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 |
||
15 | class NodeCollection extends Collection implements NodeCollectionInterface |
||
16 | { |
||
17 | /** |
||
18 | * {@inheritdoc} |
||
19 | */ |
||
20 | 9 | public function add($value) |
|
27 | |||
28 | /** |
||
29 | * {@inheritdoc} |
||
30 | */ |
||
31 | 2 | public function apply($fn) |
|
42 | |||
43 | /** |
||
44 | * On clone, clone all flows too |
||
45 | */ |
||
46 | public function __clone() |
||
52 | |||
53 | /** |
||
54 | * @return string |
||
55 | */ |
||
56 | public function __toString() |
||
60 | |||
61 | /** |
||
62 | * @inheritdoc |
||
63 | */ |
||
64 | public function getClone() |
||
68 | |||
69 | /** |
||
70 | * @param callable $fn |
||
|
|||
71 | * @param mixed|null $default |
||
72 | * |
||
73 | * @return NodeInterface|null |
||
74 | */ |
||
75 | 3 | View Code Duplication | public function first(callable $fn = null, $default = null) |
89 | |||
90 | /** |
||
91 | * @param callable $fn |
||
92 | * @param mixed|null $default |
||
93 | * |
||
94 | * @return NodeInterface|null |
||
95 | */ |
||
96 | 2 | View Code Duplication | public function last(callable $fn = null, $default = null) |
110 | } |
||
111 |
This check looks for
@param
annotations where the type inferred by our type inference engine differs from the declared type.It makes a suggestion as to what type it considers more descriptive.
Most often this is a case of a parameter that can be null in addition to its declared types.