Completed
Push — master ( ae5e03...0447ee )
by Jeroen
10:35 queued 04:37
created

Analytics/AbstractAnalyticsCommandHelper.php (1 issue)

Checks whether return doc types can be made more specific.

Documentation Informational

Upgrade to new PHP Analysis Engine

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\Command\Helper\Analytics;
4
5
use Doctrine\ORM\EntityManager;
6
use Kunstmaan\DashboardBundle\Entity\AnalyticsOverview;
7
use Symfony\Component\Console\Output\OutputInterface;
8
9
abstract class AbstractAnalyticsCommandHelper
10
{
11
    /** @var ConfigHelper */
12
    protected $configHelper;
13
14
    /** @var GooglequeryHelper */
15
    protected $query;
16
17
    /** @var EntityManager */
18
    protected $em;
19
20
    /** @var OutputInterface */
21
    protected $output;
22
23
    /**
24
     * Constructor
25
     *
26
     * @param $configHelper
27
     * @param $queryHelper
28
     * @param $output
29
     * @param $em
30
     */
31
    public function __construct($configHelper, $queryHelper, $output, $em)
32
    {
33
        $this->configHelper = $configHelper;
34
        $this->query = $queryHelper;
35
        $this->output = $output;
36
        $this->em = $em;
37
    }
38
39
    /**
40
     * Constructor
41
     *
42
     * @param AnalyticsOverview $overview
43
     *
44
     * @return array
0 ignored issues
show
Consider making the return type a bit more specific; maybe use array<string,string>.

This check looks for the generic type array as a return type and suggests a more specific type. This type is inferred from the actual code.

Loading history...
45
     */
46
    protected function getTimestamps(AnalyticsOverview $overview)
47
    {
48
        // if yearoverview set the begin time to the first day of this year
49
        $profileStartDate = explode('T', $this->configHelper->getActiveProfile()['created'])[0];
50
        if ($overview->getUseYear()) {
51
            $begin_date = date('Y-m-d', mktime(0, 0, 0, 1, 1, date('Y')));
52
            $begin = strtotime($profileStartDate) > strtotime($begin_date) ? date('Y-m-d', strtotime($profileStartDate)) : $begin_date;
53
        } else {
54
            // check if timespan is't more than existence of the profile; if so, use the creation time in stead of the timespan time
55
            $begin = strtotime($profileStartDate) > strtotime('-' . $overview->getTimespan() . ' days') ? date('Y-m-d', strtotime($profileStartDate)) : date('Y-m-d', strtotime('-' . $overview->getTimespan() . ' days'));
56
        }
57
        // set the end time
58
        $end = date('Y-m-d', strtotime('-' . $overview->getStartOffset() . ' days'));
59
60
        return array('begin' => $begin, 'end' => $end);
61
    }
62
63
    /**
64
     * get the extra data for an overview, can be overridden
65
     *
66
     * @return array
67
     */
68
    protected function getExtra(AnalyticsOverview $overview)
69
    {
70
        $extra = array();
71
72
        // add segment
73
        if ($overview->getSegment()) {
74
            $extra['segment'] = $overview->getSegment()->getQuery();
75
        }
76
77
        return $extra;
78
    }
79
80
    /**
81
     * Executes the query
82
     *
83
     * @return array the resultset
84
     */
85 View Code Duplication
    protected function executeQuery(AnalyticsOverview $overview, $metrics)
86
    {
87
        $timestamps = $this->getTimestamps($overview);
88
        $extra = $this->getExtra($overview);
89
90
        // execute query
91
        $results = $this->query->getResultsByDate(
92
            $timestamps['begin'],
93
            $timestamps['end'],
94
            $metrics,
95
            $extra
96
        );
97
98
        return $results->getRows();
99
    }
100
101
    abstract public function getData(&$overview);
102
}
103