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

ModelTrait::attributes()   B

Complexity

Conditions 5
Paths 3

Size

Total Lines 16
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 30

Importance

Changes 3
Bugs 0 Features 1
Metric Value
cc 5
eloc 10
c 3
b 0
f 1
nc 3
nop 0
dl 0
loc 16
ccs 0
cts 16
cp 0
crap 30
rs 8.8571
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