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 PostgresDriver extends Driver |
||
| 20 | { |
||
| 21 | /** |
||
| 22 | * Driver type. |
||
| 23 | */ |
||
| 24 | const TYPE = DatabaseInterface::POSTGRES; |
||
| 25 | |||
| 26 | /** |
||
| 27 | * Driver schemas. |
||
| 28 | */ |
||
| 29 | //const SCHEMA_TABLE = TableSchema::class; |
||
| 30 | |||
| 31 | /** |
||
| 32 | * Query compiler class. |
||
| 33 | */ |
||
| 34 | const QUERY_COMPILER = QueryCompiler::class; |
||
| 35 | |||
| 36 | /** |
||
| 37 | * Default timestamp expression. |
||
| 38 | */ |
||
| 39 | const DATETIME_NOW = 'now()'; |
||
| 40 | |||
| 41 | /** |
||
| 42 | * Cached list of primary keys associated with their table names. Used by InsertBuilder to |
||
| 43 | * emulate last insert id. |
||
| 44 | * |
||
| 45 | * @var array |
||
| 46 | */ |
||
| 47 | private $primaryKeys = []; |
||
| 48 | |||
| 49 | /** |
||
| 50 | * {@inheritdoc} |
||
| 51 | */ |
||
| 52 | public function hasTable(string $name): bool |
||
| 58 | |||
| 59 | /** |
||
| 60 | * {@inheritdoc} |
||
| 61 | */ |
||
| 62 | public function truncateData(string $table) |
||
| 66 | |||
| 67 | /** |
||
| 68 | * {@inheritdoc} |
||
| 69 | */ |
||
| 70 | public function tableNames(): array |
||
| 81 | |||
| 82 | /** |
||
| 83 | * Get singular primary key associated with desired table. Used to emulate last insert id. |
||
| 84 | * |
||
| 85 | * @param string $prefix Database prefix if any. |
||
| 86 | * @param string $table Fully specified table name, including postfix. |
||
| 87 | * |
||
| 88 | * @return string|null |
||
| 89 | * |
||
| 90 | * @throws DriverException |
||
| 91 | */ |
||
| 92 | public function getPrimary(string $prefix, string $table): string |
||
| 123 | |||
| 124 | /** |
||
| 125 | * {@inheritdoc} |
||
| 126 | * |
||
| 127 | * Postgres uses custom insert query builder in order to return value of inserted row. |
||
| 128 | */ |
||
| 129 | View Code Duplication | public function insertBuilder(string $prefix, array $parameters = []): InsertQuery |
|
| 136 | |||
| 137 | /** |
||
| 138 | * {@inheritdoc} |
||
| 139 | */ |
||
| 140 | protected function createPDO(): \PDO |
||
| 148 | } |
||
| 149 |
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.
In this case you can add the
@ignorePhpDoc annotation to the duplicate definition and it will be ignored.