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 |
||
9 | class PhanTextLoader implements FileChecker |
||
10 | { |
||
11 | protected $lineMatch = '#(?:\./)?(?P<fileName>.*?):(?P<lineNumber>[0-9]+)(?P<message>.*)#'; |
||
12 | |||
13 | /** |
||
14 | * @var string |
||
15 | */ |
||
16 | protected $file; |
||
17 | |||
18 | /** |
||
19 | * @var array |
||
20 | */ |
||
21 | protected $errors = []; |
||
22 | |||
23 | /** |
||
24 | * PhanJsonLoader constructor. |
||
25 | * @param string $file the path to the file containing phan output |
||
26 | */ |
||
27 | public function __construct($file) |
||
31 | |||
32 | /** |
||
33 | * {@inheritdoc} |
||
34 | */ |
||
35 | public function parseLines() |
||
48 | |||
49 | /** |
||
50 | * {@inheritdoc} |
||
51 | */ |
||
52 | View Code Duplication | public function getErrorsOnLine($file, $lineNumber) |
|
61 | |||
62 | /** |
||
63 | * {@inheritdoc} |
||
64 | */ |
||
65 | public function handleNotFoundFile() |
||
69 | |||
70 | /** |
||
71 | * {@inheritdoc} |
||
72 | */ |
||
73 | public static function getDescription() |
||
77 | |||
78 | private function checkForFile($line) |
||
82 | |||
83 | private function addError($line) |
||
89 | } |
||
90 |
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.