Passed
Push — master ( f10e44...7dce08 )
by Anton
01:36
created

Inverse::setAttribute()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 3
dl 0
loc 7
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 2
1
<?php declare(strict_types=1);
2
/**
3
 * Spiral Framework.
4
 *
5
 * @license   MIT
6
 * @author    Anton Titov (Wolfy-J)
7
 */
8
9
namespace Cycle\Annotated\Annotation\Relation;
10
11
use Spiral\Annotations\AbstractAnnotation;
12
use Spiral\Annotations\Parser;
13
14
final class Inverse extends AbstractAnnotation
15
{
16
    protected const NAME   = 'inverse';
17
    protected const SCHEMA = [
18
        'type' => Parser::STRING,
19
        'name' => Parser::STRING,
20
        'as'   => Parser::STRING, // alias to name
21
    ];
22
23
    /** @var string|null */
24
    protected $type;
25
26
    /** @var string|null */
27
    protected $name;
28
29
    /**
30
     * @inheritdoc
31
     */
32
    public function setAttribute(string $name, $value)
33
    {
34
        if ($name == "as") {
35
            $name = "name";
36
        }
37
38
        parent::setAttribute($name, $value);
39
    }
40
41
    /**
42
     * @return bool
43
     */
44
    public function isValid(): bool
45
    {
46
        return $this->getType() !== null && $this->getRelation() !== null;
47
    }
48
49
    /**
50
     * @return string|null
51
     */
52
    public function getType(): ?string
53
    {
54
        return $this->type;
55
    }
56
57
    /**
58
     * @return string|null
59
     */
60
    public function getRelation(): ?string
61
    {
62
        return $this->name ?? $this->as;
0 ignored issues
show
Bug Best Practice introduced by Wolfy-J
The property as does not exist on Cycle\Annotated\Annotation\Relation\Inverse. Did you maybe forget to declare it?
Loading history...
63
    }
64
}