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 |
||
| 35 | class TypeAssertion extends AbstractAssertion |
||
| 36 | { |
||
| 37 | /** |
||
| 38 | * @var string $operand The operand we have to check |
||
| 39 | */ |
||
| 40 | public $operand; |
||
| 41 | |||
| 42 | /** |
||
| 43 | * @var string $type The type we have to check for |
||
| 44 | */ |
||
| 45 | public $type; |
||
| 46 | |||
| 47 | /** |
||
| 48 | * @var bool $validatesTo The bool value we should test against |
||
| 49 | */ |
||
| 50 | public $validatesTo; |
||
| 51 | |||
| 52 | /** |
||
| 53 | * Default constructor |
||
| 54 | * |
||
| 55 | * @param string $operand The operand we have to check |
||
| 56 | * @param string $type The type we have to check for |
||
| 57 | */ |
||
| 58 | public function __construct($operand, $type) |
||
| 66 | |||
| 67 | /** |
||
| 68 | * Will return a string representation of this assertion. Will return false if the type is unknown. |
||
| 69 | * |
||
| 70 | * @return string |
||
| 71 | * |
||
| 72 | * @throws \AppserverIo\Doppelgaenger\Exceptions\ParserException |
||
| 73 | */ |
||
| 74 | public function getString() |
||
| 88 | |||
| 89 | /** |
||
| 90 | * Invert the logical meaning of this assertion |
||
| 91 | * |
||
| 92 | * @return boolean |
||
| 93 | */ |
||
| 94 | public function invert() |
||
| 112 | |||
| 113 | /** |
||
| 114 | * Return a string representation of the classes logic as a piece of PHP code. |
||
| 115 | * Used to transfer important logic into generated code |
||
| 116 | * |
||
| 117 | * @return string |
||
| 118 | */ |
||
| 119 | View Code Duplication | public function toCode() |
|
| 131 | } |
||
| 132 |