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
Loading history...
|
|||
63 | } |
||
64 | } |