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 XEEValidatorTest extends PHPUnit_Framework_TestCase |
||
11 | { |
||
12 | /** |
||
13 | * @dataProvider providerInvalidXML |
||
14 | * @expectedException \PhpOffice\PhpSpreadsheet\Reader\Exception |
||
15 | * |
||
16 | * @param mixed $filename |
||
17 | */ |
||
18 | public function testInvalidXML($filename) |
||
25 | |||
26 | View Code Duplication | public function providerInvalidXML() |
|
35 | |||
36 | /** |
||
37 | * @dataProvider providerInvalidSimpleXML |
||
38 | * @expectedException \PhpOffice\PhpSpreadsheet\Reader\Exception |
||
39 | * |
||
40 | * @param $filename |
||
41 | */ |
||
42 | public function testInvalidSimpleXML($filename) |
||
43 | { |
||
44 | $xmlReader = new Xml(); |
||
45 | $xmlReader->trySimpleXMLLoadString($filename); |
||
46 | } |
||
47 | |||
48 | View Code Duplication | public function providerInvalidSimpleXML() |
|
57 | |||
58 | /** |
||
59 | * @dataProvider providerValidXML |
||
60 | * |
||
61 | * @param mixed $filename |
||
62 | * @param mixed $expectedResult |
||
63 | */ |
||
64 | public function testValidXML($filename, $expectedResult) |
||
70 | |||
71 | View Code Duplication | public function providerValidXML() |
|
80 | } |
||
81 |
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.