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 |
||
19 | class SqliteDsn implements IDsn { |
||
20 | /** @var string */ |
||
21 | protected $path; |
||
22 | |||
23 | 4 | public function __construct(string $path = ':memory:') { |
|
26 | |||
27 | /** |
||
28 | * @param string $path |
||
29 | * @return SqliteDsn |
||
|
|||
30 | * @throws EmptyArgumentException |
||
31 | */ |
||
32 | 4 | View Code Duplication | public function setPath(string $path) : self { |
41 | |||
42 | /** |
||
43 | * @return string |
||
44 | */ |
||
45 | 2 | public function getPath() : string { |
|
48 | |||
49 | /** |
||
50 | * @return string |
||
51 | */ |
||
52 | 1 | public function toString() : string { |
|
55 | |||
56 | /** |
||
57 | * @return string |
||
58 | */ |
||
59 | 2 | public function __toString() : string { |
|
62 | } |
||
63 |
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.