Skip to content

Commit

Permalink
fix: make php-cs-fixer happy
Browse files Browse the repository at this point in the history
  • Loading branch information
vincentchalamon committed Dec 7, 2023
1 parent a4d625b commit 4f91b6a
Show file tree
Hide file tree
Showing 47 changed files with 717 additions and 437 deletions.
5 changes: 3 additions & 2 deletions api/.php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,20 @@
'@Symfony' => true,
'@Symfony:risky' => true,
'declare_strict_types' => true,
'php_unit_data_provider_name' => false,
'php_unit_data_provider_return_type' => true,
'php_unit_data_provider_static' => true,
'php_unit_dedicate_assert' => true,
'php_unit_dedicate_assert_internal_type' => true,
'php_unit_expectation' => true,
'php_unit_fqcn_annotation' => true,
'php_unit_internal_class' => true,
'php_unit_internal_class' => false,
'php_unit_method_casing' => true,
'php_unit_mock_short_will_return' => true,
'php_unit_namespaced' => true,
'php_unit_no_expectation_annotation' => true,
'php_unit_set_up_tear_down_visibility' => true,
'php_unit_strict' => true,
'php_unit_strict' => false,
'php_unit_test_annotation' => ['style' => 'annotation'],
'php_unit_test_case_static_method_calls' => false,
'php_unit_test_class_requires_covers' => false,
Expand Down
10 changes: 6 additions & 4 deletions api/config/bootstrap.php
Original file line number Diff line number Diff line change
@@ -1,23 +1,25 @@
<?php

declare(strict_types=1);

use Symfony\Component\Dotenv\Dotenv;

require dirname(__DIR__).'/vendor/autoload.php';
require dirname(__DIR__) . '/vendor/autoload.php';

if (!class_exists(Dotenv::class)) {
throw new LogicException('Please run "composer require symfony/dotenv" to load the ".env" files configuring the application.');
}

