Completed
Push — master ( d0979b...77dbf6 )
by Dmitry
38:40
created

ModelTrait   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 0%

Importance

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

1 Method

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