Skip to content

chore: update api-platform to 4.0.3 #454

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Oct 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
344 changes: 173 additions & 171 deletions api/composer.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion api/config/packages/api_platform.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
api_platform:
title: API Platform's demo
version: 4.0.2
version: 4.0.3
description: |
This is a demo application of the [API Platform](https://api-platform.com) framework.
[Its source code](https://github.com/api-platform/demo) includes various examples, check it out!
Expand Down
2 changes: 1 addition & 1 deletion api/src/Command/BooksImportCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public function __construct(
private readonly SerializerInterface $serializer,
private readonly DecoderInterface $decoder,
private readonly HttpClientInterface $client,
private readonly LoggerInterface $logger
private readonly LoggerInterface $logger,
) {
parent::__construct();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public function applyToCollection(QueryBuilder $queryBuilder, QueryNameGenerator
}

$queryBuilder
->andWhere(sprintf('%s.user = :user', $queryBuilder->getRootAliases()[0]))
->andWhere(\sprintf('%s.user = :user', $queryBuilder->getRootAliases()[0]))
->setParameter('user', $user)
;
}
Expand Down
6 changes: 3 additions & 3 deletions api/src/Doctrine/Orm/Filter/NameFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ protected function filterProperty(string $property, $value, QueryBuilder $queryB
$parameterName = $queryNameGenerator->generateParameterName("name{$key}");
$queryBuilder->setParameter($parameterName, "%{$value}%");
$expressions[] = $queryBuilder->expr()->orX(
$queryBuilder->expr()->like(sprintf('%s.firstName', $alias), ":{$parameterName}"),
$queryBuilder->expr()->like(sprintf('%s.lastName', $alias), ":{$parameterName}")
$queryBuilder->expr()->like(\sprintf('%s.firstName', $alias), ":{$parameterName}"),
$queryBuilder->expr()->like(\sprintf('%s.lastName', $alias), ":{$parameterName}")
);
}
$queryBuilder->andWhere($queryBuilder->expr()->andX(...$expressions));
Expand All @@ -72,7 +72,7 @@ protected function normalizeValues($value, string $property): ?array

if (empty($values)) {
$this->getLogger()->notice('Invalid filter ignored', [
'exception' => new \InvalidArgumentException(sprintf('At least one value is required, multiple values should be in "%1$s[]=firstvalue&%1$s[]=secondvalue" format', $property)),
'exception' => new \InvalidArgumentException(\sprintf('At least one value is required, multiple values should be in "%1$s[]=firstvalue&%1$s[]=secondvalue" format', $property)),
]);

return null;
Expand Down
2 changes: 1 addition & 1 deletion api/src/Entity/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,6 @@ public function getName(): ?string
return null;
}

return trim(sprintf('%s %s', $this->firstName, $this->lastName));
return trim(\sprintf('%s %s', $this->firstName, $this->lastName));
}
}
2 changes: 1 addition & 1 deletion api/src/Security/Core/UserProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public function refreshUser(UserInterface $user): UserInterface
{
$manager = $this->registry->getManagerForClass($user::class);
if (!$manager) {
throw new UnsupportedUserException(sprintf('User class "%s" not supported.', $user::class));
throw new UnsupportedUserException(\sprintf('User class "%s" not supported.', $user::class));
}

$manager->refresh($user);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public function getUserBadgeFrom(string $accessToken): UserBadge

$claims = json_decode($jws->getPayload(), true);
if (empty($claims[$this->claim])) {
throw new MissingClaimException(sprintf('"%s" claim not found.', $this->claim));
throw new MissingClaimException(\sprintf('"%s" claim not found.', $this->claim));
}

// UserLoader argument can be overridden by a UserProvider on AccessTokenAuthenticator::authenticate
Expand Down
10 changes: 5 additions & 5 deletions api/src/Security/Http/Protection/ResourceResourceHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@ public function create(object $resource, UserInterface $owner, array $context =
$this->securityAuthorizationClient->request('POST', $this->getResourceRegistrationEndpoint(), [
'auth_bearer' => $this->getPAT(),
'json' => [
'name' => sprintf('%s_%s', $shortName, $resource->getId()->__toString()),
'displayName' => sprintf('%s #%s', $operation->getShortName(), $resource->getId()->__toString()),
'name' => \sprintf('%s_%s', $shortName, $resource->getId()->__toString()),
'displayName' => \sprintf('%s #%s', $operation->getShortName(), $resource->getId()->__toString()),
'uris' => [$resourceIri],
'type' => sprintf('urn:%s:resources:%s', $this->oidcClientId, $shortName),
'type' => \sprintf('urn:%s:resources:%s', $this->oidcClientId, $shortName),
'owner' => $owner->getUserIdentifier(),
],
]);
Expand Down Expand Up @@ -75,7 +75,7 @@ public function delete(object $resource, UserInterface $owner, array $context =
'max' => 1,
'uri' => $resourceIri,
'owner' => $owner->getUserIdentifier(),
'type' => sprintf('urn:%s:resources:%s', $this->oidcClientId, $shortName),
'type' => \sprintf('urn:%s:resources:%s', $this->oidcClientId, $shortName),
],
]
);
Expand All @@ -85,7 +85,7 @@ public function delete(object $resource, UserInterface $owner, array $context =
// delete corresponding resource_set on OIDC server
$this->securityAuthorizationClient->request(
'DELETE',
sprintf('%s/%s', $this->getResourceRegistrationEndpoint(), $resourceSet['_id']),
\sprintf('%s/%s', $this->getResourceRegistrationEndpoint(), $resourceSet['_id']),
[
'auth_bearer' => $this->getPAT(),
]
Expand Down
2 changes: 1 addition & 1 deletion api/src/Security/Voter/OidcRoleVoter.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ protected function supports(string $attribute, mixed $subject): bool
protected function voteOnAttribute(string $attribute, mixed $subject, TokenInterface $token): bool
{
if (!empty($subject)) {
throw new \InvalidArgumentException(sprintf('Invalid subject type, expected empty string or "null", got "%s".', get_debug_type($subject)));
throw new \InvalidArgumentException(\sprintf('Invalid subject type, expected empty string or "null", got "%s".', get_debug_type($subject)));
}

// ensure user is authenticated
Expand Down
2 changes: 1 addition & 1 deletion api/src/Security/Voter/OidcTokenIntrospectRoleVoter.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ protected function supports(string $attribute, mixed $subject): bool
protected function voteOnAttribute(string $attribute, mixed $subject, TokenInterface $token): bool
{
if (!empty($subject)) {
throw new \InvalidArgumentException(sprintf('Invalid subject type, expected empty string or "null", got "%s".', get_debug_type($subject)));
throw new \InvalidArgumentException(\sprintf('Invalid subject type, expected empty string or "null", got "%s".', get_debug_type($subject)));
}

// ensure user is authenticated
Expand Down
4 changes: 2 additions & 2 deletions api/src/Security/Voter/OidcTokenPermissionVoter.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ protected function voteOnAttribute(string $attribute, mixed $subject, TokenInter
}

if (!\is_string($subject)) {
throw new \InvalidArgumentException(sprintf('Invalid subject type, expected "string" or "object", got "%s".', get_debug_type($subject)));
throw new \InvalidArgumentException(\sprintf('Invalid subject type, expected "string" or "object", got "%s".', get_debug_type($subject)));
}

// ensure user is authenticated
Expand All @@ -69,7 +69,7 @@ protected function voteOnAttribute(string $attribute, mixed $subject, TokenInter
'response_mode' => 'decision',
'permission_resource_format' => 'uri',
'permission_resource_matching_uri' => true,
'permission' => sprintf('%s', $subject),
'permission' => \sprintf('%s', $subject),
],
]);

Expand Down
2 changes: 1 addition & 1 deletion api/src/Serializer/BookNormalizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ final class BookNormalizer implements NormalizerInterface, NormalizerAwareInterf
*/
public function __construct(
#[Autowire(service: ReviewRepository::class)]
private ObjectRepository $repository
private ObjectRepository $repository,
) {
}

Expand Down
2 changes: 1 addition & 1 deletion api/src/Serializer/IriTransformerNormalizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ final class IriTransformerNormalizer implements NormalizerInterface, NormalizerA

public function __construct(
private readonly IriConverterInterface $iriConverter,
private readonly OperationMetadataFactoryInterface $operationMetadataFactory
private readonly OperationMetadataFactoryInterface $operationMetadataFactory,
) {
}

Expand Down
2 changes: 1 addition & 1 deletion api/src/State/Processor/BookPersistProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public function __construct(
#[Autowire(service: PersistProcessor::class)]
private ProcessorInterface $persistProcessor,
private HttpClientInterface $client,
private DecoderInterface $decoder
private DecoderInterface $decoder,
) {
}

Expand Down
2 changes: 1 addition & 1 deletion api/src/State/Processor/BookmarkPersistProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public function __construct(
#[Autowire(service: PersistProcessor::class)]
private ProcessorInterface $persistProcessor,
private Security $security,
private ClockInterface $clock
private ClockInterface $clock,
) {
}

Expand Down
4 changes: 2 additions & 2 deletions api/src/Validator/UniqueUserBookValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ final class UniqueUserBookValidator extends ConstraintValidator
public function __construct(
private readonly Security $security,
private readonly ManagerRegistry $registry,
private readonly PropertyAccessorInterface $propertyAccessor
private readonly PropertyAccessorInterface $propertyAccessor,
) {
}

Expand All @@ -47,7 +47,7 @@ public function validate($value, Constraint $constraint): void
$className = ClassUtils::getRealClass($value::class);
$manager = $this->registry->getManagerForClass($className);
if (!$manager) {
throw new ValidatorException(sprintf('"%s" is not a valid entity.', $className));
throw new ValidatorException(\sprintf('"%s" is not a valid entity.', $className));
}

if ($manager->getRepository($className)->findOneBy(['user' => $user, 'book' => $book])) {
Expand Down
14 changes: 14 additions & 0 deletions api/symfony.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,20 @@
"api-platform/schema-generator": {
"version": "v4.0.0"
},
"api-platform/symfony": {
"version": "4.0",
"recipe": {
"repo": "github.com/symfony/recipes",
"branch": "main",
"version": "4.0",
"ref": "e9952e9f393c2d048f10a78f272cd35e807d972b"
},
"files": [
"config/packages/api_platform.yaml",
"config/routes/api_platform.yaml",
"src/ApiResource/.gitignore"
]
},
"composer/pcre": {
"version": "1.0.0"
},
Expand Down
42 changes: 21 additions & 21 deletions api/tests/Api/Admin/BookTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ public function asNonAdminUserICannotGetACollectionOfBooks(int $expectedCode, st
self::assertResponseHeaderSame('content-type', 'application/problem+json; charset=utf-8');
self::assertResponseHeaderSame('link', '<http://www.w3.org/ns/hydra/error>; rel="http://www.w3.org/ns/json-ld#error",<http://localhost/docs.jsonld>; rel="http://www.w3.org/ns/hydra/core#apiDocumentation"');
self::assertJsonContains([
'@type' => 'hydra:Error',
'hydra:title' => 'An error occurred',
'hydra:description' => $hydraDescription,
'@type' => 'Error',
'title' => 'An error occurred',
'description' => $hydraDescription,
]);
}

Expand Down Expand Up @@ -196,9 +196,9 @@ public function asNonAdminUserICannotGetABook(int $expectedCode, string $hydraDe
self::assertResponseHeaderSame('content-type', 'application/problem+json; charset=utf-8');
self::assertResponseHeaderSame('link', '<http://www.w3.org/ns/hydra/error>; rel="http://www.w3.org/ns/json-ld#error",<http://localhost/docs.jsonld>; rel="http://www.w3.org/ns/hydra/core#apiDocumentation"');
self::assertJsonContains([
'@type' => 'hydra:Error',
'hydra:title' => 'An error occurred',
'hydra:description' => $hydraDescription,
'@type' => 'Error',
'title' => 'An error occurred',
'description' => $hydraDescription,
]);
}

Expand Down Expand Up @@ -254,9 +254,9 @@ public function asNonAdminUserICannotCreateABook(int $expectedCode, string $hydr
self::assertResponseHeaderSame('content-type', 'application/problem+json; charset=utf-8');
self::assertResponseHeaderSame('link', '<http://www.w3.org/ns/hydra/error>; rel="http://www.w3.org/ns/json-ld#error",<http://localhost/docs.jsonld>; rel="http://www.w3.org/ns/hydra/core#apiDocumentation"');
self::assertJsonContains([
'@type' => 'hydra:Error',
'hydra:title' => 'An error occurred',
'hydra:description' => $hydraDescription,
'@type' => 'Error',
'title' => 'An error occurred',
'description' => $hydraDescription,
]);
}

Expand Down Expand Up @@ -290,7 +290,7 @@ public static function getInvalidDataOnCreate(): iterable
Response::HTTP_UNPROCESSABLE_ENTITY,
[
'@type' => 'ConstraintViolationList',
'hydra:title' => 'An error occurred',
'title' => 'An error occurred',
'violations' => [
[
'propertyPath' => 'book',
Expand All @@ -316,8 +316,8 @@ public static function getInvalidData(): iterable
Response::HTTP_UNPROCESSABLE_ENTITY,
[
'@type' => 'ConstraintViolationList',
'hydra:title' => 'An error occurred',
'hydra:description' => 'condition: This value should be of type ' . BookCondition::class . '.',
'title' => 'An error occurred',
'description' => 'condition: This value should be of type ' . BookCondition::class . '.',
'violations' => [
[
'propertyPath' => 'condition',
Expand All @@ -334,8 +334,8 @@ public static function getInvalidData(): iterable
Response::HTTP_UNPROCESSABLE_ENTITY,
[
'@type' => 'ConstraintViolationList',
'hydra:title' => 'An error occurred',
'hydra:description' => 'condition: This value should be of type ' . BookCondition::class . '.',
'title' => 'An error occurred',
'description' => 'condition: This value should be of type ' . BookCondition::class . '.',
'violations' => [
[
'propertyPath' => 'condition',
Expand All @@ -352,7 +352,7 @@ public static function getInvalidData(): iterable
Response::HTTP_UNPROCESSABLE_ENTITY,
[
'@type' => 'ConstraintViolationList',
'hydra:title' => 'An error occurred',
'title' => 'An error occurred',
'violations' => [
[
'propertyPath' => 'book',
Expand Down Expand Up @@ -442,9 +442,9 @@ public function asNonAdminUserICannotUpdateBook(int $expectedCode, string $hydra
self::assertResponseHeaderSame('content-type', 'application/problem+json; charset=utf-8');
self::assertResponseHeaderSame('link', '<http://www.w3.org/ns/hydra/error>; rel="http://www.w3.org/ns/json-ld#error",<http://localhost/docs.jsonld>; rel="http://www.w3.org/ns/hydra/core#apiDocumentation"');
self::assertJsonContains([
'@type' => 'hydra:Error',
'hydra:title' => 'An error occurred',
'hydra:description' => $hydraDescription,
'@type' => 'Error',
'title' => 'An error occurred',
'description' => $hydraDescription,
]);
}

Expand Down Expand Up @@ -570,9 +570,9 @@ public function asNonAdminUserICannotDeleteABook(int $expectedCode, string $hydr
self::assertResponseHeaderSame('content-type', 'application/problem+json; charset=utf-8');
self::assertResponseHeaderSame('link', '<http://www.w3.org/ns/hydra/error>; rel="http://www.w3.org/ns/json-ld#error",<http://localhost/docs.jsonld>; rel="http://www.w3.org/ns/hydra/core#apiDocumentation"');
self::assertJsonContains([
'@type' => 'hydra:Error',
'hydra:title' => 'An error occurred',
'hydra:description' => $hydraDescription,
'@type' => 'Error',
'title' => 'An error occurred',
'description' => $hydraDescription,
]);
}

Expand Down
24 changes: 12 additions & 12 deletions api/tests/Api/Admin/ReviewTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@ public function asNonAdminUserICannotGetACollectionOfReviews(int $expectedCode,
self::assertResponseHeaderSame('content-type', 'application/problem+json; charset=utf-8');
self::assertResponseHeaderSame('link', '<http://www.w3.org/ns/hydra/error>; rel="http://www.w3.org/ns/json-ld#error",<http://localhost/docs.jsonld>; rel="http://www.w3.org/ns/hydra/core#apiDocumentation"');
self::assertJsonContains([
'@type' => 'hydra:Error',
'hydra:title' => 'An error occurred',
'hydra:description' => $hydraDescription,
'@type' => 'Error',
'title' => 'An error occurred',
'description' => $hydraDescription,
]);
}

Expand Down Expand Up @@ -163,9 +163,9 @@ public function asNonAdminUserICannotGetAReview(int $expectedCode, string $hydra
self::assertResponseHeaderSame('content-type', 'application/problem+json; charset=utf-8');
self::assertResponseHeaderSame('link', '<http://www.w3.org/ns/hydra/error>; rel="http://www.w3.org/ns/json-ld#error",<http://localhost/docs.jsonld>; rel="http://www.w3.org/ns/hydra/core#apiDocumentation"');
self::assertJsonContains([
'@type' => 'hydra:Error',
'hydra:title' => 'An error occurred',
'hydra:description' => $hydraDescription,
'@type' => 'Error',
'title' => 'An error occurred',
'description' => $hydraDescription,
]);
}

Expand Down Expand Up @@ -227,9 +227,9 @@ public function asNonAdminUserICannotUpdateAReview(int $expectedCode, string $hy
self::assertResponseHeaderSame('content-type', 'application/problem+json; charset=utf-8');
self::assertResponseHeaderSame('link', '<http://www.w3.org/ns/hydra/error>; rel="http://www.w3.org/ns/json-ld#error",<http://localhost/docs.jsonld>; rel="http://www.w3.org/ns/hydra/core#apiDocumentation"');
self::assertJsonContains([
'@type' => 'hydra:Error',
'hydra:title' => 'An error occurred',
'hydra:description' => $hydraDescription,
'@type' => 'Error',
'title' => 'An error occurred',
'description' => $hydraDescription,
]);
}

Expand Down Expand Up @@ -334,9 +334,9 @@ public function asNonAdminUserICannotDeleteAReview(int $expectedCode, string $hy
self::assertResponseHeaderSame('content-type', 'application/problem+json; charset=utf-8');
self::assertResponseHeaderSame('link', '<http://www.w3.org/ns/hydra/error>; rel="http://www.w3.org/ns/json-ld#error",<http://localhost/docs.jsonld>; rel="http://www.w3.org/ns/hydra/core#apiDocumentation"');
self::assertJsonContains([
'@type' => 'hydra:Error',
'hydra:title' => 'An error occurred',
'hydra:description' => $hydraDescription,
'@type' => 'Error',
'title' => 'An error occurred',
'description' => $hydraDescription,
]);
}

Expand Down
Loading
Loading