Total Complexity | 22 |
Total Lines | 181 |
Duplicated Lines | 43.09 % |
Changes | 7 | ||
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 |
||
8 | class GoogleAnalyticsReportServiceTest extends SapphireTest |
||
2 ignored issues
–
show
|
|||
9 | { |
||
10 | /** |
||
11 | * @var GoogleClientService |
||
12 | */ |
||
13 | protected $client; |
||
14 | |||
15 | /** |
||
16 | * @var GoogleAnalyticsReportService |
||
17 | */ |
||
18 | protected $service; |
||
19 | |||
20 | public function setUp() |
||
25 | } |
||
26 | |||
27 | public function testSetClient() |
||
28 | { |
||
29 | $this->service->setClient($this->client); |
||
30 | $this->assertInstanceOf(GoogleClientService::class, $this->service->getClient()); |
||
31 | } |
||
32 | |||
33 | public function testGetAnalytics() |
||
34 | { |
||
35 | $this->assertInstanceOf(Google_Service_AnalyticsReporting::class, $this->service->getAnalytics()); |
||
36 | } |
||
37 | |||
38 | public function testGetMetrics() |
||
39 | { |
||
40 | $this->assertInstanceOf(Google_Service_AnalyticsReporting_Metric::class, $this->service->getMetrics()); |
||
41 | } |
||
42 | |||
43 | public function testDateRange() |
||
44 | { |
||
45 | /* Set the daterange to 60 days */ |
||
46 | $this->service->setDateRange(60); |
||
47 | /** @var Google_Service_AnalyticsReporting_DateRange $dateRange */ |
||
48 | $dateRange = $this->service->getDateRange(); |
||
49 | |||
50 | $this->assertInstanceOf(Google_Service_AnalyticsReporting_DateRange::class, $dateRange); |
||
51 | |||
52 | $this->assertEquals('60daysAgo', $dateRange->getStartDate()); |
||
53 | } |
||
54 | |||
55 | View Code Duplication | public function testGetStartDimensionFilters() |
|
1 ignored issue
–
show
|
|||
56 | { |
||
57 | Config::inst()->update(GoogleAnalyticsReportService::class, 'starts_with', '/home'); |
||
58 | |||
59 | $filters = $this->service->getDimensionFilters(); |
||
60 | |||
61 | $this->assertTrue(is_array($filters)); |
||
62 | foreach ($filters as $filter) { |
||
63 | $this->assertInstanceOf(Google_Service_AnalyticsReporting_DimensionFilter::class, $filter); |
||
64 | } |
||
65 | } |
||
66 | |||
67 | View Code Duplication | public function testGetEndDimensionFilters() |
|
1 ignored issue
–
show
|
|||
68 | { |
||
69 | Config::inst()->update(GoogleAnalyticsReportService::class, 'ends_with', '/home'); |
||
70 | |||
71 | $filters = $this->service->getDimensionFilters(); |
||
72 | |||
73 | $this->assertTrue(is_array($filters)); |
||
74 | foreach ($filters as $filter) { |
||
75 | $this->assertInstanceOf(Google_Service_AnalyticsReporting_DimensionFilter::class, $filter); |
||
76 | } |
||
77 | } |
||
78 | |||
79 | public function testGetPageDimensionFilters() |
||
80 | { |
||
81 | $filters = $this->service->getDimensionFilters(); |
||
82 | |||
83 | $this->assertTrue(is_array($filters)); |
||
84 | foreach ($filters as $filter) { |
||
85 | $this->assertInstanceOf(Google_Service_AnalyticsReporting_DimensionFilter::class, $filter); |
||
86 | } |
||
87 | } |
||
88 | |||
89 | public function testGetDimensionFilterClauses() |
||
90 | { |
||
91 | $dimensionsClauses = $this->service->getDimensionFilterClauses(); |
||
92 | $this->assertInstanceOf(Google_Service_AnalyticsReporting_DimensionFilterClause::class, $dimensionsClauses); |
||
93 | $this->assertEquals('OR', $dimensionsClauses->getOperator()); |
||
94 | } |
||
95 | |||
96 | public function testGetPages() |
||
97 | { |
||
98 | $pages = $this->service->getPages(); |
||
99 | $this->assertTrue(is_array($pages)); |
||
100 | $this->assertLessThanOrEqual(20, count($pages)); |
||
101 | } |
||
102 | |||
103 | public function testFilterLength() |
||
104 | { |
||
105 | for ($i = 1; $i <= 30; $i++) { |
||
106 | /** @var Page` $page */ |
||
107 | $page = Page::create(['Title' => $i . ' test']); |
||
108 | $page->write(); |
||
109 | $page->doPublish(); |
||
110 | } |
||
111 | $pages = $this->service->getPages(); |
||
112 | $this->assertTrue(is_array($pages)); |
||
113 | $this->assertEquals(20, count($pages)); |
||
114 | $this->assertTrue($this->service->batched); |
||
115 | } |
||
116 | |||
117 | public function testFindHomePage() |
||
122 | } |
||
123 | |||
124 | View Code Duplication | public function testFindChildPage() |
|
1 ignored issue
–
show
|
|||
125 | { |
||
126 | /** @var Page $homePage */ |
||
127 | $homePage = Page::get()->filter(['URLSegment' => 'home'])->first(); |
||
128 | /** @var Page $homePage */ |
||
129 | $child = Page::create(['Title' => 'Test Page', 'ParentID' => $homePage->ID]); |
||
130 | $child->write(); |
||
131 | $child->doPublish(); |
||
132 | $testArray = ['', '', 'test-page']; |
||
133 | $page = $this->service->findPage($testArray); |
||
134 | $this->assertInstanceOf(Page::class, $page); |
||
135 | $this->assertEquals('/home/test-page/', $page->Link()); |
||
136 | } |
||
137 | |||
138 | View Code Duplication | public function testFindChildPageWithQuery() |
|
1 ignored issue
–
show
|
|||
139 | { |
||
140 | /** @var Page $homePage */ |
||
141 | $homePage = Page::get()->filter(['URLSegment' => 'home'])->first(); |
||
142 | /** @var Page $homePage */ |
||
143 | $child = Page::create(['Title' => 'Test Page', 'ParentID' => $homePage->ID]); |
||
144 | $child->write(); |
||
145 | $child->doPublish(); |
||
146 | $testArray = ['', '', 'test-page', '?stage=Stage']; |
||
147 | $page = $this->service->findPage($testArray); |
||
148 | $this->assertInstanceOf(Page::class, $page); |
||
149 | $this->assertEquals('/home/test-page/', $page->Link()); |
||
150 | } |
||
151 | |||
152 | View Code Duplication | public function testFindPageWithEmptyLast() |
|
164 | } |
||
165 | |||
166 | View Code Duplication | public function testGetBlacklistedPages() |
|
1 ignored issue
–
show
|
|||
167 | { |
||
168 | Config::inst()->update(GoogleAnalyticsReportService::class, 'blacklist', [ErrorPage::class]); |
||
169 | $pages = $this->service->getPages(); |
||
170 | $this->assertTrue(is_array($pages)); |
||
171 | $this->assertNotContains('page-not-found', $pages); |
||
172 | } |
||
173 | |||
174 | View Code Duplication | public function testGetWhitelistedPages() |
|
1 ignored issue
–
show
|
|||
175 | { |
||
183 | } |
||
184 | |||
185 | public function testUpdateVisits() |
||
191 |
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