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 |
||
7 | final class FieldMap implements FieldNode |
||
8 | { |
||
9 | /** @var Node[] */ |
||
10 | private $fields; |
||
11 | |||
12 | /** @param Node[] $fields */ |
||
13 | public function __construct(array $fields) |
||
17 | |||
18 | /** |
||
19 | * @param string $name |
||
20 | * |
||
21 | * @return Node |
||
22 | */ |
||
23 | public function __get($name) |
||
27 | |||
28 | /** |
||
29 | * @param string $name |
||
30 | * |
||
31 | * @return Field |
||
|
|||
32 | * |
||
33 | * @throws FieldNotFoundException |
||
34 | */ |
||
35 | View Code Duplication | public function getField($name) |
|
43 | |||
44 | public function matches($criteria) |
||
59 | } |
||
60 |
This check compares the return type specified in the
@return
annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.