Skip to content

Commit

Permalink
better array keys type detection
Browse files Browse the repository at this point in the history
  • Loading branch information
juliangut committed Nov 9, 2018
1 parent de57d5e commit 308854e
Showing 1 changed file with 8 additions and 18 deletions.
26 changes: 8 additions & 18 deletions src/Mapping/Driver/MappingTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ protected function getGroupMetadata(array $mapping, GroupMetadata $parentGroup =
*
* @return RouteMetadata
*/
protected function getRouteMetadata($mapping, GroupMetadata $group = null): RouteMetadata
protected function getRouteMetadata(array $mapping, GroupMetadata $group = null): RouteMetadata
{
$route = (new RouteMetadata())
->setMethods($this->getMethods($mapping))
Expand Down Expand Up @@ -232,7 +232,7 @@ protected function isXmlHttpRequest(array $mapping): bool
*/
protected function getPriority(array $mapping): int
{
return \array_key_exists('priority', $mapping) ? (int) $mapping['priority'] : 0;
return (int) ($mapping['priority'] ?? 0);
}

/**
Expand Down Expand Up @@ -266,14 +266,9 @@ protected function getParameters(array $mapping): array

$parameters = $mapping['parameters'];

\array_map(
function ($key) {
if (!\is_string($key)) {
throw new DriverException('Parameters keys must be all strings');
}
},
\array_keys($parameters)
);
if ($parameters !== [] && \array_keys($parameters) === \range(0, \count($parameters) - 1)) {
throw new DriverException('Parameters keys must be all strings');
}

return $parameters;
}
Expand All @@ -295,14 +290,9 @@ protected function getPlaceholders(array $mapping): array

$placeholders = $mapping['placeholders'];

\array_map(
function ($key) {
if (!\is_string($key)) {
throw new DriverException('Placeholder keys must be all strings');
}
},
\array_keys($placeholders)
);
if ($placeholders !== [] && \array_keys($placeholders) === \range(0, \count($placeholders) - 1)) {
throw new DriverException('Placeholder keys must be all strings');
}

return $placeholders;
}
Expand Down

0 comments on commit 308854e

Please sign in to comment.