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 |
||
| 25 | View Code Duplication | class Having implements Specification |
|
| 26 | { |
||
| 27 | /** |
||
| 28 | * @var Filter|QueryModifier|string |
||
| 29 | */ |
||
| 30 | protected $child; |
||
| 31 | |||
| 32 | /** |
||
| 33 | * @param Filter|QueryModifier|string $child |
||
| 34 | */ |
||
| 35 | public function __construct($child) |
||
| 39 | |||
| 40 | /** |
||
| 41 | * @param QueryBuilder $qb |
||
| 42 | * @param string $dqlAlias |
||
| 43 | */ |
||
| 44 | public function modify(QueryBuilder $qb, $dqlAlias) |
||
| 56 | |||
| 57 | /** |
||
| 58 | * @param QueryBuilder $qb |
||
| 59 | * @param string $dqlAlias |
||
| 60 | * |
||
| 61 | * @return string |
||
| 62 | */ |
||
| 63 | public function getFilter(QueryBuilder $qb, $dqlAlias) |
||
| 67 | } |
||
| 68 |
If you suppress an error, we recommend checking for the error condition explicitly: