Passed
Pull Request — master (#152)
by
unknown
02:25
created

AttributeTrait::rules()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 17
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 20

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 4
eloc 9
c 1
b 0
f 0
nc 4
nop 0
dl 0
loc 17
ccs 0
cts 10
cp 0
crap 20
rs 9.9666
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Validator;
6
7
use ReflectionClass;
8
9
trait AttributeTrait
10
{
11
    public function rules(): array
12
    {
13
        $class = new ReflectionClass($this);
14
        $rules = [];
15
16
        foreach ($class->getProperties() as $property) {
17
            if ($property->isStatic()) {
18
                continue;
19
            }
20
21
            $attributes = $property->getAttributes(Validate::class);
22
            foreach ($attributes as $attribute) {
23
                $rules[$property->getName()][] = $attribute->newInstance()->getRule();
24
            }
25
        }
26
27
        return $rules;
28
    }
29
}
30