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 |
||
24 | abstract class Bitwise implements Operand |
||
25 | { |
||
26 | const B_AND = '&'; |
||
27 | |||
28 | const B_OR = '|'; |
||
29 | |||
30 | const B_XOR = '^'; |
||
31 | |||
32 | const B_LS = '<<'; |
||
33 | |||
34 | const B_RS = '>>'; |
||
35 | |||
36 | /** |
||
37 | * @var string[] |
||
38 | */ |
||
39 | private static $operations = [ |
||
40 | self::B_AND, |
||
41 | self::B_OR, |
||
42 | ]; |
||
43 | |||
44 | /** |
||
45 | * @var string |
||
46 | */ |
||
47 | private $operation; |
||
48 | |||
49 | /** |
||
50 | * @var Operand|string |
||
51 | */ |
||
52 | private $field; |
||
53 | |||
54 | /** |
||
55 | * @var Operand|string |
||
56 | */ |
||
57 | private $value; |
||
58 | |||
59 | /** |
||
60 | * @param string $operation |
||
61 | * @param Operand|string $field |
||
62 | * @param Operand|string $value |
||
63 | */ |
||
64 | View Code Duplication | public function __construct($operation, $field, $value) |
|
78 | |||
79 | /** |
||
80 | * @param QueryBuilder $qb |
||
81 | * @param string $dqlAlias |
||
82 | * |
||
83 | * @return string |
||
84 | */ |
||
85 | public function transform(QueryBuilder $qb, $dqlAlias) |
||
91 | } |
||
92 |
If you suppress an error, we recommend checking for the error condition explicitly: