Skip to content
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

fix: lint #393

Merged
merged 1 commit into from Mar 26, 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion api/src/Command/BooksImportCommand.php
Expand Up @@ -84,7 +84,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int

$io->progressFinish();

$output->write($this->serializer->serialize($data, 'json', [JsonEncode::OPTIONS => JSON_PRETTY_PRINT]));
$output->write($this->serializer->serialize($data, 'json', [JsonEncode::OPTIONS => \JSON_PRETTY_PRINT]));

return Command::SUCCESS;
}
Expand Down
4 changes: 3 additions & 1 deletion api/src/DataFixtures/Story/DefaultStory.php
Expand Up @@ -14,7 +14,9 @@

final class DefaultStory extends Story
{
public function __construct(private readonly DecoderInterface $decoder) {}
public function __construct(private readonly DecoderInterface $decoder)
{
}

public function build(): void
{
Expand Down
Expand Up @@ -16,9 +16,11 @@
*/
final readonly class BookmarkQueryCollectionExtension implements QueryCollectionExtensionInterface
{
public function __construct(private Security $security) {}
public function __construct(private Security $security)
{
}

public function applyToCollection(QueryBuilder $queryBuilder, QueryNameGeneratorInterface $queryNameGenerator, string $resourceClass, Operation $operation = null, array $context = []): void
public function applyToCollection(QueryBuilder $queryBuilder, QueryNameGeneratorInterface $queryNameGenerator, string $resourceClass, ?Operation $operation = null, array $context = []): void
{
if (
Bookmark::class !== $resourceClass
Expand Down
2 changes: 1 addition & 1 deletion api/src/Doctrine/Orm/Filter/NameFilter.php
Expand Up @@ -31,7 +31,7 @@ public function getDescription(string $resourceClass): array
/**
* @param string|null $value
*/
protected function filterProperty(string $property, $value, QueryBuilder $queryBuilder, QueryNameGeneratorInterface $queryNameGenerator, string $resourceClass, Operation $operation = null, array $context = []): void
protected function filterProperty(string $property, $value, QueryBuilder $queryBuilder, QueryNameGeneratorInterface $queryNameGenerator, string $resourceClass, ?Operation $operation = null, array $context = []): void
{
if ('name' !== $property) {
return;
Expand Down
4 changes: 3 additions & 1 deletion api/src/Entity/User.php
Expand Up @@ -101,7 +101,9 @@ public function getId(): ?Uuid
return $this->id;
}

public function eraseCredentials(): void {}
public function eraseCredentials(): void
{
}

/**
* @return array<int, string>
Expand Down
4 changes: 3 additions & 1 deletion api/src/Security/Core/UserProvider.php
Expand Up @@ -17,7 +17,9 @@
*/
final readonly class UserProvider implements AttributesBasedUserProviderInterface
{
public function __construct(private ManagerRegistry $registry, private UserRepository $repository) {}
public function __construct(private ManagerRegistry $registry, private UserRepository $repository)
{
}

public function refreshUser(UserInterface $user): UserInterface
{
Expand Down
7 changes: 4 additions & 3 deletions api/src/Serializer/BookNormalizer.php
Expand Up @@ -24,12 +24,13 @@ public function __construct(
private RouterInterface $router,
#[Autowire(service: ReviewRepository::class)]
private ObjectRepository $repository
) {}
) {
}

/**
* @param Book $object
*/
public function normalize(mixed $object, string $format = null, array $context = []): array
public function normalize(mixed $object, ?string $format = null, array $context = []): array
{
$object->reviews = $this->router->generate('_api_/books/{bookId}/reviews{._format}_get_collection', [
'bookId' => $object->getId(),
Expand All @@ -39,7 +40,7 @@ public function normalize(mixed $object, string $format = null, array $context =
return $this->normalizer->normalize($object, $format, [self::class => true] + $context);
}

public function supportsNormalization(mixed $data, string $format = null, array $context = []): bool
public function supportsNormalization(mixed $data, ?string $format = null, array $context = []): bool
{
return $data instanceof Book && !isset($context[self::class]);
}
Expand Down
7 changes: 4 additions & 3 deletions api/src/Serializer/IriTransformerNormalizer.php
Expand Up @@ -21,9 +21,10 @@ final class IriTransformerNormalizer implements NormalizerInterface, NormalizerA
public function __construct(
private readonly IriConverterInterface $iriConverter,
private readonly OperationMetadataFactoryInterface $operationMetadataFactory
) {}
) {
}

public function normalize(mixed $object, string $format = null, array $context = []): array
public function normalize(mixed $object, ?string $format = null, array $context = []): array
{
/** @var array $data */
$data = $this->normalizer->normalize($object, $format, $context + [self::class => true]);
Expand Down Expand Up @@ -54,7 +55,7 @@ public function normalize(mixed $object, string $format = null, array $context =
return $data;
}

public function supportsNormalization(mixed $data, string $format = null, array $context = []): bool
public function supportsNormalization(mixed $data, ?string $format = null, array $context = []): bool
{
return \is_object($data)
&& !is_iterable($data)
Expand Down
3 changes: 2 additions & 1 deletion api/src/State/Processor/BookPersistProcessor.php
Expand Up @@ -29,7 +29,8 @@ public function __construct(
private ProcessorInterface $mercureProcessor,
private HttpClientInterface $client,
private DecoderInterface $decoder
) {}
) {
}

/**
* @param Book $data
Expand Down
3 changes: 2 additions & 1 deletion api/src/State/Processor/BookRemoveProcessor.php
Expand Up @@ -29,7 +29,8 @@ public function __construct(
private ProcessorInterface $mercureProcessor,
private ResourceMetadataCollectionFactoryInterface $resourceMetadataCollectionFactory,
private IriConverterInterface $iriConverter
) {}
) {
}

/**
* @param Book $data
Expand Down
3 changes: 2 additions & 1 deletion api/src/State/Processor/BookmarkPersistProcessor.php
Expand Up @@ -25,7 +25,8 @@ public function __construct(
private ProcessorInterface $persistProcessor,
private Security $security,
private ClockInterface $clock
) {}
) {
}

/**
* @param Bookmark $data
Expand Down
3 changes: 2 additions & 1 deletion api/src/State/Processor/MercureProcessor.php
Expand Up @@ -31,7 +31,8 @@ public function __construct(
private ResourceMetadataCollectionFactoryInterface $resourceMetadataCollectionFactory,
#[Autowire('%api_platform.formats%')]
private array $formats
) {}
) {
}

/**
* @param array{item_uri_template?: string, topics?: array, mercure_data?: string} $context
Expand Down
3 changes: 2 additions & 1 deletion api/src/State/Processor/ReviewPersistProcessor.php
Expand Up @@ -29,7 +29,8 @@ public function __construct(
private ProcessorInterface $mercureProcessor,
private Security $security,
private ClockInterface $clock
) {}
) {
}

/**
* @param Review $data
Expand Down
3 changes: 2 additions & 1 deletion api/src/State/Processor/ReviewRemoveProcessor.php
Expand Up @@ -29,7 +29,8 @@ public function __construct(
private ProcessorInterface $mercureProcessor,
private ResourceMetadataCollectionFactoryInterface $resourceMetadataCollectionFactory,
private IriConverterInterface $iriConverter
) {}
) {
}

/**
* @param Review $data
Expand Down
2 changes: 1 addition & 1 deletion api/src/Validator/UniqueUserBook.php
Expand Up @@ -11,7 +11,7 @@ final class UniqueUserBook extends Constraint
{
public string $message = 'The book is already related to the current user.';

public function __construct(array $options = null, string $message = null, array $groups = null, mixed $payload = null)
public function __construct(?array $options = null, ?string $message = null, ?array $groups = null, mixed $payload = null)
{
parent::__construct($options ?? [], $groups, $payload);

Expand Down
3 changes: 2 additions & 1 deletion api/src/Validator/UniqueUserBookValidator.php
Expand Up @@ -23,7 +23,8 @@ public function __construct(
private readonly Security $security,
private readonly ManagerRegistry $registry,
private readonly PropertyAccessorInterface $propertyAccessor
) {}
) {
}

/**
* @param Bookmark|Review|null $value
Expand Down
12 changes: 6 additions & 6 deletions api/tests/Api/Admin/BookTest.php
Expand Up @@ -15,12 +15,12 @@
use App\Tests\Api\Trait\SecurityTrait;
use App\Tests\Api\Trait\SerializerTrait;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\Test;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Mercure\Update;
use Zenstruck\Foundry\FactoryCollection;
use Zenstruck\Foundry\Test\Factories;
use Zenstruck\Foundry\Test\ResetDatabase;
use PHPUnit\Framework\Attributes\Test;

final class BookTest extends ApiTestCase
{
Expand Down Expand Up @@ -63,7 +63,7 @@ public function asNonAdminUserICannotGetACollectionOfBooks(int $expectedCode, st

#[Test]
#[DataProvider(methodName: 'getUrls')]
public function asAdminUserICanGetACollectionOfBooks(FactoryCollection $factory, string $url, int $hydraTotalItems, int $itemsPerPage = null): void
public function asAdminUserICanGetACollectionOfBooks(FactoryCollection $factory, string $url, int $hydraTotalItems, ?int $itemsPerPage = null): void
{
// Cannot use Factory as data provider because BookFactory has a service dependency
$factory->create();
Expand Down Expand Up @@ -315,11 +315,11 @@ public static function getInvalidData(): iterable
[
'@type' => 'ConstraintViolationList',
'hydra:title' => 'An error occurred',
'hydra:description' => 'condition: This value should be of type '.BookCondition::class.'.',
'hydra:description' => 'condition: This value should be of type ' . BookCondition::class . '.',
'violations' => [
[
'propertyPath' => 'condition',
'hint' => 'The data must belong to a backed enumeration of type '.BookCondition::class,
'hint' => 'The data must belong to a backed enumeration of type ' . BookCondition::class,
],
],
],
Expand All @@ -333,11 +333,11 @@ public static function getInvalidData(): iterable
[
'@type' => 'ConstraintViolationList',
'hydra:title' => 'An error occurred',
'hydra:description' => 'condition: This value should be of type '.BookCondition::class.'.',
'hydra:description' => 'condition: This value should be of type ' . BookCondition::class . '.',
'violations' => [
[
'propertyPath' => 'condition',
'hint' => 'The data must belong to a backed enumeration of type '.BookCondition::class,
'hint' => 'The data must belong to a backed enumeration of type ' . BookCondition::class,
],
],
],
Expand Down
4 changes: 2 additions & 2 deletions api/tests/Api/Admin/ReviewTest.php
Expand Up @@ -16,12 +16,12 @@
use App\Tests\Api\Trait\SecurityTrait;
use App\Tests\Api\Trait\SerializerTrait;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\Test;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Mercure\Update;
use Zenstruck\Foundry\FactoryCollection;
use Zenstruck\Foundry\Test\Factories;
use Zenstruck\Foundry\Test\ResetDatabase;
use PHPUnit\Framework\Attributes\Test;

final class ReviewTest extends ApiTestCase
{
Expand Down Expand Up @@ -64,7 +64,7 @@ public function asNonAdminUserICannotGetACollectionOfReviews(int $expectedCode,

#[Test]
#[DataProvider(methodName: 'getAdminUrls')]
public function asAdminUserICanGetACollectionOfReviews(FactoryCollection $factory, callable|string $url, int $hydraTotalItems, int $itemsPerPage = null): void
public function asAdminUserICanGetACollectionOfReviews(FactoryCollection $factory, callable|string $url, int $hydraTotalItems, ?int $itemsPerPage = null): void
{
$factory->create();

Expand Down
4 changes: 2 additions & 2 deletions api/tests/Api/Admin/UserTest.php
Expand Up @@ -11,11 +11,11 @@
use App\Tests\Api\Admin\Trait\UsersDataProviderTrait;
use App\Tests\Api\Trait\SecurityTrait;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\Test;
use Symfony\Component\Uid\Uuid;
use Zenstruck\Foundry\FactoryCollection;
use Zenstruck\Foundry\Test\Factories;
use Zenstruck\Foundry\Test\ResetDatabase;
use PHPUnit\Framework\Attributes\Test;

final class UserTest extends ApiTestCase
{
Expand Down Expand Up @@ -57,7 +57,7 @@ public function asNonAdminUserICannotGetACollectionOfUsers(int $expectedCode, st

#[Test]
#[DataProvider(methodName: 'getAdminUrls')]
public function asAdminUserICanGetACollectionOfUsers(FactoryCollection $factory, callable|string $url, int $hydraTotalItems, int $itemsPerPage = null): void
public function asAdminUserICanGetACollectionOfUsers(FactoryCollection $factory, callable|string $url, int $hydraTotalItems, ?int $itemsPerPage = null): void
{
$factory->create();

Expand Down
2 changes: 1 addition & 1 deletion api/tests/Api/BookTest.php
Expand Up @@ -10,11 +10,11 @@
use App\DataFixtures\Factory\ReviewFactory;
use App\Enum\BookCondition;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\Test;
use Symfony\Component\HttpFoundation\Response;
use Zenstruck\Foundry\FactoryCollection;
use Zenstruck\Foundry\Test\Factories;
use Zenstruck\Foundry\Test\ResetDatabase;
use PHPUnit\Framework\Attributes\Test;

final class BookTest extends ApiTestCase
{
Expand Down
4 changes: 2 additions & 2 deletions api/tests/Api/BookmarkTest.php
Expand Up @@ -128,11 +128,11 @@ public function asAUserICannotCreateABookmarkWithInvalidData(): void
self::assertJsonContains([
'@type' => 'ConstraintViolationList',
'hydra:title' => 'An error occurred',
'hydra:description' => 'book: This value should be of type '.Book::class.'.',
'hydra:description' => 'book: This value should be of type ' . Book::class . '.',
'violations' => [
[
'propertyPath' => 'book',
'hint' => 'Item not found for "/books/'.$uuid.'".',
'hint' => 'Item not found for "/books/' . $uuid . '".',
],
],
]);
Expand Down
2 changes: 1 addition & 1 deletion api/tests/Api/Trait/SerializerTrait.php
Expand Up @@ -19,7 +19,7 @@ public static function serialize(mixed $data, string $format, array $context = [
static::fail('A client must have Serializer enabled to make serialization. Did you forget to require symfony/serializer?');
}

public static function getOperationNormalizationContext(string $resourceClass, string $operationName = null): array
public static function getOperationNormalizationContext(string $resourceClass, ?string $operationName = null): array
{
if ($resourceMetadataFactoryCollection = static::getContainer()->get('api_platform.metadata.resource.metadata_collection_factory')) {
$operation = $resourceMetadataFactoryCollection->create($resourceClass)->getOperation($operationName);
Expand Down
Expand Up @@ -9,11 +9,11 @@
use App\Doctrine\Orm\Extension\BookmarkQueryCollectionExtension;
use App\Entity\Bookmark;
use Doctrine\ORM\QueryBuilder;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
use Symfony\Bundle\SecurityBundle\Security;
use Symfony\Component\Security\Core\User\UserInterface;
use PHPUnit\Framework\Attributes\Test;

final class BookmarkQueryCollectionExtensionTest extends TestCase
{
Expand Down
2 changes: 1 addition & 1 deletion api/tests/Security/Core/UserProviderTest.php
Expand Up @@ -10,12 +10,12 @@
use Doctrine\Persistence\ManagerRegistry;
use Doctrine\Persistence\ObjectManager;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Security\Core\Exception\UnsupportedUserException;
use Symfony\Component\Security\Core\User\UserInterface;
use Symfony\Component\Uid\Uuid;
use PHPUnit\Framework\Attributes\Test;

final class UserProviderTest extends TestCase
{
Expand Down
2 changes: 1 addition & 1 deletion api/tests/Serializer/BookNormalizerTest.php
Expand Up @@ -8,12 +8,12 @@
use App\Enum\BookCondition;
use App\Repository\ReviewRepository;
use App\Serializer\BookNormalizer;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Routing\RouterInterface;
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
use Symfony\Component\Uid\Uuid;
use PHPUnit\Framework\Attributes\Test;

final class BookNormalizerTest extends TestCase
{
Expand Down
2 changes: 1 addition & 1 deletion api/tests/Serializer/IriTransformerNormalizerTest.php
Expand Up @@ -10,10 +10,10 @@
use ApiPlatform\Metadata\Operation\Factory\OperationMetadataFactoryInterface;
use App\Serializer\IriTransformerNormalizer;
use Doctrine\Common\Collections\ArrayCollection;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
use PHPUnit\Framework\Attributes\Test;

final class IriTransformerNormalizerTest extends TestCase
{
Expand Down
2 changes: 1 addition & 1 deletion api/tests/State/Processor/BookPersistProcessorTest.php
Expand Up @@ -8,13 +8,13 @@
use ApiPlatform\State\ProcessorInterface;
use App\Entity\Book;
use App\State\Processor\BookPersistProcessor;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Serializer\Encoder\DecoderInterface;
use Symfony\Contracts\HttpClient\HttpClientInterface;
use Symfony\Contracts\HttpClient\ResponseInterface;
use PHPUnit\Framework\Attributes\Test;

final class BookPersistProcessorTest extends TestCase
{
Expand Down