Total Complexity | 8 |
Total Lines | 159 |
Duplicated Lines | 44.65 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
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 |
||
20 | class DataObjectAnnotatorTest extends SapphireTest |
||
21 | { |
||
22 | |||
23 | /** |
||
24 | * @var MockDataObjectAnnotator |
||
1 ignored issue
–
show
|
|||
25 | */ |
||
26 | private $annotator; |
||
27 | |||
28 | /** |
||
29 | * @var AnnotatePermissionChecker $permissionChecker |
||
30 | */ |
||
31 | private $permissionChecker; |
||
32 | |||
33 | /** |
||
34 | * Setup Defaults |
||
35 | */ |
||
36 | View Code Duplication | public function setUp() |
|
37 | { |
||
38 | parent::setUp(); |
||
39 | Config::modify()->set(DataObjectAnnotator::class, 'enabled', true); |
||
40 | Config::modify()->set(DataObjectAnnotator::class, 'enabled_modules', ['ideannotator']); |
||
41 | |||
42 | $this->annotator = Injector::inst()->get(MockDataObjectAnnotator::class); |
||
43 | $this->permissionChecker = Injector::inst()->get(AnnotatePermissionChecker::class); |
||
44 | } |
||
45 | |||
46 | /** |
||
47 | * Test if the correct annotations are generated |
||
48 | * for all database fields, relations and extensions |
||
49 | * and that the start and end tags are present |
||
50 | */ |
||
51 | public function testFileContentWithAnnotations() |
||
52 | { |
||
53 | $classInfo = new AnnotateClassInfo(Team::class); |
||
1 ignored issue
–
show
|
|||
54 | $filePath = $classInfo->getClassFilePath(); |
||
55 | |||
56 | $content = $this->annotator->getGeneratedFileContent(file_get_contents($filePath), Team::class); |
||
57 | |||
58 | // ClassName title |
||
59 | $this->assertContains(' * Class \SilverLeague\IDEAnnotator\Tests\Team', $content); |
||
60 | |||
61 | // database fields |
||
62 | $this->assertContains('@property string $Title', $content); |
||
63 | $this->assertContains('@property int $VisitCount', $content); |
||
64 | $this->assertContains('@property float $Price', $content); |
||
65 | |||
66 | // has_one ID |
||
67 | $this->assertContains('@property int $CaptainID', $content); |
||
68 | // has_one relation |
||
69 | $this->assertContains('@method \SilverLeague\IDEAnnotator\Tests\Player Captain()', $content); |
||
70 | // has_many relation |
||
71 | $this->assertContains( |
||
72 | '@method \SilverStripe\ORM\DataList|\SilverLeague\IDEAnnotator\Tests\SubTeam[] SubTeams()', |
||
73 | $content |
||
74 | ); |
||
75 | // many_many relation |
||
76 | $this->assertContains( |
||
77 | '@method \SilverStripe\ORM\ManyManyList|\SilverLeague\IDEAnnotator\Tests\Player[] Players()', |
||
78 | $content |
||
79 | ); |
||
80 | $this->assertContains( |
||
81 | '@method \SilverStripe\ORM\ManyManyList|\SilverLeague\IDEAnnotator\Tests\Player[] Reserves()', |
||
82 | $content |
||
83 | ); |
||
84 | |||
85 | // DataExtension |
||
86 | $this->assertContains('@mixin \SilverLeague\IDEAnnotator\Tests\Team_Extension', $content); |
||
87 | } |
||
88 | |||
89 | View Code Duplication | public function testInversePlayerRelationOfTeam() |
|
90 | { |
||
91 | $classInfo = new AnnotateClassInfo(Player::class); |
||
1 ignored issue
–
show
|
|||
92 | $filePath = $classInfo->getClassFilePath(); |
||
93 | |||
94 | $content = $this->annotator->getGeneratedFileContent(file_get_contents($filePath), Player::class); |
||
95 | |||
96 | $this->assertContains('@property boolean $IsRetired', $content); |
||
97 | $this->assertContains('@property string $ShirtNumber', $content); |
||
98 | $this->assertContains('@property int $FavouriteTeamID', $content); |
||
99 | $this->assertContains('@method \SilverLeague\IDEAnnotator\Tests\Team FavouriteTeam()', $content); |
||
100 | |||
101 | $this->assertContains( |
||
102 | '@method \SilverStripe\ORM\ManyManyList|\SilverLeague\IDEAnnotator\Tests\Team[] TeamPlayer()', |
||
103 | $content |
||
104 | ); |
||
105 | $this->assertContains( |
||
106 | '@method \SilverStripe\ORM\ManyManyList|\SilverLeague\IDEAnnotator\Tests\Team[] TeamReserve()', |
||
107 | $content |
||
108 | ); |
||
109 | } |
||
110 | |||
111 | public function testExistingMethodsWillNotBeTagged() |
||
120 | ); |
||
121 | } |
||
122 | |||
123 | /** |
||
124 | * Test that multiple annotation runs won't generate ducplicate docblocks |
||
125 | */ |
||
126 | View Code Duplication | public function testNothingHasChangedAfterSecondAnnotation() |
|
127 | { |
||
128 | $classInfo = new AnnotateClassInfo(Team::class); |
||
129 | $filePath = $classInfo->getClassFilePath(); |
||
130 | $original = file_get_contents($filePath); |
||
131 | $firstRun = $this->annotator->getGeneratedFileContent($original, Team::class); |
||
132 | $secondRun = $this->annotator->getGeneratedFileContent($firstRun, Team::class); |
||
133 | $this->assertEquals($firstRun, $secondRun); |
||
134 | } |
||
135 | |||
136 | /** |
||
137 | * Test the generation of annotations for a DataExtension |
||
138 | */ |
||
139 | View Code Duplication | public function testAnnotateDataExtension() |
|
156 | ); |
||
157 | } |
||
158 | |||
159 | /** |
||
160 | * |
||
161 | */ |
||
162 | View Code Duplication | public function testTwoClassesInOneFile() |
|
163 | { |
||
164 | $classInfo = new AnnotateClassInfo(DoubleDataObjectInOneFile1::class); |
||
1 ignored issue
–
show
|
|||
165 | $filePath = $classInfo->getClassFilePath(); |
||
166 | $original = file_get_contents($filePath); |
||
167 | $annotated = $this->annotator->getGeneratedFileContent($original, DoubleDataObjectInOneFile1::class); |
||
168 | |||
169 | $this->assertContains('@property string $Title', $annotated); |
||
170 | |||
171 | $annotated = $this->annotator->getGeneratedFileContent($annotated, DoubleDataObjectInOneFile2::class); |
||
1 ignored issue
–
show
|
|||
172 | |||
173 | $this->assertContains('@property string $Name', $annotated); |
||
174 | } |
||
175 | |||
176 | public function tearDown() |
||
179 | } |
||
180 | } |
||
181 |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths