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 |
||
| 10 | abstract class AbstractComparisonOperatorCondition extends AbstractCondition |
||
| 11 | { |
||
| 12 | protected |
||
| 13 | $leftOperand, |
||
|
1 ignored issue
–
show
|
|||
| 14 | $rightOperand; |
||
| 15 | |||
| 16 | 158 | public function __construct(Type $leftOperand, $rightOperand) |
|
| 21 | |||
| 22 | 192 | public function toString(Escaper $escaper): string |
|
| 36 | |||
| 37 | 181 | private function generateFieldOperand(Type $field): string |
|
| 41 | |||
| 42 | 181 | private function generateRightOperand(Escaper $escaper) |
|
| 51 | |||
| 52 | 206 | public function isEmpty(): bool |
|
| 58 | |||
| 59 | abstract protected function getConditionOperator(): string; |
||
| 60 | |||
| 61 | 145 | View Code Duplication | private function escapeValue($value, Escaper $escaper) |
| 72 | } |
||
| 73 |
Only declaring a single property per statement allows you to later on add doc comments more easily.
It is also recommended by PSR2, so it is a common style that many people expect.