// Load cached env vars if the .env.local.php file exists
// Run "composer dump-env prod" to create it (requires symfony/flex >=1.2)
if (is_array($env = @include dirname(__DIR__).'/.env.local.php') && (!isset($env['APP_ENV']) || ($_SERVER['APP_ENV'] ?? $_ENV['APP_ENV'] ?? $env['APP_ENV']) === $env['APP_ENV'])) {
if (is_array($env = @include dirname(__DIR__) . '/.env.local.php') && (!isset($env['APP_ENV']) || ($_SERVER['APP_ENV'] ?? $_ENV['APP_ENV'] ?? $env['APP_ENV']) === $env['APP_ENV'])) {
(new Dotenv())->usePutenv(false)->populate($env);
} else {
// load all the .env files
(new Dotenv())->usePutenv(false)->loadEnv(dirname(__DIR__).'/.env');
(new Dotenv())->usePutenv(false)->loadEnv(dirname(__DIR__) . '/.env');
}

$_SERVER += $_ENV;
$_SERVER['APP_ENV'] = $_ENV['APP_ENV'] = ($_SERVER['APP_ENV'] ?? $_ENV['APP_ENV'] ?? null) ?: 'dev';
$_SERVER['APP_DEBUG'] = $_SERVER['APP_DEBUG'] ?? $_ENV['APP_DEBUG'] ?? 'prod' !== $_SERVER['APP_ENV'];
$_SERVER['APP_DEBUG'] = $_ENV['APP_DEBUG'] = (int) $_SERVER['APP_DEBUG'] || filter_var($_SERVER['APP_DEBUG'], FILTER_VALIDATE_BOOLEAN) ? '1' : '0';
$_SERVER['APP_DEBUG'] = $_ENV['APP_DEBUG'] = (int) $_SERVER['APP_DEBUG'] || filter_var($_SERVER['APP_DEBUG'], \FILTER_VALIDATE_BOOLEAN) ? '1' : '0';
2 changes: 2 additions & 0 deletions api/config/bundles.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

return [
Symfony\Bundle\FrameworkBundle\FrameworkBundle::class => ['all' => true],
Symfony\Bundle\SecurityBundle\SecurityBundle::class => ['all' => true],
Expand Down
6 changes: 4 additions & 2 deletions api/config/preload.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

if (file_exists(dirname(__DIR__).'/var/cache/prod/App_KernelProdContainer.preload.php')) {
require dirname(__DIR__).'/var/cache/prod/App_KernelProdContainer.preload.php';
declare(strict_types=1);

if (file_exists(dirname(__DIR__) . '/var/cache/prod/App_KernelProdContainer.preload.php')) {
require dirname(__DIR__) . '/var/cache/prod/App_KernelProdContainer.preload.php';
}
8 changes: 5 additions & 3 deletions api/public/index.php
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
<?php

declare(strict_types=1);

use App\Kernel;

require_once dirname(__DIR__).'/vendor/autoload_runtime.php';
require_once dirname(__DIR__) . '/vendor/autoload_runtime.php';

// Support CloudFlare Flexible SSL
// https://developers.cloudflare.com/fundamentals/reference/http-request-headers/#cf-visitor
if ($_SERVER['HTTP_CF_VISITOR'] ?? false) {
$_SERVER['HTTP_X_FORWARDED_PROTO'] = \json_decode($_SERVER['HTTP_CF_VISITOR'], true)['scheme'];
$_SERVER['HTTP_X_FORWARDED_PROTO'] = json_decode($_SERVER['HTTP_CF_VISITOR'], true)['scheme'];
}

return function (array $context) {
return static function (array $context) {
return new Kernel($context['APP_ENV'], (bool) $context['APP_DEBUG']);
};
10 changes: 5 additions & 5 deletions api/src/Command/BooksImportCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,21 +52,21 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$io->progressStart($limit);
$data = [];
while ($offset < $limit) {
/* @see https://openlibrary.org/dev/docs/restful_api */
$uri = 'https://openlibrary.org/query?type=/type/edition&languages=/languages/eng&subjects=Science%20Fiction&authors=&covers=&title=&description=&publish_date&offset='.$offset;
/** @see https://openlibrary.org/dev/docs/restful_api */
$uri = 'https://openlibrary.org/query?type=/type/edition&languages=/languages/eng&subjects=Science%20Fiction&authors=&covers=&title=&description=&publish_date&offset=' . $offset;
$books = $this->getData($uri);
foreach ($books as $book) {
$this->logger->info('Importing book.', [
'book' => 'https://openlibrary.org'.$book['key'].'.json',
'book' => 'https://openlibrary.org' . $book['key'] . '.json',
]);

$datum = [
'book' => 'https://openlibrary.org'.$book['key'].'.json',
'book' => 'https://openlibrary.org' . $book['key'] . '.json',
'title' => $book['title'],
];

if (isset($book['authors'][0]['key'])) {
$author = $this->getData('https://openlibrary.org'.$book['authors'][0]['key']);
$author = $this->getData('https://openlibrary.org' . $book['authors'][0]['key']);
if (isset($author['name'])) {
$datum['author'] = $author['name'];
}
Expand Down
52 changes: 26 additions & 26 deletions api/src/DataFixtures/Factory/BookFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public function __construct()
{
parent::__construct();

$this->data = json_decode(file_get_contents(__DIR__.'/../books.json'), true);
$this->data = json_decode(file_get_contents(__DIR__ . '/../books.json'), true);
shuffle($this->data);
}

Expand All @@ -77,36 +77,36 @@ protected function getDefaults(): array
protected function initialize(): self
{
return $this
->afterInstantiate(function (Book $book): void {
if ($book->book && $book->title && $book->author) {
return;
}
->afterInstantiate(function (Book $book): void {
if ($book->book && $book->title && $book->author) {
return;
}

if (!$book->book) {
$book->book = 'https://openlibrary.org/books/OL'.self::faker()->unique()->randomNumber(7, true).'M.json';
$book->title ??= self::faker()->text();
$book->author ??= self::faker()->name();
if (!$book->book) {
$book->book = 'https://openlibrary.org/books/OL' . self::faker()->unique()->randomNumber(7, true) . 'M.json';
$book->title ??= self::faker()->text();
$book->author ??= self::faker()->name();

return;
}
return;
}

// An Open Library book URI has been specified: try to find it in the array of books
$data = array_filter($this->data, static function (array $datum) use ($book) {
return $book->book === $datum['book'];
});
if ($data) {
$datum = current($data);
$book->title ??= $datum['title'];
// A book can have no author
$book->author ??= $datum['author'] ?? self::faker()->name();
// An Open Library book URI has been specified: try to find it in the array of books
$data = array_filter($this->data, static function (array $datum) use ($book) {
return $book->book === $datum['book'];
});
if ($data) {
$datum = current($data);
$book->title ??= $datum['title'];
// A book can have no author
$book->author ??= $datum['author'] ?? self::faker()->name();

return;
}
return;
}

// No Open Library book has been found in the array of books
$book->title ??= self::faker()->text();
$book->author ??= self::faker()->name();
})
// No Open Library book has been found in the array of books
$book->title ??= self::faker()->text();
$book->author ??= self::faker()->name();
})
;
}

Expand Down
9 changes: 4 additions & 5 deletions api/src/DataFixtures/Factory/BookmarkFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ public function __construct()
protected function getDefaults(): array
{
return [
'user' => lazy(fn () => UserFactory::new()),
'book' => lazy(fn () => BookFactory::new()),
'user' => lazy(static fn () => UserFactory::new()),
'book' => lazy(static fn () => BookFactory::new()),
'bookmarkedAt' => \DateTimeImmutable::createFromMutable(self::faker()->dateTime()),
];
}
Expand All @@ -74,9 +74,8 @@ protected function getDefaults(): array
*/
protected function initialize(): self
{
return $this
// ->afterInstantiate(function(Bookmark $bookmark): void {})
;
return $this;
// ->afterInstantiate(function(Bookmark $bookmark): void {})
}

protected static function getClass(): string
Expand Down
9 changes: 4 additions & 5 deletions api/src/DataFixtures/Factory/ReviewFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ public function __construct()
protected function getDefaults(): array
{
return [
'user' => lazy(fn () => UserFactory::new()),
'book' => lazy(fn () => BookFactory::new()),
'user' => lazy(static fn () => UserFactory::new()),
'book' => lazy(static fn () => BookFactory::new()),
'publishedAt' => \DateTimeImmutable::createFromMutable(self::faker()->dateTime('-1 week')),
'body' => self::faker()->text(),
'rating' => self::faker()->numberBetween(0, 5),
Expand All @@ -76,9 +76,8 @@ protected function getDefaults(): array
*/
protected function initialize(): self
{
return $this
// ->afterInstantiate(function(Review $review): void {})
;
return $this;
// ->afterInstantiate(function(Review $review): void {})
}

protected static function getClass(): string
Expand Down
9 changes: 4 additions & 5 deletions api/src/DataFixtures/Factory/UserFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@ public function __construct()
parent::__construct();
}

public static function createOneAdmin(array $attributes = []): User|Proxy
public static function createOneAdmin(array $attributes = []): Proxy|User
{
return static::createOne(['roles' => ['ROLE_ADMIN']] + $attributes);
return self::createOne(['roles' => ['ROLE_ADMIN']] + $attributes);
}

/**
Expand All @@ -80,9 +80,8 @@ protected function getDefaults(): array
*/
protected function initialize(): self
{
return $this
// ->afterInstantiate(function(User $user): void {})
;
return $this;
// ->afterInstantiate(function(User $user): void {})
}

protected static function getClass(): string
Expand Down
6 changes: 2 additions & 4 deletions api/src/DataFixtures/Story/DefaultStory.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@

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

public function build(): void
{
Expand All @@ -36,7 +34,7 @@ public function build(): void

// Import books
$books = []; // store books in array to pick 30 random ones later without the default one
$data = $this->decoder->decode(file_get_contents(__DIR__.'/../books.json'), 'json');
$data = $this->decoder->decode(file_get_contents(__DIR__ . '/../books.json'), 'json');
foreach ($data as $datum) {
$book = BookFactory::createOne($datum + [
'condition' => BookCondition::cases()[array_rand(BookCondition::cases())],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@
*/
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
{
Expand All @@ -32,6 +30,7 @@ public function applyToCollection(QueryBuilder $queryBuilder, QueryNameGenerator

$queryBuilder
->andWhere(sprintf('%s.user = :user', $queryBuilder->getRootAliases()[0]))
->setParameter('user', $user);
->setParameter('user', $user)
;
}
}
8 changes: 4 additions & 4 deletions api/src/Doctrine/Orm/Filter/NameFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,11 @@ protected function filterProperty(string $property, $value, QueryBuilder $queryB
$alias = $queryBuilder->getRootAliases()[0];
$expressions = [];
foreach ($values as $key => $value) {
$parameterName = $queryNameGenerator->generateParameterName("name$key");
$queryBuilder->setParameter($parameterName, "%$value%");
$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 Down
6 changes: 3 additions & 3 deletions api/src/Entity/Book.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
AbstractNormalizer::GROUPS => ['Book:write'],
],
// todo waiting for https://github.com/api-platform/core/pull/5844
// collectDenormalizationErrors: true,
// collectDenormalizationErrors: true,
security: 'is_granted("ROLE_ADMIN")'
)]
#[ApiResource(
Expand Down Expand Up @@ -119,7 +119,7 @@ class Book
* @see https://schema.org/name
*/
#[ApiFilter(OrderFilter::class)]
#[ApiFilter(SearchFilter::class, strategy: 'i'.SearchFilterInterface::STRATEGY_PARTIAL)]
#[ApiFilter(SearchFilter::class, strategy: 'i' . SearchFilterInterface::STRATEGY_PARTIAL)]
#[ApiProperty(
types: ['https://schema.org/name'],
example: 'Hyperion'
Expand All @@ -131,7 +131,7 @@ class Book
/**
* @see https://schema.org/author
*/
#[ApiFilter(SearchFilter::class, strategy: 'i'.SearchFilterInterface::STRATEGY_PARTIAL)]
#[ApiFilter(SearchFilter::class, strategy: 'i' . SearchFilterInterface::STRATEGY_PARTIAL)]
#[ApiProperty(
types: ['https://schema.org/author'],
example: 'Dan Simmons'
Expand Down
2 changes: 1 addition & 1 deletion api/src/Entity/Bookmark.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
AbstractNormalizer::GROUPS => ['Bookmark:write'],
],
// todo waiting for https://github.com/api-platform/core/pull/5844
// collectDenormalizationErrors: true,
// collectDenormalizationErrors: true,
mercure: true,
security: 'is_granted("ROLE_USER")'
)]
Expand Down
4 changes: 2 additions & 2 deletions api/src/Entity/Review.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
AbstractNormalizer::GROUPS => ['Review:write', 'Review:write:admin'],
],
// todo waiting for https://github.com/api-platform/core/pull/5844
// collectDenormalizationErrors: true,
// collectDenormalizationErrors: true,
security: 'is_granted("ROLE_ADMIN")'
)]
#[ApiResource(
Expand Down Expand Up @@ -139,7 +139,7 @@
AbstractNormalizer::GROUPS => ['Review:write'],
],
// todo waiting for https://github.com/api-platform/core/pull/5844
// collectDenormalizationErrors: true
// collectDenormalizationErrors: true
)]
#[ORM\Entity(repositoryClass: ReviewRepository::class)]
#[ORM\UniqueConstraint(fields: ['user', 'book'])]
Expand Down
4 changes: 1 addition & 3 deletions api/src/Entity/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,7 @@ public function getId(): ?Uuid
return $this->id;
}

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

/**
* @return array<int, string>
Expand Down
4 changes: 2 additions & 2 deletions api/src/Enum/BookCondition.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
shortName: 'BookCondition',
types: ['https://schema.org/OfferItemCondition'],
operations: [
new GetCollection(provider: BookCondition::class.'::getCases'),
new Get(provider: BookCondition::class.'::getCase'),
new GetCollection(provider: BookCondition::class . '::getCases'),
new Get(provider: BookCondition::class . '::getCase'),
],
)]
enum BookCondition: string
Expand Down
2 changes: 2 additions & 0 deletions api/src/Kernel.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace App;

use Symfony\Bundle\FrameworkBundle\Kernel\MicroKernelTrait;
Expand Down
Loading

0 comments on commit 4f91b6a

Please sign in to comment.