| Total Complexity | 13 |
| Total Lines | 75 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | <?php declare(strict_types=1); |
||
| 15 | final class Inverse extends AbstractAnnotation |
||
| 16 | { |
||
| 17 | protected const NAME = 'inverse'; |
||
| 18 | protected const SCHEMA = [ |
||
| 19 | 'type' => Parser::STRING, |
||
| 20 | 'name' => Parser::STRING, |
||
| 21 | 'as' => Parser::STRING, // alias to name |
||
| 22 | 'load' => Parser::STRING, |
||
| 23 | 'fetch' => Parser::STRING, // alias to load |
||
| 24 | ]; |
||
| 25 | |||
| 26 | /** @var string|null */ |
||
| 27 | protected $type; |
||
| 28 | |||
| 29 | /** @var string|null */ |
||
| 30 | protected $name; |
||
| 31 | |||
| 32 | /** @var string|null */ |
||
| 33 | protected $load; |
||
| 34 | |||
| 35 | /** |
||
| 36 | * @inheritdoc |
||
| 37 | */ |
||
| 38 | public function setAttribute(string $name, $value) |
||
| 49 | } |
||
| 50 | |||
| 51 | /** |
||
| 52 | * @return bool |
||
| 53 | */ |
||
| 54 | public function isValid(): bool |
||
| 55 | { |
||
| 56 | return $this->getType() !== null && $this->getRelation() !== null; |
||
| 57 | } |
||
| 58 | |||
| 59 | /** |
||
| 60 | * @return string|null |
||
| 61 | */ |
||
| 62 | public function getType(): ?string |
||
| 63 | { |
||
| 64 | return $this->type; |
||
| 65 | } |
||
| 66 | |||
| 67 | /** |
||
| 68 | * @return string|null |
||
| 69 | */ |
||
| 70 | public function getRelation(): ?string |
||
| 73 | } |
||
| 74 | |||
| 75 | /** |
||
| 76 | * @return int|null |
||
| 77 | */ |
||
| 78 | public function getLoadMethod(): ?int |
||
| 92 | } |
Let?s assume that you have a directory layout like this:
. |-- OtherDir | |-- Bar.php | `-- Foo.php `-- SomeDir `-- Foo.phpand let?s assume the following content of
Bar.php:If both files
OtherDir/Foo.phpandSomeDir/Foo.phpare loaded in the same runtime, you will see a PHP error such as the following:PHP Fatal error: Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.phpHowever, as
OtherDir/Foo.phpdoes not necessarily have to be loaded and the error is only triggered if it is loaded beforeOtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias: