Passed
Push — master ( daa35d...1046d9 )
by Anton
01:34
created

AbstractAnnotation   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 5
eloc 10
dl 0
loc 35
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getName() 0 3 1
A setAttribute() 0 3 1
A getSchema() 0 11 3
1
<?php
2
declare(strict_types=1);
3
/**
4
 * Spiral Framework.
5
 *
6
 * @license   MIT
7
 * @author    Anton Titov (Wolfy-J)
8
 */
9
10
namespace Spiral\Annotations;
11
12
/**
13
 * Constant based node declaration.
14
 */
15
abstract class AbstractAnnotation implements AnnotationInterface
16
{
17
    protected const NAME   = '';
18
    protected const SCHEMA = [];
19
20
    /**
21
     * @inheritdoc
22
     */
23
    public function getName(): string
24
    {
25
        return static::NAME;
26
    }
27
28
    /**
29
     * @inheritdoc
30
     */
31
    public function getSchema(): array
32
    {
33
        $schema = static::SCHEMA;
34
35
        array_walk_recursive($schema, function (&$v) {
36
            if (is_string($v) && class_exists($v)) {
37
                $v = new $v;
38
            }
39
        });
40
41
        return $schema;
42
    }
43
44
    /**
45
     * @inheritdoc
46
     */
47
    public function setAttribute(string $name, $value)
48
    {
49
        $this->{$name} = $value;
50
    }
51
}