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 |
||
25 | View Code Duplication | class ClassBinding extends AbstractBinding |
|
|
|||
26 | { |
||
27 | /** |
||
28 | * @var string |
||
29 | */ |
||
30 | private $className; |
||
31 | |||
32 | /** |
||
33 | * Creates a new class binding. |
||
34 | * |
||
35 | * @param string $className The fully-qualified name of the bound |
||
36 | * class. |
||
37 | * @param string $typeName The name of the type to bind against. |
||
38 | * @param array $parameterValues The values of the parameters defined |
||
39 | * for the type. |
||
40 | * |
||
41 | * @throws NoSuchParameterException If an invalid parameter was passed. |
||
42 | * @throws MissingParameterException If a required parameter was not passed. |
||
43 | */ |
||
44 | 32 | public function __construct($className, $typeName, array $parameterValues = array()) |
|
50 | |||
51 | /** |
||
52 | * Returns the name of the bound class. |
||
53 | * |
||
54 | * @return string The fully-qualified class name. |
||
55 | */ |
||
56 | 1 | public function getClassName() |
|
60 | |||
61 | /** |
||
62 | * {@inheritdoc} |
||
63 | */ |
||
64 | public function equals(Binding $other) |
||
73 | |||
74 | /** |
||
75 | * {@inheritdoc} |
||
76 | */ |
||
77 | 14 | protected function preSerialize(array &$data) |
|
83 | |||
84 | /** |
||
85 | * {@inheritdoc} |
||
86 | */ |
||
87 | 8 | protected function postUnserialize(array &$data) |
|
93 | } |
||
94 |
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.