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 |
||
18 | class RequestValidatorTest extends \PHPUnit_Framework_TestCase |
||
19 | { |
||
20 | /** |
||
21 | * @test |
||
22 | */ |
||
23 | public function canValidateDate() |
||
28 | |||
29 | /** |
||
30 | * @test |
||
31 | * @expectedException \KleijnWeb\SwaggerBundle\Exception\InvalidParametersException |
||
32 | */ |
||
33 | public function canInvalidateDate() |
||
39 | |||
40 | /** |
||
41 | * @test |
||
42 | */ |
||
43 | public function canValidateDateTime() |
||
49 | |||
50 | /** |
||
51 | * @test |
||
52 | * @expectedException \KleijnWeb\SwaggerBundle\Exception\InvalidParametersException |
||
53 | */ |
||
54 | public function canInvalidateDateTime() |
||
59 | |||
60 | /** |
||
61 | * @test |
||
62 | * @expectedException \KleijnWeb\SwaggerBundle\Exception\InvalidParametersException |
||
63 | */ |
||
64 | public function canUseAdditionalJsonSchemaConstraints() |
||
70 | |||
71 | |||
72 | /** |
||
73 | * @test |
||
74 | */ |
||
75 | View Code Duplication | public function canOmitParameterWhenNotExplicitlyMarkedAsRequired() |
|
93 | |||
94 | /** |
||
95 | * @test |
||
96 | * @expectedException \KleijnWeb\SwaggerBundle\Exception\InvalidParametersException |
||
97 | */ |
||
98 | View Code Duplication | public function cannotOmitParameterWhenExplicitlyMarkedAsRequired() |
|
116 | |||
117 | /** |
||
118 | * @test |
||
119 | * @expectedException \KleijnWeb\SwaggerBundle\Exception\InvalidParametersException |
||
120 | */ |
||
121 | View Code Duplication | public function cannotOmitBodyWhenExplicitlyMarkedAsRequired() |
|
140 | |||
141 | /** |
||
142 | * @param mixed $value |
||
143 | * @param string $rawValue |
||
144 | * @param string $format |
||
145 | * |
||
146 | * @param array $additionalParameterProperties |
||
147 | * |
||
148 | * @throws \KleijnWeb\SwaggerBundle\Exception\InvalidParametersException |
||
149 | */ |
||
150 | private function runStringTest($value, $rawValue, $format, array $additionalParameterProperties = []) |
||
186 | } |
||
187 |
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.