ModelTrait::attributes()   A
last analyzed

Complexity

Conditions 5
Paths 3

Size

Total Lines 17

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 30

Importance

Changes 0
Metric Value
dl 0
loc 17
ccs 0
cts 16
cp 0
rs 9.3888
c 0
b 0
f 0
cc 5
nc 3
nop 0
crap 30
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