Skip to content

Commit 195c43e

Browse files
committed
Close #227
1 parent e463ddb commit 195c43e

File tree

15 files changed

+87
-319
lines changed

15 files changed

+87
-319
lines changed

src/Http/Headers/MediaType.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ public function getSubType(): string
9999
public function getMediaType(): string
100100
{
101101
if ($this->mediaType === null) {
102-
$this->mediaType = $this->getType() . '/' . $this->getSubType();
102+
$this->mediaType = $this->type . '/' . $this->getSubType();
103103
}
104104

105105
return $this->mediaType;
@@ -154,7 +154,7 @@ private function isTypeEquals(MediaTypeInterface $mediaType): bool
154154
{
155155
// Type, subtype and param name should be compared case-insensitive
156156
// https://tools.ietf.org/html/rfc7231#section-3.1.1.1
157-
return \strcasecmp($this->getType(), $mediaType->getType()) === 0;
157+
return \strcasecmp($this->type, $mediaType->getType()) === 0;
158158
}
159159

160160
/**
@@ -191,7 +191,7 @@ private function isMediaParametersMatch(MediaTypeInterface $mediaType): bool
191191
} elseif ($this->bothMediaTypeParamsNotEmptyAndEqualInSize($mediaType)) {
192192
// Type, subtype and param name should be compared case-insensitive
193193
// https://tools.ietf.org/html/rfc7231#section-3.1.1.1
194-
$ourParameters = \array_change_key_case($this->getParameters());
194+
$ourParameters = \array_change_key_case($this->parameters);
195195
$parametersToCompare = \array_change_key_case($mediaType->getParameters());
196196

197197
// if at least one name are different they are not equal
@@ -227,7 +227,7 @@ private function isMediaParametersEqual(MediaTypeInterface $mediaType): bool
227227
} elseif ($this->bothMediaTypeParamsNotEmptyAndEqualInSize($mediaType)) {
228228
// Type, subtype and param name should be compared case-insensitive
229229
// https://tools.ietf.org/html/rfc7231#section-3.1.1.1
230-
$ourParameters = \array_change_key_case($this->getParameters());
230+
$ourParameters = \array_change_key_case($this->parameters);
231231
$parametersToCompare = \array_change_key_case($mediaType->getParameters());
232232

233233
// if at least one name are different they are not equal
@@ -258,7 +258,7 @@ private function isMediaParametersEqual(MediaTypeInterface $mediaType): bool
258258
*/
259259
private function bothMediaTypeParamsEmpty(MediaTypeInterface $mediaType): bool
260260
{
261-
return $this->getParameters() === null && $mediaType->getParameters() === null;
261+
return $this->parameters === null && $mediaType->getParameters() === null;
262262
}
263263

264264
/**
@@ -268,7 +268,7 @@ private function bothMediaTypeParamsEmpty(MediaTypeInterface $mediaType): bool
268268
*/
269269
private function bothMediaTypeParamsNotEmptyAndEqualInSize(MediaTypeInterface $mediaType): bool
270270
{
271-
$pr1 = $this->getParameters();
271+
$pr1 = $this->parameters;
272272
$pr2 = $mediaType->getParameters();
273273

274274
return (empty($pr1) === false && empty($pr2) === false) && (\count($pr1) === \count($pr2));

src/Http/Query/BaseQueryParser.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,6 @@ protected function setMessages(?array $messages): self
125125
*/
126126
protected function getMessage(string $message): string
127127
{
128-
$hasTranslation = $this->messages !== null && \array_key_exists($message, $this->messages) === false;
129-
130-
return $hasTranslation === true ? $this->messages[$message] : $message;
128+
return $this->messages[$message] ?? $message;
131129
}
132130
}

src/Http/Query/BaseQueryParserTrait.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,9 @@ protected function getIncludes(array $parameters, string $errorTitle): iterable
3838
{
3939
if (\array_key_exists(P::PARAM_INCLUDE, $parameters) === true) {
4040
$paramName = P::PARAM_INCLUDE;
41-
$includes = $parameters[P::PARAM_INCLUDE];
41+
$includes = $parameters[$paramName];
4242
foreach ($this->splitCommaSeparatedStringAndCheckNoEmpties($paramName, $includes, $errorTitle) as $path) {
43-
yield $path => $this->splitStringAndCheckNoEmpties(P::PARAM_INCLUDE, $path, '.', $errorTitle);
43+
yield $path => $this->splitStringAndCheckNoEmpties($paramName, $path, '.', $errorTitle);
4444
}
4545
}
4646
}

src/I18n/Messages.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public static function compose(string $message, ...$parameters): string
5353
*/
5454
public static function getTranslation(string $message): string
5555
{
56-
return \array_key_exists($message, static::$translations) === true ? static::$translations[$message] : $message;
56+
return static::$translations[$message] ?? $message;
5757
}
5858

5959
/**

src/Parser/IdentifierAndResource.php

Lines changed: 24 additions & 114 deletions
Original file line numberDiff line numberDiff line change
@@ -98,13 +98,17 @@ public function __construct(
9898
SchemaContainerInterface $container,
9999
$data
100100
) {
101+
\assert($position->getLevel() >= ParserInterface::ROOT_LEVEL);
102+
101103
$schema = $container->getSchema($data);
102-
$this
103-
->setPosition($position)
104-
->setFactory($factory)
105-
->setSchemaContainer($container)
106-
->setSchema($schema)
107-
->setData($data);
104+
105+
$this->position = $position;
106+
$this->factory = $factory;
107+
$this->schemaContainer = $container;
108+
$this->schema = $schema;
109+
$this->data = $data;
110+
$this->index = $schema->getId($data);
111+
$this->type = $schema->getType();
108112
}
109113

110114
/**
@@ -136,23 +140,23 @@ public function getType(): string
136140
*/
137141
public function hasIdentifierMeta(): bool
138142
{
139-
return $this->getSchema()->hasIdentifierMeta($this->getData());
143+
return $this->schema->hasIdentifierMeta($this->data);
140144
}
141145

142146
/**
143147
* @inheritdoc
144148
*/
145149
public function getIdentifierMeta()
146150
{
147-
return $this->getSchema()->getIdentifierMeta($this->getData());
151+
return $this->schema->getIdentifierMeta($this->data);
148152
}
149153

150154
/**
151155
* @inheritdoc
152156
*/
153157
public function getAttributes(): iterable
154158
{
155-
return $this->getSchema()->getAttributes($this->getData());
159+
return $this->schema->getAttributes($this->data);
156160
}
157161

158162
/**
@@ -168,24 +172,24 @@ public function getRelationships(): iterable
168172

169173
$this->relationshipsCache = [];
170174

171-
$currentPath = $this->getPosition()->getPath();
172-
$nextLevel = $this->getPosition()->getLevel() + 1;
175+
$currentPath = $this->position->getPath();
176+
$nextLevel = $this->position->getLevel() + 1;
173177
$nextPathPrefix = empty($currentPath) === true ? '' : $currentPath . PositionInterface::PATH_SEPARATOR;
174-
foreach ($this->getSchema()->getRelationships($this->getData()) as $name => $description) {
178+
foreach ($this->schema->getRelationships($this->data) as $name => $description) {
175179
\assert($this->assertRelationshipNameAndDescription($name, $description) === true);
176180

177181
[$hasData, $relationshipData, $nextPosition] = $this->parseRelationshipData(
178-
$this->getFactory(),
179-
$this->getSchemaContainer(),
180-
$this->getType(),
182+
$this->factory,
183+
$this->schemaContainer,
184+
$this->type,
181185
$name,
182186
$description,
183187
$nextLevel,
184188
$nextPathPrefix
185189
);
186190

187191
[$hasLinks, $links] =
188-
$this->parseRelationshipLinks($this->getSchema(), $this->getData(), $name, $description);
192+
$this->parseRelationshipLinks($this->schema, $this->data, $name, $description);
189193

190194
$hasMeta = \array_key_exists(SchemaInterface::RELATIONSHIP_META, $description);
191195
$meta = $hasMeta === true ? $description[SchemaInterface::RELATIONSHIP_META] : null;
@@ -196,7 +200,7 @@ public function getRelationships(): iterable
196200
'` MUST contain at least one of the following: links, data or meta.'
197201
);
198202

199-
$relationship = $this->getFactory()->createRelationship(
203+
$relationship = $this->factory->createRelationship(
200204
$nextPosition,
201205
$hasData,
202206
$relationshipData,
@@ -237,109 +241,15 @@ public function getLinks(): iterable
237241
*/
238242
public function hasResourceMeta(): bool
239243
{
240-
return $this->getSchema()->hasResourceMeta($this->getData());
244+
return $this->schema->hasResourceMeta($this->data);
241245
}
242246

243247
/**
244248
* @inheritdoc
245249
*/
246250
public function getResourceMeta()
247251
{
248-
return $this->getSchema()->getResourceMeta($this->getData());
249-
}
250-
251-
/**
252-
* @inheritdoc
253-
*/
254-
protected function setPosition(PositionInterface $position): self
255-
{
256-
\assert($position->getLevel() >= ParserInterface::ROOT_LEVEL);
257-
258-
$this->position = $position;
259-
260-
return $this;
261-
}
262-
263-
/**
264-
* @return FactoryInterface
265-
*/
266-
protected function getFactory(): FactoryInterface
267-
{
268-
return $this->factory;
269-
}
270-
271-
/**
272-
* @param FactoryInterface $factory
273-
*
274-
* @return self
275-
*/
276-
protected function setFactory(FactoryInterface $factory): self
277-
{
278-
$this->factory = $factory;
279-
280-
return $this;
281-
}
282-
283-
/**
284-
* @return SchemaContainerInterface
285-
*/
286-
protected function getSchemaContainer(): SchemaContainerInterface
287-
{
288-
return $this->schemaContainer;
289-
}
290-
291-
/**
292-
* @param SchemaContainerInterface $container
293-
*
294-
* @return self
295-
*/
296-
protected function setSchemaContainer(SchemaContainerInterface $container): self
297-
{
298-
$this->schemaContainer = $container;
299-
300-
return $this;
301-
}
302-
303-
/**
304-
* @return SchemaInterface
305-
*/
306-
protected function getSchema(): SchemaInterface
307-
{
308-
return $this->schema;
309-
}
310-
311-
/**
312-
* @param SchemaInterface $schema
313-
*
314-
* @return self
315-
*/
316-
protected function setSchema(SchemaInterface $schema): self
317-
{
318-
$this->schema = $schema;
319-
320-
return $this;
321-
}
322-
323-
/**
324-
* @return mixed
325-
*/
326-
protected function getData()
327-
{
328-
return $this->data;
329-
}
330-
331-
/**
332-
* @param mixed $data
333-
*
334-
* @return self
335-
*/
336-
protected function setData($data): self
337-
{
338-
$this->data = $data;
339-
$this->index = $this->getSchema()->getId($data);
340-
$this->type = $this->getSchema()->getType();
341-
342-
return $this;
252+
return $this->schema->getResourceMeta($this->data);
343253
}
344254

345255
/**
@@ -349,7 +259,7 @@ private function cacheLinks(): void
349259
{
350260
if ($this->links === null) {
351261
$this->links = [];
352-
foreach ($this->getSchema()->getLinks($this->getData()) as $name => $link) {
262+
foreach ($this->schema->getLinks($this->data) as $name => $link) {
353263
\assert(\is_string($name) === true && empty($name) === false);
354264
\assert($link instanceof LinkInterface);
355265
$this->links[$name] = $link;

0 commit comments

Comments
 (0)