Total Complexity | 17 |
Total Lines | 173 |
Duplicated Lines | 26.01 % |
Changes | 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 | /** |
||
21 | * Create the Services |
||
22 | */ |
||
23 | public function setUp() |
||
28 | } |
||
29 | |||
30 | /** |
||
31 | * Check if we can set and get the client |
||
32 | */ |
||
33 | public function testSetClient() |
||
34 | { |
||
35 | $this->service->setClient($this->client); |
||
36 | $this->assertInstanceOf(GoogleClientService::class, $this->service->getClient()); |
||
37 | } |
||
38 | |||
39 | /** |
||
40 | * See if we have a new Service registered |
||
41 | */ |
||
42 | public function testGetAnalytics() |
||
43 | { |
||
44 | $this->assertInstanceOf(Google_Service_AnalyticsReporting::class, $this->service->getAnalytics()); |
||
45 | } |
||
46 | |||
47 | /** |
||
48 | * Check if the Metric is set |
||
49 | */ |
||
50 | public function testGetMetrics() |
||
51 | { |
||
52 | $this->assertInstanceOf(Google_Service_AnalyticsReporting_Metric::class, $this->service->getMetrics()); |
||
53 | } |
||
54 | |||
55 | /** |
||
56 | * Check if setting the daterange updates the Analytics_DateRange |
||
57 | */ |
||
58 | public function testDateRange() |
||
59 | { |
||
60 | /* Set the daterange to 60 days */ |
||
61 | $this->service->setDateRange(60); |
||
62 | /** @var Google_Service_AnalyticsReporting_DateRange $dateRange */ |
||
63 | $dateRange = $this->service->getDateRange(); |
||
64 | |||
65 | $this->assertInstanceOf(Google_Service_AnalyticsReporting_DateRange::class, $dateRange); |
||
66 | |||
67 | $this->assertEquals('60daysAgo', $dateRange->getStartDate()); |
||
68 | } |
||
69 | |||
70 | /** |
||
71 | * Validate start_with filter |
||
72 | */ |
||
73 | View Code Duplication | public function testGetStartDimensionFilters() |
|
74 | { |
||
75 | Config::inst()->update(GoogleAnalyticsReportService::class, 'starts_with', '/'); |
||
76 | |||
77 | $filters = $this->service->getDimensionFilters(); |
||
78 | |||
79 | $this->assertTrue(is_array($filters)); |
||
80 | /** @var $filter */ |
||
81 | foreach ($filters as $filter) { |
||
82 | $this->assertInstanceOf(Google_Service_AnalyticsReporting_DimensionFilter::class, $filter); |
||
83 | $expressions = $filter->getExpressions(); |
||
84 | $this->assertEquals('/', $expressions[0]); |
||
85 | $this->assertEquals('BEGINS_WITH', $filter->getOperator()); |
||
86 | } |
||
87 | } |
||
88 | |||
89 | /** |
||
90 | * validate end_with filter |
||
91 | */ |
||
92 | View Code Duplication | public function testGetEndDimensionFilters() |
|
93 | { |
||
94 | Config::inst()->update(GoogleAnalyticsReportService::class, 'ends_with', '/'); |
||
95 | |||
96 | $filters = $this->service->getDimensionFilters(); |
||
97 | |||
98 | $this->assertTrue(is_array($filters)); |
||
99 | foreach ($filters as $filter) { |
||
100 | $this->assertInstanceOf(Google_Service_AnalyticsReporting_DimensionFilter::class, $filter); |
||
101 | $expressions = $filter->getExpressions(); |
||
102 | $this->assertEquals('/', $expressions[0]); |
||
103 | $this->assertEquals('ENDS_WITH', $filter->getOperator()); |
||
104 | } |
||
105 | } |
||
106 | |||
107 | /** |
||
108 | * Test page filters are created |
||
109 | */ |
||
110 | public function testGetPageDimensionFilters() |
||
111 | { |
||
112 | $filters = $this->service->getDimensionFilters(); |
||
113 | |||
114 | $this->assertTrue(is_array($filters)); |
||
115 | foreach ($filters as $filter) { |
||
116 | $this->assertInstanceOf(Google_Service_AnalyticsReporting_DimensionFilter::class, $filter); |
||
117 | $this->assertTrue(in_array($filter->getOperator(), ['ENDS_WITH', 'EXACT'], true)); |
||
118 | } |
||
119 | } |
||
120 | |||
121 | /** |
||
122 | * Validate our DimensionClause is set with OR |
||
123 | */ |
||
124 | public function testGetDimensionFilterClauses() |
||
125 | { |
||
126 | $dimensionsClauses = $this->service->getDimensionFilterClauses(); |
||
127 | $this->assertInstanceOf(Google_Service_AnalyticsReporting_DimensionFilterClause::class, $dimensionsClauses); |
||
128 | $this->assertEquals('OR', $dimensionsClauses->getOperator()); |
||
129 | } |
||
130 | |||
131 | /** |
||
132 | * Make sure the filter-list does not exceed 20 |
||
133 | */ |
||
134 | public function testGetPages() |
||
139 | } |
||
140 | |||
141 | /** |
||
142 | * Make sure we're not adding more than 20 filters, despite more pages being available |
||
143 | */ |
||
144 | public function testFilterLength() |
||
145 | { |
||
156 | } |
||
157 | |||
158 | /** |
||
159 | * Validate blacklisted pages don't show up |
||
160 | */ |
||
161 | View Code Duplication | public function testGetBlacklistedPages() |
|
162 | { |
||
163 | Config::inst()->update(GoogleAnalyticsReportService::class, 'blacklist', [ErrorPage::class]); |
||
164 | $pages = $this->service->getPages(); |
||
165 | $this->assertTrue(is_array($pages)); |
||
166 | $this->assertNotContains('page-not-found', $pages); |
||
167 | } |
||
168 | |||
169 | /** |
||
170 | * Make sure we only get whitelisted pages |
||
171 | */ |
||
172 | View Code Duplication | public function testGetWhitelistedPages() |
|
181 | } |
||
182 | } |
||
183 |
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