PanelTrait   A
last analyzed

Complexity

Total Complexity 10

Size/Duplication

Total Lines 91
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 91
ccs 26
cts 26
cp 1
rs 10
c 0
b 0
f 0
wmc 10
lcom 2
cbo 2

8 Methods

Rating   Name   Duplication   Size   Complexity  
A getLabel() 0 4 1
A getIndexUrl() 0 4 1
A getChart() 0 4 1
A setModel() 0 4 1
A hasEntryData() 0 4 1
A getUrl() 0 7 1
A registerAssets() 0 4 1
A cleanup() 0 10 3
1
<?php
2
3
namespace bedezign\yii2\audit\components\panels;
4
5
use bedezign\yii2\audit\Audit;
6
use bedezign\yii2\audit\models\AuditData;
7
use bedezign\yii2\audit\models\AuditEntry;
8
use yii\helpers\Url;
9
use yii\web\View;
10
11
/**
12
 * PanelTrait
13
 * @package bedezign\yii2\audit\panels
14
 *
15
 * @property Audit $module
16
 * @property array|mixed $data
17
 * @property string $id
18
 * @property string $tag
19
 * @property AuditEntry $model
20
 * @method string getName()
21
 */
22
trait PanelTrait
23
{
24
    /**
25
     * @var int Maximum age (in days) of the data before it is cleaned
26
     */
27
    public $maxAge = null;
28
29
    /**
30
     * @var AuditEntry
31
     */
32
    protected $_model;
33
34
    /**
35
     * @return string
36
     */
37 3
    public function getLabel()
38
    {
39 3
        return $this->getName() . ' <small>(' . count($this->data) . ')</small>';
40
    }
41
42
    /**
43
     * @return array|bool
44
     */
45 33
    public function getIndexUrl()
46
    {
47 33
        return false;
48
    }
49
50
    /**
51
     * @return string|bool
52
     */
53 3
    public function getChart()
54
    {
55 3
        return false;
56
    }
57
58
    /**
59
     * @param AuditEntry $model
60
     */
61 3
    public function setModel($model)
62
    {
63 3
        $this->_model = $model;
64 3
    }
65
66
    /**
67
     * Returns if the panel is available for the specified entry.
68
     * If not it will not be shown in the viewer.
69
     *
70
     * @param AuditEntry $entry
71
     * @return bool
72
     */
73 3
    public function hasEntryData($entry)
0 ignored issues
show
Unused Code introduced by Steve Guns
The parameter $entry is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
74
    {
75 3
        return false;
76
    }
77
78
    /**
79
     * @return string
80
     */
81 3
    public function getUrl($additionalParams = NULL)
0 ignored issues
show
Unused Code introduced by Vadim Mazur
The parameter $additionalParams is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
82
    {
83 3
        return Url::toRoute(['/' . $this->module->id . '/entry/view',
84 3
            'panel' => $this->id,
85 3
            'id' => $this->tag,
86 3
        ]);
87
    }
88
89
    /**
90
     * @param View $view
91
     */
92 3
    public function registerAssets($view)
0 ignored issues
show
Unused Code introduced by cornernote
The parameter $view is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
93
    {
94
95 3
    }
96
97
    /**
98
     * @param int|null $maxAge
99
     * @return int
100
     */
101 3
    public function cleanup($maxAge = null)
102
    {
103 3
        $maxAge = $maxAge !== null ? $maxAge : $this->maxAge;
104 3
        if ($maxAge === null)
105 3
            return false;
106 3
        return AuditData::deleteAll('type = :type AND created <= :created', [
107 3
            ':type' => $this->id,
108 3
            ':created' => date('Y-m-d 23:59:59', strtotime("-$maxAge days")),
109 3
        ]);
110
    }
111
112
}
113