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 |
||
14 | View Code Duplication | class Fault implements FaultMessageInterface |
|
|
|||
15 | { |
||
16 | |||
17 | /** |
||
18 | * @property \GoetasWebservices\SoapServices\SoapClient\Envelope\SoapEnvelope12\Messages\FaultBody $body |
||
19 | */ |
||
20 | private $body = null; |
||
21 | |||
22 | /** |
||
23 | * Gets as body |
||
24 | * |
||
25 | * @return \GoetasWebservices\SoapServices\SoapClient\Envelope\SoapEnvelope12\Messages\FaultBody |
||
26 | */ |
||
27 | 5 | public function getBody() |
|
31 | |||
32 | /** |
||
33 | * Sets a new body |
||
34 | * |
||
35 | * @param \GoetasWebservices\SoapServices\SoapClient\Envelope\SoapEnvelope12\Messages\FaultBody $body |
||
36 | * @return self |
||
37 | */ |
||
38 | 3 | public function setBody(\GoetasWebservices\SoapServices\SoapClient\Envelope\SoapEnvelope12\Messages\FaultBody $body) |
|
43 | |||
44 | /** |
||
45 | * @param ResponseInterface $response |
||
46 | * @param RequestInterface $request |
||
47 | * @param \Exception $e |
||
48 | * @return FaultException |
||
49 | */ |
||
50 | 4 | public function createException(ResponseInterface $response, RequestInterface $request, \Exception $e = null) |
|
57 | |||
58 | } |
||
59 | |||
60 |
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.