1 | <?php declare(strict_types=1); |
||
34 | class IdentifierAndResource implements ResourceInterface |
||
35 | { |
||
36 | use ParseRelationshipDataTrait, ParseRelationshipLinksTrait; |
||
37 | |||
38 | /** @var string */ |
||
39 | public const MSG_NO_SCHEMA_FOUND = 'No Schema found for resource `%s` at path `%s`.'; |
||
40 | |||
41 | /** @var string */ |
||
42 | public const MSG_INVALID_OPERATION = 'Invalid operation.'; |
||
43 | |||
44 | /** |
||
45 | * @var PositionInterface |
||
46 | */ |
||
47 | private $position; |
||
48 | |||
49 | /** |
||
50 | * @var FactoryInterface |
||
51 | */ |
||
52 | private $factory; |
||
53 | |||
54 | /** |
||
55 | * @var SchemaContainerInterface |
||
56 | */ |
||
57 | private $schemaContainer; |
||
58 | |||
59 | /** |
||
60 | * @var SchemaInterface |
||
61 | */ |
||
62 | private $schema; |
||
63 | |||
64 | /** |
||
65 | * @var mixed |
||
66 | */ |
||
67 | private $data; |
||
68 | |||
69 | /** |
||
70 | * @var string |
||
71 | */ |
||
72 | private $index; |
||
73 | |||
74 | /** |
||
75 | * @var string |
||
76 | */ |
||
77 | private $type; |
||
78 | |||
79 | /** |
||
80 | * @var null|array |
||
81 | */ |
||
82 | private $links = null; |
||
83 | |||
84 | /** |
||
85 | * @var null|array |
||
86 | */ |
||
87 | private $relationshipsCache = null; |
||
88 | |||
89 | /** |
||
90 | * @param PositionInterface $position |
||
91 | * @param FactoryInterface $factory |
||
92 | * @param SchemaContainerInterface $container |
||
93 | * @param mixed $data |
||
94 | */ |
||
95 | 60 | public function __construct( |
|
96 | PositionInterface $position, |
||
97 | FactoryInterface $factory, |
||
98 | SchemaContainerInterface $container, |
||
99 | $data |
||
100 | ) { |
||
101 | 60 | \assert($position->getLevel() >= ParserInterface::ROOT_LEVEL); |
|
102 | |||
103 | 60 | $schema = $container->getSchema($data); |
|
104 | |||
105 | 60 | $this->position = $position; |
|
106 | 60 | $this->factory = $factory; |
|
107 | 60 | $this->schemaContainer = $container; |
|
108 | 60 | $this->schema = $schema; |
|
109 | 60 | $this->data = $data; |
|
110 | 60 | $this->index = $schema->getId($data); |
|
111 | 60 | $this->type = $schema->getType(); |
|
112 | 60 | } |
|
113 | |||
114 | /** |
||
115 | * @inheritdoc |
||
116 | */ |
||
117 | 60 | public function getPosition(): PositionInterface |
|
121 | |||
122 | /** |
||
123 | * @inheritdoc |
||
124 | */ |
||
125 | 60 | public function getId(): ?string |
|
129 | |||
130 | /** |
||
131 | * @inheritdoc |
||
132 | */ |
||
133 | 60 | public function getType(): string |
|
137 | |||
138 | /** |
||
139 | * @inheritdoc |
||
140 | */ |
||
141 | 31 | public function hasIdentifierMeta(): bool |
|
145 | |||
146 | /** |
||
147 | * @inheritdoc |
||
148 | */ |
||
149 | 2 | public function getIdentifierMeta() |
|
150 | { |
||
151 | 2 | return $this->schema->getIdentifierMeta($this->data); |
|
152 | } |
||
153 | |||
154 | /** |
||
155 | * @inheritdoc |
||
156 | */ |
||
157 | 57 | public function getAttributes(): iterable |
|
161 | |||
162 | /** |
||
163 | * @inheritdoc |
||
164 | */ |
||
165 | 60 | public function getRelationships(): iterable |
|
218 | |||
219 | /** |
||
220 | * @inheritdoc |
||
221 | */ |
||
222 | 57 | public function hasLinks(): bool |
|
228 | |||
229 | /** |
||
230 | * @inheritdoc |
||
231 | */ |
||
232 | 56 | public function getLinks(): iterable |
|
238 | |||
239 | /** |
||
240 | * @inheritdoc |
||
241 | */ |
||
242 | 57 | public function hasResourceMeta(): bool |
|
246 | |||
247 | /** |
||
248 | * @inheritdoc |
||
249 | */ |
||
250 | 1 | public function getResourceMeta() |
|
254 | |||
255 | /** |
||
256 | * Read and parse links from schema. |
||
257 | */ |
||
258 | 57 | private function cacheLinks(): void |
|
269 | |||
270 | /** |
||
271 | * @param string $name |
||
272 | * @param array $description |
||
273 | * |
||
274 | * @return bool |
||
275 | */ |
||
276 | 45 | private function assertRelationshipNameAndDescription(string $name, array $description): bool |
|
289 | } |
||
290 |
This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.