These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | namespace Kunstmaan\DashboardBundle\Helper\Google\Analytics; |
||
4 | |||
5 | class QueryHelper |
||
6 | { |
||
7 | /** @var ServiceHelper */ |
||
8 | private $serviceHelper; |
||
9 | |||
10 | /** @var ConfigHelper */ |
||
11 | private $configHelper; |
||
12 | |||
13 | /** |
||
14 | * constructor |
||
15 | * |
||
16 | * @var ServiceHelper |
||
17 | */ |
||
18 | public function __construct(ServiceHelper $serviceHelper, ConfigHelper $configHelper) |
||
19 | { |
||
20 | $this->serviceHelper = $serviceHelper; |
||
21 | $this->configHelper = $configHelper; |
||
22 | } |
||
23 | |||
24 | /** |
||
25 | * Constructs a Google API query and returns the result |
||
26 | * |
||
27 | * @param int $timespan Timespan for the data to query in days |
||
28 | * @param int $startOffset An offset in days |
||
29 | * @param string $metrics The needed metrics |
||
30 | * @param array $extra Extra options suchs as dimentions, sort data, filter data,.. |
||
31 | * |
||
32 | * @return \Google_GaData result A data object containing the queried data |
||
33 | */ |
||
34 | View Code Duplication | public function getResults($timespan, $startOffset, $metrics, $extra = []) |
|
0 ignored issues
–
show
|
|||
35 | { |
||
36 | $profileId = $this->configHelper->getProfileId(); |
||
37 | |||
38 | return $this->serviceHelper->getService()->data_ga->get( |
||
39 | 'ga:' . $profileId, |
||
40 | $timespan . 'daysAgo', |
||
41 | $startOffset . 'daysAgo', |
||
42 | $metrics, |
||
43 | $extra |
||
44 | ); |
||
45 | } |
||
46 | |||
47 | /** |
||
48 | * Constructs a Google API query and returns the result |
||
49 | * |
||
50 | * @param string $from Start date for the data to query |
||
51 | * @param string $to End date in the past |
||
52 | * @param string $metrics The needed metrics |
||
53 | * @param array $extra Extra options suchs as dimentions, sort data, filter data,.. |
||
54 | * |
||
55 | * @return \Google_GaData result A data object containing the queried data |
||
56 | */ |
||
57 | View Code Duplication | public function getResultsByDate($from, $to, $metrics, $extra = []) |
|
58 | { |
||
59 | $profileId = $this->configHelper->getProfileId(); |
||
60 | |||
61 | return $this->serviceHelper->getService()->data_ga->get( |
||
62 | 'ga:' . $profileId, |
||
63 | $from, |
||
64 | $to, |
||
65 | $metrics, |
||
66 | $extra |
||
67 | ); |
||
68 | } |
||
69 | |||
70 | /** |
||
71 | * get the service helper |
||
72 | * |
||
73 | * @return ServiceHelper $serviceHelper |
||
74 | */ |
||
75 | public function getServiceHelper() |
||
76 | { |
||
77 | return $this->serviceHelper; |
||
78 | } |
||
79 | } |
||
80 |
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.