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 declare(strict_types = 1); |
||
13 | abstract class InjectableAbstractConfigurator |
||
14 | { |
||
15 | /** @var string Method argument name */ |
||
16 | protected $argumentName; |
||
17 | |||
18 | /** @var string Method argument type */ |
||
19 | protected $argumentType; |
||
20 | |||
21 | /** |
||
22 | * InjectArgument constructor. |
||
23 | * |
||
24 | * @param string $argumentName Injected argument name |
||
25 | * @param string $argumentType Injected argument type hint |
||
26 | * |
||
27 | * @internal param array $valueOrValues |
||
28 | * |
||
29 | */ |
||
30 | public function __construct(string $argumentName, string $argumentType) |
||
35 | |||
36 | /** |
||
37 | * Build full class name. |
||
38 | * |
||
39 | * @param string $className Full or short class name |
||
40 | * @param string $namespace Name space |
||
41 | * |
||
42 | * @return string Full class name |
||
43 | */ |
||
44 | View Code Duplication | protected function buildFullClassName($className, $namespace) |
|
53 | } |
||
54 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.