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 | class SpreadsheetLoader implements SpreadsheetLoaderInterface |
||
15 | { |
||
16 | /** |
||
17 | * @var string |
||
18 | */ |
||
19 | protected $spreadsheetClass; |
||
20 | |||
21 | /** |
||
22 | * @var RelationshipsLoader |
||
23 | */ |
||
24 | protected $relationshipsLoader; |
||
25 | |||
26 | /** |
||
27 | * @var SharedStringsLoader |
||
28 | */ |
||
29 | protected $sharedStringsLoader; |
||
30 | |||
31 | /** |
||
32 | * @var StylesLoader |
||
33 | */ |
||
34 | protected $stylesLoader; |
||
35 | |||
36 | /** |
||
37 | * @var WorksheetListReader |
||
38 | */ |
||
39 | protected $worksheetListReader; |
||
40 | |||
41 | /** |
||
42 | * @var ValueTransformerFactory |
||
43 | */ |
||
44 | protected $valueTransformerFactory; |
||
45 | |||
46 | /** |
||
47 | * @var RowIteratorFactory |
||
48 | */ |
||
49 | protected $rowIteratorFactory; |
||
50 | |||
51 | /** |
||
52 | * @var ArchiveLoader |
||
53 | */ |
||
54 | protected $archiveLoader; |
||
55 | |||
56 | /** |
||
57 | * Constructor |
||
58 | * |
||
59 | * @param ArchiveLoader $archiveLoader |
||
60 | * @param RelationshipsLoader $relationshipsLoader |
||
61 | * @param SharedStringsLoader $sharedStringsLoader |
||
62 | * @param StylesLoader $stylesLoader |
||
63 | * @param WorksheetListReader $worksheetListReader |
||
64 | * @param ValueTransformerFactory $valueTransformerFactory |
||
65 | * @param RowIteratorFactory $rowIteratorFactory |
||
66 | * @param string $spreadsheetClass |
||
67 | */ |
||
68 | View Code Duplication | public function __construct( |
|
87 | |||
88 | /** |
||
89 | * {@inheritdoc} |
||
90 | */ |
||
91 | public function open($path, $type = null) |
||
105 | |||
106 | } |
||
107 |
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.