ModelTrait   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 0%

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A attributes() 0 17 5
1
<?php
2
/**
3
 * HiPanel core package
4
 *
5
 * @link      https://hipanel.com/
6
 * @package   hipanel-core
7
 * @license   BSD-3-Clause
8
 * @copyright Copyright (c) 2014-2019, HiQDev (http://hiqdev.com/)
9
 */
10
11
namespace hipanel\base;
12
13
trait ModelTrait
14
{
15
    /**
16
     * Overrides default [[attributes()]] method.
17
     * Extracts attributes from the validation rules described in [[rules()]] method.
18
     *
19
     * @return array
20
     */
21
    public function attributes()
22
    {
23
        $attributes = \yii\base\Model::attributes();
24
        foreach (self::rules() as $rule) {
25
            if (is_string(reset($rule))) {
26
                continue;
27
            }
28
            foreach (reset($rule) as $attribute) {
29
                if (substr_compare($attribute, '!', 0, 1) === 0) {
30
                    $attribute = mb_substr($attribute, 1);
31
                }
32
                $attributes[$attribute] = $attribute;
33
            }
34
        }
35
36
        return array_values($attributes);
37
    }
38
}
39