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 declare(strict_types = 1); |
||
8 | class Expression |
||
9 | { |
||
10 | /** @var array */ |
||
11 | private $queryPartial; |
||
12 | |||
13 | /** |
||
14 | * Expression constructor. |
||
15 | */ |
||
16 | public function __construct() |
||
20 | |||
21 | /** |
||
22 | * @param array|Expression $expression |
||
23 | * |
||
24 | * @return $this |
||
25 | */ |
||
26 | View Code Duplication | public function and($expression) |
|
42 | |||
43 | /** |
||
44 | * @param array|Expression $expression |
||
45 | * |
||
46 | * @return $this |
||
47 | */ |
||
48 | View Code Duplication | public function or($expression) |
|
64 | |||
65 | /** |
||
66 | * @return array |
||
67 | */ |
||
68 | public function getQueryPartial(): array |
||
72 | |||
73 | /** |
||
74 | * @param string $operator |
||
75 | */ |
||
76 | private function prepareOperator(string $operator) |
||
82 | } |
||
83 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.