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 |
||
12 | class HumbugLoader implements FileChecker |
||
13 | { |
||
14 | /** |
||
15 | * @var string |
||
16 | */ |
||
17 | protected $json; |
||
18 | /** |
||
19 | * @var array |
||
20 | */ |
||
21 | protected $invalidLines; |
||
22 | |||
23 | protected $errorMethods = [ |
||
24 | 'errored', |
||
25 | 'escaped', |
||
26 | ]; |
||
27 | |||
28 | /** |
||
29 | * HumbugLoader constructor. |
||
30 | * @param string $filePath the file path to json output of humbug |
||
31 | */ |
||
32 | View Code Duplication | public function __construct($filePath) |
|
41 | |||
42 | /** |
||
43 | * {@inheritdoc} |
||
44 | */ |
||
45 | public function getLines() |
||
63 | |||
64 | /** |
||
65 | * {@inheritdoc} |
||
66 | */ |
||
67 | public function isValidLine($file, $lineNumber) |
||
71 | |||
72 | /** |
||
73 | * {@inheritdoc} |
||
74 | */ |
||
75 | public function handleNotFoundFile() |
||
79 | |||
80 | /** |
||
81 | * {@inheritdoc} |
||
82 | */ |
||
83 | public static function getDescription() |
||
87 | } |
||
88 |
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.