StatsAttributesTrait   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 20
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 7
c 1
b 0
f 0
dl 0
loc 20
rs 10
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A setStatsAttributes() 0 5 1
A getStatsAttributes() 0 3 1
A throwExceptionIfStatsAttributesIsNotSet() 0 4 2
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\traits;
9
10
11
use yii\base\InvalidConfigException;
12
13
/**
14
 * Trait StatsAttributesTrait
15
 *
16
 * @package app\components\stats\traits
17
 *
18
 * @property array $statsAttributes
19
 */
20
trait StatsAttributesTrait
21
{
22
    protected $statsAttributes = [];
23
24
    public function setStatsAttributes(array $statsAttributes)
25
    {
26
        $this->statsAttributes = $statsAttributes;
27
28
        return $this;
29
    }
30
31
    public function getStatsAttributes(): array
32
    {
33
        return $this->statsAttributes;
34
    }
35
36
    protected function throwExceptionIfStatsAttributesIsNotSet()
37
    {
38
        if (!$this->statsAttributes) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $this->statsAttributes of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
39
            throw new InvalidConfigException('Property \'statsAttributes\' can not be empty.');
40
        }
41
    }
42
}