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 |
||
18 | class MySqlUnixSocketDsn implements IDsn { |
||
19 | /** @var string */ |
||
20 | private $unixSocket; |
||
21 | |||
22 | /** @var string */ |
||
23 | private $dbName; |
||
24 | |||
25 | public function __construct(string $unixSocket, string $dbName) { |
||
29 | |||
30 | /** |
||
31 | * @param string $unixSocket |
||
32 | * @return MySqlUnixSocketDsn |
||
|
|||
33 | * @throws EmptyArgumentException |
||
34 | */ |
||
35 | public function setUnixSocket(string $unixSocket) : self { |
||
44 | |||
45 | /** |
||
46 | * @return string |
||
47 | */ |
||
48 | public function getUnixSocket() : string { |
||
51 | |||
52 | /** |
||
53 | * @param string $dbName |
||
54 | * @return MySqlUnixSocketDsn |
||
55 | * @throws EmptyArgumentException |
||
56 | */ |
||
57 | View Code Duplication | public function setDbName(string $dbName) : self { |
|
66 | |||
67 | /** |
||
68 | * @return string |
||
69 | */ |
||
70 | public function getDbName() : string { |
||
73 | |||
74 | public function toString() : string { |
||
77 | } |
||
78 |
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.