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 |
||
| 34 | class InstanceAssertion extends AbstractAssertion |
||
| 35 | { |
||
| 36 | /** |
||
| 37 | * @var string $operand The operand we have to check |
||
| 38 | */ |
||
| 39 | public $operand; |
||
| 40 | |||
| 41 | /** |
||
| 42 | * @var string $class The name of the class we have to check for |
||
| 43 | */ |
||
| 44 | public $class; |
||
| 45 | |||
| 46 | /** |
||
| 47 | * Default constructor |
||
| 48 | * |
||
| 49 | * @param string $operand The operand we have to check |
||
| 50 | * @param string $class The name of the class we have to check for |
||
| 51 | */ |
||
| 52 | public function __construct($operand, $class) |
||
| 59 | |||
| 60 | /** |
||
| 61 | * Will return a string representation of this assertion |
||
| 62 | * |
||
| 63 | * @return string |
||
| 64 | */ |
||
| 65 | public function getString() |
||
| 74 | |||
| 75 | /** |
||
| 76 | * Invert the logical meaning of this assertion |
||
| 77 | * |
||
| 78 | * @return bool |
||
| 79 | */ |
||
| 80 | public function invert() |
||
| 98 | |||
| 99 | /** |
||
| 100 | * Return a string representation of the classes logic as a piece of PHP code. |
||
| 101 | * Used to transfer important logic into generated code |
||
| 102 | * |
||
| 103 | * @return string |
||
| 104 | */ |
||
| 105 | View Code Duplication | public function toCode() |
|
| 116 | } |
||
| 117 |