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 | class PgSQLDatabase implements DatabaseInterface |
||
8 | { |
||
9 | protected $console; |
||
10 | protected $database; |
||
11 | protected $schema; |
||
12 | protected $username; |
||
13 | protected $password; |
||
14 | protected $host; |
||
15 | protected $port; |
||
16 | |||
17 | /** |
||
18 | * @param Console $console |
||
19 | * @param $database |
||
20 | * @param string $schema |
||
21 | * @param $username |
||
22 | * @param $password |
||
23 | * @param string $host |
||
24 | * @param int $port |
||
25 | * @param string $socket |
||
|
|||
26 | */ |
||
27 | View Code Duplication | public function __construct(Console $console, $database, $schema, $username, $password, $host, $port) |
|
37 | |||
38 | /** |
||
39 | * Create a database dump. |
||
40 | * |
||
41 | * @param $destinationFile |
||
42 | * |
||
43 | * @return bool |
||
44 | */ |
||
45 | public function dump($destinationFile) |
||
63 | |||
64 | /** |
||
65 | * Return the file extension of a dump file (sql, ...). |
||
66 | * |
||
67 | * @return string |
||
68 | */ |
||
69 | public function getFileExtension() |
||
73 | |||
74 | /** |
||
75 | * Get the path to the pgsql_dump. |
||
76 | * |
||
77 | * @return string |
||
78 | */ |
||
79 | protected function getDumpCommandPath() |
||
83 | |||
84 | /** |
||
85 | * Determine if COPY should be used instead of INSERT. |
||
86 | */ |
||
87 | protected function useCopy() |
||
91 | } |
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.
Consider the following example. The parameter
$italy
is not defined by the methodfinale(...)
.The most likely cause is that the parameter was removed, but the annotation was not.