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 |
||
10 | class Xml extends Callback |
||
11 | { |
||
12 | use ResultTrait; |
||
13 | use TransactionsTrait; |
||
14 | |||
15 | /** |
||
16 | * @var string |
||
17 | */ |
||
18 | protected $xml; |
||
19 | |||
20 | /** |
||
21 | * Holds an XML object based on the Xml::$xml string |
||
22 | * |
||
23 | * @var \SimpleXMLElement |
||
24 | */ |
||
25 | protected $xmlDoc; |
||
26 | |||
27 | /** |
||
28 | * @var string |
||
29 | */ |
||
30 | protected $version; |
||
31 | |||
32 | /** |
||
33 | * @var \DateTimeImmutable |
||
34 | */ |
||
35 | protected $date; |
||
36 | |||
37 | /** |
||
38 | * @var string |
||
39 | */ |
||
40 | protected $path; |
||
41 | |||
42 | /** |
||
43 | * @var int |
||
44 | */ |
||
45 | protected $errorCode; |
||
46 | |||
47 | /** |
||
48 | * @var string |
||
49 | */ |
||
50 | protected $errorMessage; |
||
51 | |||
52 | 9 | View Code Duplication | public function init() |
72 | |||
73 | 18 | public static function initable(ServerRequestInterface $request): bool |
|
79 | } |
||
80 |
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.