Completed
Push — master ( 19af7f...765e83 )
by ARCANEDEV
14s queued 11s
created

src/Tables/StatsTable.php (2 issues)

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 namespace Arcanedev\LogViewer\Tables;
2
3
use Arcanedev\LogViewer\Contracts\Utilities\LogLevels as LogLevelsContract;
4
use Illuminate\Support\Arr;
5
use Illuminate\Support\Collection;
6
7
/**
8
 * Class     StatsTable
9
 *
10
 * @package  Arcanedev\LogViewer\Tables
11
 * @author   ARCANEDEV <[email protected]>
12
 */
13
class StatsTable extends AbstractTable
14
{
15
    /* -----------------------------------------------------------------
16
     |  Main Methods
17
     | -----------------------------------------------------------------
18
     */
19
20
    /**
21
     * Make a stats table instance.
22
     *
23
     * @param  array                                               $data
24
     * @param  \Arcanedev\LogViewer\Contracts\Utilities\LogLevels  $levels
25
     * @param  string|null                                         $locale
26
     *
27
     * @return self
28
     */
29 36
    public static function make(array $data, LogLevelsContract $levels, $locale = null)
30
    {
31 36
        return new self($data, $levels, $locale);
32
    }
33
34
    /* -----------------------------------------------------------------
35
     |  Other Methods
36
     | -----------------------------------------------------------------
37
     */
38
39
    /**
40
     * Prepare table header.
41
     *
42
     * @param  array  $data
43
     *
44
     * @return array
45
     */
46 78
    protected function prepareHeader(array $data)
47
    {
48 78
        return array_merge_recursive(
49
            [
50 78
                'date' => $this->translate('general.date'),
51 78
                'all'  => $this->translate('general.all'),
52
            ],
53 78
            $this->levels->names($this->locale)
54
        );
55
    }
56
57
    /**
58
     * Prepare table rows.
59
     *
60
     * @param  array  $data
61
     *
62
     * @return array
63
     */
64 78
    protected function prepareRows(array $data)
65
    {
66 78
        $rows = [];
67
68 78
        foreach ($data as $date => $levels) {
69 78
            $rows[$date] = array_merge(compact('date'), $levels);
70
        }
71
72 78
        return $rows;
73
    }
74
75
    /**
76
     * Prepare table footer.
77
     *
78
     * @param  array  $data
79
     *
80
     * @return array
81
     */
82 78
    protected function prepareFooter(array $data)
83
    {
84 78
        $footer = [];
85
86 78
        foreach ($data as $date => $levels) {
87 78
            foreach ($levels as $level => $count) {
88 78
                if ( ! isset($footer[$level])) {
89 78
                    $footer[$level] = 0;
90
                }
91
92 78
                $footer[$level] += $count;
93
            }
94
        }
95
96 78
        return $footer;
97
    }
98
99
    /**
100
     * Get totals.
101
     *
102
     * @param  string|null  $locale
0 ignored issues
show
There is no parameter named $locale. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
103
     *
104
     * @return \Illuminate\Support\Collection
105
     */
106 18
    public function totals()
107
    {
108 18
        $totals = Collection::make();
109
110 18
        foreach (Arr::except($this->footer(), 'all') as $level => $count) {
111 18
            $totals->put($level, [
112 18
                'label'     => $this->translate("levels.$level"),
113 18
                'value'     => $count,
114 18
                'color'     => $this->color($level),
115 18
                'highlight' => $this->color($level),
116
            ]);
117
        }
118
119 18
        return $totals;
120
    }
121
122
    /**
123
     * Get json totals data.
124
     *
125
     * @param  string|null  $locale
126
     *
127
     * @return string
128
     */
129 6
    public function totalsJson($locale = null)
130
    {
131 6
        return $this->totals($locale)->toJson(JSON_PRETTY_PRINT);
0 ignored issues
show
The call to StatsTable::totals() has too many arguments starting with $locale.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
132
    }
133
}
134