Passed
Push — master ( 7ba57e...634515 )
by Paweł
03:13
created

BaseDiff::getData()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 3
nc 2
nop 0
dl 0
loc 7
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * Created for IG Monitoring.
4
 * User: jakim <[email protected]>
5
 * Date: 2019-01-25
6
 */
7
8
namespace app\components\stats\base;
9
10
11
use app\components\stats\contracts\DiffInterface;
12
use app\components\stats\traits\FromToDateTrait;
13
use app\components\stats\traits\StatsAttributesTrait;
14
use yii\base\BaseObject;
15
use yii\helpers\ArrayHelper;
16
17
abstract class BaseDiff extends BaseObject implements DiffInterface
18
{
19
    use FromToDateTrait, StatsAttributesTrait;
20
21
    protected $data;
22
23
    public function getModel($key): array
24
    {
25
        return ArrayHelper::getValue($this->getData(), $key, []);
26
    }
27
28
    public function getData()
29
    {
30
        if ($this->data === null) {
31
            $this->data = $this->prepareData();
32
        }
33
34
        return $this->data;
35
    }
36
37
    abstract protected function prepareData(): array;
38
}