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

AttributeTrait   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 19
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 10
c 1
b 0
f 0
dl 0
loc 19
ccs 0
cts 10
cp 0
rs 10
wmc 4

1 Method

Rating   Name   Duplication   Size   Complexity  
A rules() 0 17 4
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