GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Passed
Push — master ( 871d34...713d9f )
by Steve
04:40
created

RendersSummaryChartTrait   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
dl 0
loc 43
rs 10
c 0
b 0
f 0
wmc 4
lcom 0
cbo 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getChartModel() 0 4 1
B getChartData() 0 24 3
1
<?php
2
/**
3
 * Created by shalvah
4
 * Date: 9/1/17
5
 * Time: 12:10 PM
6
 */
7
8
namespace bedezign\yii2\audit\components\panels;
9
10
/**
11
 * Trait RendersSummaryChartTrait
12
 * @package bedezign\yii2\audit\components\panels
13
 *
14
 * Used by audit panels or controllers which want to render a summary chart in their view
15
 */
16
trait RendersSummaryChartTrait
17
{
18
    /**
19
     * The name of the model for which the chart should be rendered
20
     *
21
     * @return string Fully namespaced class name
22
     */
23
    protected function getChartModel()
24
    {
25
        return static::className();
26
    }
27
28
    /**
29
     * Return audit data for the last seven days
30
     * to be rendered on the chart
31
     *
32
     * @return array
33
     */
34
    protected function getChartData()
35
    {
36
        //initialise defaults (0 entries) for each day
37
        $defaults = [];
38
        $startDate = strtotime('-6 days');
39
        foreach (range(-6, 0) as $day) {
40
            $defaults[date('D: Y-m-d', strtotime($day . 'days'))] = 0;
41
        }
42
43
        $panelModel = $this->getChartModel();
44
        $results = $panelModel::find()
45
            ->select(["COUNT(DISTINCT id) as count", "created AS day"])
46
            ->where(['between', 'created',
47
                date('Y-m-d 00:00:00', $startDate),
48
                date('Y-m-d 23:59:59')])
49
            ->groupBy("day")->indexBy('day')->column();
50
51
        // replace defaults with data from db where available
52
        foreach ($results as $date => $count) {
53
            $date = date('D: Y-m-d', strtotime($date));
54
            $defaults[$date] += $count;
55
        }
56
        return $defaults;
57
    }
58
}
59