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 |
||
11 | class XEEValidatorTest extends PHPUnit_Framework_TestCase |
||
12 | { |
||
13 | /** |
||
14 | * @var Spreadsheet |
||
15 | */ |
||
16 | private $spreadsheetXEETest; |
||
17 | |||
18 | /** |
||
19 | * @return Spreadsheet |
||
20 | */ |
||
21 | protected function loadXEETestFile() |
||
33 | |||
34 | /** |
||
35 | * @dataProvider providerInvalidXML |
||
36 | * @expectedException \PhpOffice\PhpSpreadsheet\Reader\Exception |
||
37 | * |
||
38 | * @param mixed $filename |
||
39 | */ |
||
40 | public function testInvalidXML($filename) |
||
47 | |||
48 | View Code Duplication | public function providerInvalidXML() |
|
57 | |||
58 | /** |
||
59 | * @dataProvider providerInvalidSimpleXML |
||
60 | * @expectedException \PhpOffice\PhpSpreadsheet\Reader\Exception |
||
61 | * |
||
62 | * @param $filename |
||
63 | */ |
||
64 | public function testInvalidSimpleXML($filename) |
||
69 | |||
70 | View Code Duplication | public function providerInvalidSimpleXML() |
|
79 | |||
80 | /** |
||
81 | * @dataProvider providerValidXML |
||
82 | * |
||
83 | * @param mixed $filename |
||
84 | * @param mixed $expectedResult |
||
85 | */ |
||
86 | public function testValidXML($filename, $expectedResult) |
||
92 | |||
93 | View Code Duplication | public function providerValidXML() |
|
102 | |||
103 | /** |
||
104 | * Check if it can read XML Hyperlink correctly. |
||
105 | */ |
||
106 | View Code Duplication | public function testReadHyperlinks() |
|
117 | } |
||
118 |
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.