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 |
||
17 | class InjectArgument extends AnnotationWithValue implements MethodInterface |
||
18 | { |
||
19 | /** @var string Method argument name */ |
||
20 | protected $argumentName; |
||
21 | |||
22 | /** @var string Method argument type */ |
||
23 | protected $argumentType; |
||
24 | |||
25 | /** |
||
26 | * InjectArgument constructor. |
||
27 | * |
||
28 | * @param array $valueOrValues |
||
29 | * |
||
30 | * @throws \InvalidArgumentException |
||
31 | */ |
||
32 | 6 | public function __construct(array $valueOrValues) |
|
40 | |||
41 | /** |
||
42 | * {@inheritdoc} |
||
43 | * |
||
44 | * @throws \InvalidArgumentException |
||
45 | */ |
||
46 | 5 | public function toMethodMetadata(MethodMetadata $methodMetadata) |
|
74 | |||
75 | /** |
||
76 | * Check method argument existance. |
||
77 | * |
||
78 | * @param string $argument |
||
79 | * @param MethodMetadata $methodMetadata |
||
80 | * |
||
81 | * @return bool True if @InjectArgument argument name is valid |
||
82 | */ |
||
83 | 5 | protected function checkArgumentExists(string $argument, MethodMetadata $methodMetadata) : bool |
|
87 | |||
88 | /** |
||
89 | * Build full class name. |
||
90 | * |
||
91 | * @param string $className Full or short class name |
||
92 | * @param string $namespace Name space |
||
93 | * |
||
94 | * @return string Full class name |
||
95 | */ |
||
96 | 3 | View Code Duplication | protected function buildFullClassName($className, $namespace) |
105 | } |
||
106 |
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.