Completed
Pull Request — master (#6)
by
unknown
03:50 queued 01:18
created

StatisticGridView::columns()   B

Complexity

Conditions 2
Paths 1

Size

Total Lines 32
Code Lines 22

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 1
Bugs 1 Features 0
Metric Value
dl 0
loc 32
ccs 0
cts 25
cp 0
rs 8.8571
c 1
b 1
f 0
cc 2
eloc 22
nc 1
nop 0
crap 6
1
<?php
2
/**
3
 * HiPanel tickets module
4
 *
5
 * @link      https://github.com/hiqdev/hipanel-module-ticket
6
 * @package   hipanel-module-ticket
7
 * @license   BSD-3-Clause
8
 * @copyright Copyright (c) 2015-2017, HiQDev (http://hiqdev.com/)
9
 */
10
11
namespace hipanel\modules\ticket\grid;
12
13
use hipanel\grid\MainColumn;
14
use hipanel\grid\SwitchColumn;
15
use hipanel\modules\client\grid\ClientColumn;
16
use hipanel\widgets\ClientSellerLink;
17
use hipanel\modules\ticket\menus\TemplateActionsMenu;
18
use hiqdev\yii2\menus\grid\MenuColumn;
19
use yii\helpers\Html;
20
use yii\helpers\Url;
21
use Yii;
22
23
class StatisticGridView extends \hipanel\grid\BoxedGridView
24
{
25
    public function columns()
26
    {
27
        return array_merge(parent::columns(), [
28
            'client_id' => [
29
                'class' => ClientColumn::class,
30
                'label' => Yii::t('hipanel', 'Client'),
31
                'idAttribute' => 'client_id',
32
                'sortAttribute' => 'client',
33
                'attribute' => 'client_id',
34
                'value' => function ($model) {
35
                    return ClientSellerLink::widget(compact('model'));
36
                },
37
            ],
38
            'spent' => [
39
                'label' => Yii::t('hipanel:ticket', 'Spent'),
40
                'filter' => false,
41
                'value' => function($model) {
42
                    return Yii::$app->formatter->asDuration($model->spent * 60);
43
                },
44
            ],
45
            'tickets' => [
46
                'format' => 'html',
47
                'value' => function($model) {
48
                    foreach (explode(",", $model->thread_ids) as $thread) {
49
                        $threads[$thread] = Html::a($thread, Url::to(['@ticket/view', 'id' => $thread]));
0 ignored issues
show
Coding Style Comprehensibility introduced by
$threads was never initialized. Although not strictly required by PHP, it is generally a good practice to add $threads = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
50
                    }
51
                    ksort($threads);
52
                    return implode(" ", $threads);
53
                }
54
            ],
55
        ]);
56
    }
57
}
58