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 |
||
| 20 | View Code Duplication | final class UrlParamHandler extends AbstractParameterHandler |
|
| 21 | { |
||
| 22 | /** |
||
| 23 | * @var StringConverter |
||
| 24 | */ |
||
| 25 | private $converter; |
||
| 26 | |||
| 27 | /** |
||
| 28 | * Constructor |
||
| 29 | * |
||
| 30 | * @param StringConverter $converter |
||
| 31 | */ |
||
| 32 | 4 | public function __construct(StringConverter $converter) |
|
| 36 | |||
| 37 | /** |
||
| 38 | * Set a value to the [@see RequestBuilder] for parameter type |
||
| 39 | * |
||
| 40 | * @param RequestBuilder $requestBuilder |
||
| 41 | * @param mixed $value |
||
| 42 | * @return void |
||
| 43 | * @throws \RuntimeException |
||
| 44 | */ |
||
| 45 | 3 | public function apply(RequestBuilder $requestBuilder, $value): void |
|
| 53 | } |
||
| 54 |