Skip to content

Commit

Permalink
revert code style & improve ApiPlatformExtensionTest
Browse files Browse the repository at this point in the history
  • Loading branch information
laryjulien committed Nov 12, 2021
1 parent f5929a5 commit 8732bc9
Show file tree
Hide file tree
Showing 226 changed files with 10,143 additions and 3,689 deletions.
10 changes: 8 additions & 2 deletions src/Action/ExceptionAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,10 @@ public function __invoke($exception, Request $request): Response
$exceptionClass = $exception->getClass();
$statusCode = $exception->getStatusCode();

$exceptionToStatus = array_merge($this->exceptionToStatus, $operation ? $operation->getExceptionToStatus() ?? [] : $this->getOperationExceptionToStatus($request));
$exceptionToStatus = array_merge(
$this->exceptionToStatus,
$operation ? $operation->getExceptionToStatus() ?? [] : $this->getOperationExceptionToStatus($request)
);

foreach ($exceptionToStatus as $class => $status) {
if (is_a($exceptionClass, $class, true)) {
Expand Down Expand Up @@ -107,6 +110,9 @@ private function getOperationExceptionToStatus(Request $request): array
throw new \LogicException('"exception_to_status" attribute should be an array.');
}

return array_merge($resourceExceptionToStatus, $operationExceptionToStatus);
return array_merge(
$resourceExceptionToStatus,
$operationExceptionToStatus
);
}
}
5 changes: 4 additions & 1 deletion src/Bridge/Doctrine/Common/Filter/ExistsFilterTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,10 @@ abstract protected function normalizePropertyName($property);
private function normalizeValue($value, string $property): ?bool
{
if (\is_array($value) && isset($value[self::QUERY_PARAMETER_KEY])) {
@trigger_error(sprintf('The ExistsFilter syntax "%s[exists]=true/false" is deprecated since 2.5. Use the syntax "%s[%s]=true/false" instead.', $property, $this->existsParameterName, $property), \E_USER_DEPRECATED);
@trigger_error(
sprintf('The ExistsFilter syntax "%s[exists]=true/false" is deprecated since 2.5. Use the syntax "%s[%s]=true/false" instead.', $property, $this->existsParameterName, $property),
\E_USER_DEPRECATED
);
$value = $value[self::QUERY_PARAMETER_KEY];
}

Expand Down
26 changes: 21 additions & 5 deletions src/Bridge/Doctrine/Orm/State/UriVariablesHandlerTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,19 +38,35 @@ private function handleUriVariables(QueryBuilder $queryBuilder, array $identifie
$propertyIdentifier = $uriVariable->getIdentifiers()[0];
$joinAlias = $queryNameGenerator->generateJoinAlias($inverseProperty);

$queryBuilder->join($uriVariable->getTargetClass(), $joinAlias, 'with', "$alias.$propertyIdentifier = $joinAlias.$inverseProperty");
$queryBuilder->join(
$uriVariable->getTargetClass(),
$joinAlias,
'with',
"$alias.$propertyIdentifier = $joinAlias.$inverseProperty"
);

$expression = $queryBuilder->expr()->eq("{$joinAlias}.{$propertyIdentifier}", $placeholder);
$expression = $queryBuilder->expr()->eq(
"{$joinAlias}.{$propertyIdentifier}",
$placeholder
);
} elseif ($property = $uriVariable->getProperty()) {
$propertyIdentifier = $uriVariable->getIdentifiers()[0];
$joinAlias = $queryNameGenerator->generateJoinAlias($property);

$queryBuilder->join("$alias.$property", $joinAlias, );
$queryBuilder->join(
"$alias.$property",
$joinAlias,
);

$expression = $queryBuilder->expr()->eq("{$joinAlias}.{$propertyIdentifier}", $placeholder);
$expression = $queryBuilder->expr()->eq(
"{$joinAlias}.{$propertyIdentifier}",
$placeholder
);
} else {
$propertyIdentifier = $uriVariable->getIdentifiers()[0];
$expression = $queryBuilder->expr()->eq("{$alias}.{$propertyIdentifier}", $placeholder);
$expression = $queryBuilder->expr()->eq(
"{$alias}.{$propertyIdentifier}", $placeholder
);
}
$queryBuilder->andWhere($expression);
$queryBuilder->setParameter($placeholder, $value, $doctrineClassMetadata->getTypeOfField($identifier));
Expand Down
9 changes: 7 additions & 2 deletions src/Core/Annotation/ApiFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,13 @@ final class ApiFilter
* @param string $id
* @param string $strategy
*/
public function __construct($filterClass, ?string $id = null, ?string $strategy = null, array $properties = [], array $arguments = [])
{
public function __construct(
$filterClass,
?string $id = null,
?string $strategy = null,
array $properties = [],
array $arguments = []
) {
if (\is_array($filterClass)) { /** @phpstan-ignore-line Doctrine annotations */
$options = $filterClass;
$this->filterClass = $options['value'] ?? null;
Expand Down
30 changes: 27 additions & 3 deletions src/Core/Annotation/ApiProperty.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,33 @@ final class ApiProperty
*
* @throws InvalidArgumentException
*/
public function __construct($description = null, ?bool $readable = null, ?bool $writable = null, ?bool $readableLink = null, ?bool $writableLink = null, ?bool $required = null, ?string $iri = null, ?bool $identifier = null, $default = null, $example = null, // attributes
?array $attributes = null, ?string $deprecationReason = null, ?bool $fetchable = null, ?bool $fetchEager = null, ?array $jsonldContext = null, ?array $openapiContext = null, ?bool $push = null, ?string $security = null, ?array $swaggerContext = null, ?string $securityPostDenormalize = null, ?array $types = [], ?array $builtinTypes = [])
{
public function __construct(
$description = null,
?bool $readable = null,
?bool $writable = null,
?bool $readableLink = null,
?bool $writableLink = null,
?bool $required = null,
?string $iri = null,
?bool $identifier = null,
$default = null,
$example = null,

// attributes
?array $attributes = null,
?string $deprecationReason = null,
?bool $fetchable = null,
?bool $fetchEager = null,
?array $jsonldContext = null,
?array $openapiContext = null,
?bool $push = null,
?string $security = null,
?array $swaggerContext = null,
?string $securityPostDenormalize = null,

?array $types = [],
?array $builtinTypes = []
) {
if (!\is_array($description)) { // @phpstan-ignore-line Doctrine annotations support
[$publicProperties, $configurableAttributes] = self::getConfigMetadata();

Expand Down
55 changes: 52 additions & 3 deletions src/Core/Annotation/ApiResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -181,9 +181,58 @@ final class ApiResource
*
* @throws InvalidArgumentException
*/
public function __construct($description = null, ?array $collectionOperations = null, ?array $graphql = null, ?string $iri = null, ?array $itemOperations = null, ?string $shortName = null, ?array $subresourceOperations = null, // attributes
?array $attributes = null, ?array $cacheHeaders = null, ?array $denormalizationContext = null, ?string $deprecationReason = null, ?bool $elasticsearch = null, ?bool $fetchPartial = null, ?bool $forceEager = null, ?array $formats = null, ?array $filters = null, ?array $hydraContext = null, $input = null, $mercure = null, $messenger = null, ?array $normalizationContext = null, ?array $openapiContext = null, ?array $order = null, $output = null, ?bool $paginationClientEnabled = null, ?bool $paginationClientItemsPerPage = null, ?bool $paginationClientPartial = null, ?array $paginationViaCursor = null, ?bool $paginationEnabled = null, ?bool $paginationFetchJoinCollection = null, ?int $paginationItemsPerPage = null, ?int $paginationMaximumItemsPerPage = null, ?bool $paginationPartial = null, ?string $routePrefix = null, ?string $security = null, ?string $securityMessage = null, ?string $securityPostDenormalize = null, ?string $securityPostDenormalizeMessage = null, ?string $securityPostValidation = null, ?string $securityPostValidationMessage = null, ?bool $stateless = null, ?string $sunset = null, ?array $swaggerContext = null, ?array $validationGroups = null, ?int $urlGenerationStrategy = null, ?bool $compositeIdentifier = null, ?array $exceptionToStatus = null, ?bool $queryParameterValidationEnabled = null)
{
public function __construct(
$description = null,
?array $collectionOperations = null,
?array $graphql = null,
?string $iri = null,
?array $itemOperations = null,
?string $shortName = null,
?array $subresourceOperations = null,

// attributes
?array $attributes = null,
?array $cacheHeaders = null,
?array $denormalizationContext = null,
?string $deprecationReason = null,
?bool $elasticsearch = null,
?bool $fetchPartial = null,
?bool $forceEager = null,
?array $formats = null,
?array $filters = null,
?array $hydraContext = null,
$input = null,
$mercure = null,
$messenger = null,
?array $normalizationContext = null,
?array $openapiContext = null,
?array $order = null,
$output = null,
?bool $paginationClientEnabled = null,
?bool $paginationClientItemsPerPage = null,
?bool $paginationClientPartial = null,
?array $paginationViaCursor = null,
?bool $paginationEnabled = null,
?bool $paginationFetchJoinCollection = null,
?int $paginationItemsPerPage = null,
?int $paginationMaximumItemsPerPage = null,
?bool $paginationPartial = null,
?string $routePrefix = null,
?string $security = null,
?string $securityMessage = null,
?string $securityPostDenormalize = null,
?string $securityPostDenormalizeMessage = null,
?string $securityPostValidation = null,
?string $securityPostValidationMessage = null,
?bool $stateless = null,
?string $sunset = null,
?array $swaggerContext = null,
?array $validationGroups = null,
?int $urlGenerationStrategy = null,
?bool $compositeIdentifier = null,
?array $exceptionToStatus = null,
?bool $queryParameterValidationEnabled = null
) {
if (!\is_array($description)) { // @phpstan-ignore-line Doctrine annotations support
[$publicProperties, $configurableAttributes] = self::getConfigMetadata();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,13 @@ public function __construct(ResourceClassResolverInterface $resourceClassResolve
$rawurlencode = ExpressionFunction::fromPhp('rawurlencode', 'escape');
$this->expressionLanguage->addFunction($rawurlencode);

$this->expressionLanguage->addFunction(new ExpressionFunction('iri', static function (string $apiResource, int $referenceType = UrlGeneratorInterface::ABS_URL): string {
return sprintf('iri(%s, %d)', $apiResource, $referenceType);
}, static function (array $arguments, $apiResource, int $referenceType = UrlGeneratorInterface::ABS_URL) use ($iriConverter): string {
return $iriConverter->getIriFromItem($apiResource, null, $referenceType);
}));
$this->expressionLanguage->addFunction(
new ExpressionFunction('iri', static function (string $apiResource, int $referenceType = UrlGeneratorInterface::ABS_URL): string {
return sprintf('iri(%s, %d)', $apiResource, $referenceType);
}, static function (array $arguments, $apiResource, int $referenceType = UrlGeneratorInterface::ABS_URL) use ($iriConverter): string {
return $iriConverter->getIriFromItem($apiResource, null, $referenceType);
})
);
}
}

Expand Down Expand Up @@ -300,7 +302,11 @@ private function getGraphQlSubscriptionUpdates($object, array $options, string $

$updates = [];
foreach ($payloads as [$subscriptionId, $data]) {
$updates[] = $this->buildUpdate($this->graphQlMercureSubscriptionIriGenerator->generateTopicIri($subscriptionId), (string) (new JsonResponse($data))->getContent(), $options);
$updates[] = $this->buildUpdate(
$this->graphQlMercureSubscriptionIriGenerator->generateTopicIri($subscriptionId),
(string) (new JsonResponse($data))->getContent(),
$options
);
}

return $updates;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,9 @@ public function applyToCollection(Builder $aggregationBuilder, string $resourceC
if ($this->isPropertyNested($field, $resourceClass)) {
[$field] = $this->addLookupsForNestedProperty($field, $aggregationBuilder, $resourceClass);
}
$aggregationBuilder->sort($context['mongodb_odm_sort_fields'] = ($context['mongodb_odm_sort_fields'] ?? []) + [$field => $order]);
$aggregationBuilder->sort(
$context['mongodb_odm_sort_fields'] = ($context['mongodb_odm_sort_fields'] ?? []) + [$field => $order]
);
}

return;
Expand All @@ -101,7 +103,9 @@ public function applyToCollection(Builder $aggregationBuilder, string $resourceC

if (null !== $this->order) {
foreach ($identifiers as $identifier) {
$aggregationBuilder->sort($context['mongodb_odm_sort_fields'] = ($context['mongodb_odm_sort_fields'] ?? []) + [$identifier => $this->order]);
$aggregationBuilder->sort(
$context['mongodb_odm_sort_fields'] = ($context['mongodb_odm_sort_fields'] ?? []) + [$identifier => $this->order]
);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,13 @@ public function applyToCollection(Builder $aggregationBuilder, string $resourceC

$aggregationBuilder
->facet()
->field('results')->pipeline($resultsAggregationBuilder)
->field('count')->pipeline($repository->createAggregationBuilder()
->count('count'));
->field('results')->pipeline(
$resultsAggregationBuilder
)
->field('count')->pipeline(
$repository->createAggregationBuilder()
->count('count')
);
}

/**
Expand Down
37 changes: 32 additions & 5 deletions src/Core/Bridge/Doctrine/MongoDbOdm/Filter/DateFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,19 +65,43 @@ protected function filterProperty(string $property, $values, Builder $aggregatio
}

if (isset($values[self::PARAMETER_BEFORE])) {
$this->addMatch($aggregationBuilder, $matchField, self::PARAMETER_BEFORE, $values[self::PARAMETER_BEFORE], $nullManagement);
$this->addMatch(
$aggregationBuilder,
$matchField,
self::PARAMETER_BEFORE,
$values[self::PARAMETER_BEFORE],
$nullManagement
);
}

if (isset($values[self::PARAMETER_STRICTLY_BEFORE])) {
$this->addMatch($aggregationBuilder, $matchField, self::PARAMETER_STRICTLY_BEFORE, $values[self::PARAMETER_STRICTLY_BEFORE], $nullManagement);
$this->addMatch(
$aggregationBuilder,
$matchField,
self::PARAMETER_STRICTLY_BEFORE,
$values[self::PARAMETER_STRICTLY_BEFORE],
$nullManagement
);
}

if (isset($values[self::PARAMETER_AFTER])) {
$this->addMatch($aggregationBuilder, $matchField, self::PARAMETER_AFTER, $values[self::PARAMETER_AFTER], $nullManagement);
$this->addMatch(
$aggregationBuilder,
$matchField,
self::PARAMETER_AFTER,
$values[self::PARAMETER_AFTER],
$nullManagement
);
}

if (isset($values[self::PARAMETER_STRICTLY_AFTER])) {
$this->addMatch($aggregationBuilder, $matchField, self::PARAMETER_STRICTLY_AFTER, $values[self::PARAMETER_STRICTLY_AFTER], $nullManagement);
$this->addMatch(
$aggregationBuilder,
$matchField,
self::PARAMETER_STRICTLY_AFTER,
$values[self::PARAMETER_STRICTLY_AFTER],
$nullManagement
);
}
}

Expand Down Expand Up @@ -116,7 +140,10 @@ private function addMatch(Builder $aggregationBuilder, string $field, string $op
(self::INCLUDE_NULL_AFTER === $nullManagement && \in_array($operator, [self::PARAMETER_AFTER, self::PARAMETER_STRICTLY_AFTER], true)) ||
(self::INCLUDE_NULL_BEFORE_AND_AFTER === $nullManagement && \in_array($operator, [self::PARAMETER_AFTER, self::PARAMETER_STRICTLY_AFTER, self::PARAMETER_BEFORE, self::PARAMETER_STRICTLY_BEFORE], true))
) {
$aggregationBuilder->match()->addOr($aggregationBuilder->matchExpr()->field($field)->operator($operatorValue[$operator], $value), $aggregationBuilder->matchExpr()->field($field)->equals(null));
$aggregationBuilder->match()->addOr(
$aggregationBuilder->matchExpr()->field($field)->operator($operatorValue[$operator], $value),
$aggregationBuilder->matchExpr()->field($field)->equals(null)
);

return;
}
Expand Down
4 changes: 3 additions & 1 deletion src/Core/Bridge/Doctrine/MongoDbOdm/Filter/OrderFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@ protected function filterProperty(string $property, $direction, Builder $aggrega
[$matchField] = $this->addLookupsForNestedProperty($property, $aggregationBuilder, $resourceClass);
}

$aggregationBuilder->sort($context['mongodb_odm_sort_fields'] = ($context['mongodb_odm_sort_fields'] ?? []) + [$matchField => $direction]);
$aggregationBuilder->sort(
$context['mongodb_odm_sort_fields'] = ($context['mongodb_odm_sort_fields'] ?? []) + [$matchField => $direction]
);
}
}
8 changes: 7 additions & 1 deletion src/Core/Bridge/Doctrine/MongoDbOdm/Filter/RangeFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,13 @@ protected function filterProperty(string $property, $values, Builder $aggregatio
}

foreach ($values as $operator => $value) {
$this->addMatch($aggregationBuilder, $field, $matchField, $operator, $value);
$this->addMatch(
$aggregationBuilder,
$field,
$matchField,
$operator,
$value
);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,14 @@ public function getTypes($class, $property, array $context = []): ?array
$collectionKeyType = Type::BUILTIN_TYPE_INT;

return [
new Type(Type::BUILTIN_TYPE_OBJECT, false, Collection::class, true, new Type($collectionKeyType), new Type(Type::BUILTIN_TYPE_OBJECT, false, $class)),
new Type(
Type::BUILTIN_TYPE_OBJECT,
false,
Collection::class,
true,
new Type($collectionKeyType),
new Type(Type::BUILTIN_TYPE_OBJECT, false, $class)
),
];
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,11 @@ public function getResult(QueryBuilder $queryBuilder, string $resourceClass = nu
if (null === $this->requestStack) {
$isPartialEnabled = $this->pagination->isPartialEnabled($resourceClass, $operationName, $context);
} else {
$isPartialEnabled = $this->isPartialPaginationEnabled($this->requestStack->getCurrentRequest(), null === $resourceClass ? null : $this->resourceMetadataFactory->create($resourceClass), $operationName);
$isPartialEnabled = $this->isPartialPaginationEnabled(
$this->requestStack->getCurrentRequest(),
null === $resourceClass ? null : $this->resourceMetadataFactory->create($resourceClass),
$operationName
);
}

if ($isPartialEnabled) {
Expand Down
Loading

0 comments on commit 8732bc9

Please sign in to comment.