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 |
||
| 15 | final class Validator |
||
| 16 | { |
||
| 17 | /** |
||
| 18 | * @var ObjectFacade |
||
| 19 | */ |
||
| 20 | private $facade; |
||
| 21 | |||
| 22 | /** |
||
| 23 | * Validator constructor. |
||
| 24 | * |
||
| 25 | * @param ObjectFacade $facade |
||
| 26 | */ |
||
| 27 | public function __construct(ObjectFacade $facade) |
||
| 31 | |||
| 32 | /** |
||
| 33 | * @param ObjectFacade $facade |
||
| 34 | * |
||
| 35 | * @return Validator |
||
| 36 | */ |
||
| 37 | public static function new(ObjectFacade $facade): self |
||
| 41 | |||
| 42 | /** |
||
| 43 | * @param ReflectionProperty $property |
||
| 44 | * |
||
| 45 | * @return bool |
||
| 46 | */ |
||
| 47 | public function isValidProperty(ReflectionProperty $property): bool |
||
| 63 | |||
| 64 | /** |
||
| 65 | * @param ReflectionMethod $method |
||
| 66 | * |
||
| 67 | * @return bool |
||
| 68 | */ |
||
| 69 | public function isValidMethod(ReflectionMethod $method): bool |
||
| 85 | |||
| 86 | /** |
||
| 87 | * @param ReflectionMethod $method |
||
| 88 | * @param $value |
||
| 89 | * |
||
| 90 | * @return bool |
||
| 91 | */ |
||
| 92 | public function isValidSetterMethod(ReflectionMethod $method, $value): bool |
||
| 130 | |||
| 131 | /** |
||
| 132 | * @param ReflectionParameter $parameter |
||
| 133 | * @param $value |
||
| 134 | * |
||
| 135 | * @return bool |
||
| 136 | */ |
||
| 137 | public function isValidValue(ReflectionParameter $parameter, $value): bool |
||
| 141 | |||
| 142 | /** |
||
| 143 | * @param ReflectionMethod $method |
||
| 144 | * |
||
| 145 | * @return bool |
||
| 146 | */ |
||
| 147 | public function validateGetterMethod(ReflectionMethod $method): bool |
||
| 162 | } |