Passed
Push — master ( b7948f...0e5cc9 )
by Simon
01:28
created

code/Tasks/AnalyticsUpdateTask.php (1 issue)

1
<?php
2
3
class AnalyticsUpdateTask extends BuildTask
1 ignored issue
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
4
{
5
    /**
6
     * @return string Title
7
     */
8
    public function getTitle()
9
    {
10
        return 'Update Google Analytics information for the configured pages';
11
    }
12
13
    /**
14
     * Start booting up
15
     * @param SS_HTTPRequest $request
16
     * @throws \Google_Exception
17
     * @throws \LogicException
18
     */
19
    public function run($request)
20
    {
21
        $clientService = new GoogleClientService();
22
23
        $this->getReport($clientService);
24
    }
25
26
    /**
27
     * Get the report and ask the service to update neatly
28
     *
29
     * @param GoogleClientService $client
30
     * @throws \ValidationException
31
     */
32
    protected function getReport($client)
33
    {
34
        $service = new GoogleAnalyticsReportService($client);
35
36
        $reports = $service->getReport();
37
        $count = 0;
38
39
        $updateService = new PageUpdateService();
40
        /** @var array $rows */
41
        foreach ($reports as $report) {
42
            /** @var array $rows */
43
            $rows = $report->getData()->getRows();
44
            $count += $updateService->updateVisits($rows);
45
        }
46
        echo "<p>$count Pages updated with Google Analytics visit count</p>";
47
    }
48
}
49