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 JSONTextIntegrationTest extends SapphireTest |
||
15 | { |
||
16 | /** |
||
17 | * @var string |
||
18 | */ |
||
19 | protected static $fixture_file; |
||
20 | |||
21 | /** |
||
22 | * Modifies fixtures property to be able to run on PHP <5.6 without use of constant in class property which 5.6+ allows |
||
23 | */ |
||
24 | public function __construct() |
||
32 | |||
33 | /** |
||
34 | * Allows us the ability to scaffold DB records for {@link TestOnly} implementations. |
||
35 | * @var array |
||
36 | */ |
||
37 | protected static $extra_dataobjects = [ |
||
38 | MyAwesomeJSONModel::class |
||
39 | ]; |
||
40 | |||
41 | /** |
||
42 | * Tests JSONText::setValue() by means of a simple JSONPath expression operating on a nested JSON array |
||
43 | * on a saved DataObject record. |
||
44 | */ |
||
45 | View Code Duplication | public function testSetValueOnNestedArray() |
|
70 | |||
71 | /** |
||
72 | * Tests JSONText::setValue() by means of a simple JSONPath expression operating on a simple, un-nested JSON array |
||
73 | * on a saved DataObject record. |
||
74 | */ |
||
75 | View Code Duplication | public function testSetValueOnUnNestedArray() |
|
99 | |||
100 | } |
||
101 |
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.