[PHP-CS-Fixer] 👉 PHP 8.0 migration

This commit is contained in:
theUniC
2021-09-14 19:37:18 +02:00
parent ba0736cb9d
commit cc76cb88dd
71 changed files with 164 additions and 186 deletions

View File

@@ -1,27 +1,7 @@
<?php
use App\Kernel;
use Symfony\Component\ErrorHandler\Debug;
use Symfony\Component\HttpFoundation\Request;
require dirname(__DIR__).'/config/bootstrap.php';
require_once dirname(__DIR__).'/vendor/autoload_runtime.php';
if ($_SERVER['APP_DEBUG']) {
umask(0000);
Debug::enable();
}
if ($trustedProxies = $_SERVER['TRUSTED_PROXIES'] ?? $_ENV['TRUSTED_PROXIES'] ?? false) {
Request::setTrustedProxies(explode(',', $trustedProxies), Request::HEADER_X_FORWARDED_ALL ^ Request::HEADER_X_FORWARDED_HOST);
}
if ($trustedHosts = $_SERVER['TRUSTED_HOSTS'] ?? $_ENV['TRUSTED_HOSTS'] ?? false) {
Request::setTrustedHosts([$trustedHosts]);
}
$kernel = new Kernel($_SERVER['APP_ENV'], (bool) $_SERVER['APP_DEBUG']);
$request = Request::createFromGlobals();
$response = $kernel->handle($request);
$response->send();
$kernel->terminate($request, $response);
return static fn(array $context) => new Kernel($context['APP_ENV'], (bool) $context['APP_DEBUG']);

View File

@@ -34,7 +34,7 @@ final class CheepDataPersister implements ContextAwareDataPersisterInterface
PostCheep::fromArray([
'author_id' => $data->authorId,
'cheep_id' => $id->toString(),
'message' => $data->message
'message' => $data->message,
])
);
@@ -43,7 +43,7 @@ final class CheepDataPersister implements ContextAwareDataPersisterInterface
return $data;
}
public function remove(mixed $data, array $context = [])
public function remove(mixed $data, array $context = []): void
{
// TODO: Implement remove() method.
}

View File

@@ -1,4 +1,4 @@
<?php
<?php declare(strict_types=1);
namespace App\Command;
@@ -21,7 +21,7 @@ final class FollowCommand extends Command
parent::__construct($name);
}
protected function configure()
protected function configure(): void
{
$this
->setDescription('Make an author follow another author')

View File

@@ -1,4 +1,4 @@
<?php
<?php declare(strict_types=1);
namespace App\Command;

View File

@@ -1,4 +1,4 @@
<?php
<?php declare(strict_types=1);
namespace App\Command;

View File

@@ -1,4 +1,4 @@
<?php
<?php declare(strict_types=1);
namespace App\Command;

View File

@@ -14,7 +14,7 @@ final class DefaultController extends AbstractController
public function __invoke(): Response
{
return $this->render('spa.html.twig', [
'entrypoint' => 'app'
'entrypoint' => 'app',
]);
}
}

View File

@@ -1,4 +1,4 @@
<?php
<?php declare(strict_types=1);
namespace App\DataFixtures;

View File

@@ -1,4 +1,4 @@
<?php
<?php declare(strict_types=1);
namespace App\DataFixtures;
@@ -13,7 +13,7 @@ use Doctrine\Persistence\ObjectManager;
class AuthorsFixtures extends Fixture
{
public function load(ObjectManager $manager)
public function load(ObjectManager $manager): void
{
$carlos = Author::signUp(
authorId: AuthorId::fromString('69e08972-80d4-4769-b6db-48abfdd857cf'),

View File

@@ -1,4 +1,4 @@
<?php
<?php declare(strict_types=1);
namespace App;

View File

@@ -1,4 +1,4 @@
<?php
<?php declare(strict_types=1);
namespace Architecture\CQRS\Domain;

View File

@@ -1,4 +1,4 @@
<?php
<?php declare(strict_types=1);
namespace Architecture\CQRS\Domain;

View File

@@ -1,4 +1,4 @@
<?php
<?php declare(strict_types=1);
namespace Architecture\CQRS\Domain;

View File

@@ -1,4 +1,4 @@
<?php
<?php declare(strict_types=1);
namespace Architecture\CQRS\Domain;
@@ -28,7 +28,7 @@ class DomainEventPublisher
public function ofId(int $id): ?Subscriber
{
return isset($this->subscribers[$id]) ? $this->subscribers[$id] : null;
return $this->subscribers[$id] ?? null;
}
public function unsubscribe(int $id): void

View File

@@ -1,4 +1,4 @@
<?php
<?php declare(strict_types=1);
namespace Architecture\CQRS\Domain;

View File

@@ -1,4 +1,4 @@
<?php
<?php declare(strict_types=1);
namespace Architecture\CQRS\Domain;

View File

@@ -1,4 +1,4 @@
<?php
<?php declare(strict_types=1);
namespace Architecture\CQRS\Domain;

View File

@@ -1,4 +1,4 @@
<?php
<?php declare(strict_types=1);
namespace Architecture\CQRS\Domain;

View File

@@ -1,4 +1,4 @@
<?php
<?php declare(strict_types=1);
namespace Architecture\CQRS\Domain;

View File

@@ -1,4 +1,4 @@
<?php
<?php declare(strict_types=1);
namespace Architecture\CQRS\Domain;

View File

@@ -1,4 +1,4 @@
<?php
<?php declare(strict_types=1);
namespace Architecture\CQRS\Domain;

View File

@@ -1,4 +1,4 @@
<?php
<?php declare(strict_types=1);
namespace Architecture\CQRS\Domain;

View File

@@ -1,4 +1,4 @@
<?php
<?php declare(strict_types=1);
namespace Architecture\CQRS\Domain;

View File

@@ -1,4 +1,4 @@
<?php
<?php declare(strict_types=1);
namespace Architecture\CQRS\Domain;

View File

@@ -1,4 +1,4 @@
<?php
<?php declare(strict_types=1);
namespace Architecture\CQRS\Example;

View File

@@ -1,4 +1,4 @@
<?php
<?php declare(strict_types=1);
namespace Architecture\CQRS\Infrastructure\Persistence\Doctrine;

View File

@@ -1,4 +1,4 @@
<?php
<?php declare(strict_types=1);
namespace Architecture\CQRS\Infrastructure\Persistence\Doctrine\Types;

View File

@@ -1,4 +1,4 @@
<?php
<?php declare(strict_types=1);
namespace Architecture\CQRS\Infrastructure\Projection;

View File

@@ -1,4 +1,4 @@
<?php
<?php declare(strict_types=1);
namespace Architecture\CQRS\Infrastructure\Projection\Elasticsearch;
@@ -32,8 +32,8 @@ class PostContentWasChangedProjection implements Projection
'type' => 'post',
'id' => $id,
'body' => ['doc' => [
'content' => $event->content()
]]
'content' => $event->content(),
]],
]);
}
}

View File

@@ -1,4 +1,4 @@
<?php
<?php declare(strict_types=1);
namespace Architecture\CQRS\Infrastructure\Projection\Elasticsearch;
@@ -32,8 +32,8 @@ class PostTitleWasChangedProjection implements Projection
'type' => 'post',
'id' => $id,
'body' => ['doc' => [
'title' => $event->title()
]]
'title' => $event->title(),
]],
]);
}
}

View File

@@ -1,4 +1,4 @@
<?php
<?php declare(strict_types=1);
namespace Architecture\CQRS\Infrastructure\Projection\Elasticsearch;
@@ -32,8 +32,8 @@ class PostWasCategorizedProjection implements Projection
'type' => 'post',
'id' => $id,
'body' => ['doc' => [
'category_id' => $event->categoryId()->id()
]]
'category_id' => $event->categoryId()->id(),
]],
]);
}
}

View File

@@ -1,4 +1,4 @@
<?php
<?php declare(strict_types=1);
namespace Architecture\CQRS\Infrastructure\Projection\Elasticsearch;
@@ -34,8 +34,8 @@ class PostWasCreatedProjection implements Projection
'id' => $id,
'body' => [
'title' => $event->title(),
'content' => $event->content()
]
'content' => $event->content(),
],
]);
}
}

View File

@@ -1,4 +1,4 @@
<?php
<?php declare(strict_types=1);
namespace Architecture\CQRS\Infrastructure\Projection\Elasticsearch;
@@ -32,8 +32,8 @@ class PostWasPublishedProjection implements Projection
'type' => 'post',
'id' => $id,
'body' => ['doc' => [
'is_published' => true
]]
'is_published' => true,
]],
]);
}
}

View File

@@ -1,4 +1,4 @@
<?php
<?php declare(strict_types=1);
namespace Architecture\CQRS\Infrastructure\Projection;

View File

@@ -1,4 +1,4 @@
<?php
<?php declare(strict_types=1);
namespace Architecture\CQRS\Presentation;
@@ -15,13 +15,13 @@ class PostController
'type' => 'post',
'body' => [
'sort' => [
'created_at' => ['order' => 'desc']
]
]
'created_at' => ['order' => 'desc'],
],
],
]);
return [
'posts' => $response
'posts' => $response,
];
}
}

View File

@@ -1,4 +1,4 @@
<?php
<?php declare(strict_types=1);
namespace Architecture\ES\Domain;

View File

@@ -1,4 +1,4 @@
<?php
<?php declare(strict_types=1);
namespace Architecture\ES\Domain;

View File

@@ -1,4 +1,4 @@
<?php
<?php declare(strict_types=1);
namespace Architecture\ES\Domain;

View File

@@ -1,4 +1,4 @@
<?php
<?php declare(strict_types=1);
namespace Architecture\ES\Domain;

View File

@@ -1,4 +1,4 @@
<?php
<?php declare(strict_types=1);
namespace Architecture\ES\Infrastructure;
@@ -41,8 +41,8 @@ class EventStore
$this->serializer->serialize([
'type' => get_class($event),
'created_on' => $date,
'data' => $data
])
'data' => $data,
]),
]
);
}

View File

@@ -1,4 +1,4 @@
<?php
<?php declare(strict_types=1);
namespace Architecture\ES\Infrastructure;

View File

@@ -1,4 +1,4 @@
<?php
<?php declare(strict_types=1);
namespace Architecture\ES\Infrastructure;
@@ -66,8 +66,8 @@ class SnapshotRepository
'type' => get_class($aggregate),
'data' => $this->serializer->serialize(
$aggregate
)
]
),
],
]
)
);

View File

@@ -1,4 +1,4 @@
<?php
<?php declare(strict_types=1);
namespace Architecture\ES\Infrastructure\V0;

View File

@@ -1,4 +1,4 @@
<?php
<?php declare(strict_types=1);
namespace Architecture\ES\Infrastructure\V1;

View File

@@ -21,7 +21,7 @@ final class SymfonyAuthorFollowedHandler implements MessageSubscriberInterface
{
yield AuthorFollowed::class => [
'bus' => 'event.bus',
'method' => 'handlerAuthorFollowed'
'method' => 'handlerAuthorFollowed',
];
}

View File

@@ -21,7 +21,7 @@ final class SymfonyAuthorUnfollowedHandler implements MessageSubscriberInterface
{
yield AuthorUnfollowed::class => [
'bus' => 'event.bus',
'method' => 'handleAuthorUnfollowed'
'method' => 'handleAuthorUnfollowed',
];
}

View File

@@ -27,7 +27,7 @@ final class SymfonyCountFollowerProjector implements MessageSubscriberInterface
yield AuthorFollowed::class => [
'bus' => 'event.bus',
'method' => 'handleAuthorFollowed'
'method' => 'handleAuthorFollowed',
];
// yield CountFollowers::class => [

View File

@@ -27,7 +27,7 @@ final class DoctrineOrmAuthors implements Authors
$author = $this->em
->getRepository(Author::class)
->findOneBy([
'authorId.id' => Uuid::fromString($authorId->id())
'authorId.id' => Uuid::fromString($authorId->id()),
]);
if (null === $author) {

View File

@@ -36,7 +36,7 @@ final class DoctrineOrmFollows implements Follows
{
return $this->repository->findOneBy([
'fromAuthorId.id' => $fromAuthorId,
'toAuthorId.id' => $toAuthorId
'toAuthorId.id' => $toAuthorId,
]);
}
}

View File

@@ -55,7 +55,7 @@ final class PostCheepController extends AbstractController
try {
$logger->info('Executing SignUp command');
$entityManager->transactional(function () use ($command, $postCheepHandler, $logger) {
$entityManager->transactional(function () use ($command, $postCheepHandler, $logger): void {
($postCheepHandler)($command);
$logger->info('SignUp command executed successfully');
});

View File

@@ -20,9 +20,7 @@ final class DoctrineTransactionalMiddleware implements MiddlewareInterface
public function handle(Envelope $envelope, StackInterface $stack): Envelope
{
/** @var Envelope $result */
$result = $this->em->transactional(static function () use ($envelope, $stack): Envelope {
return $stack->next()->handle($envelope, $stack);
});
$result = $this->em->transactional(static fn (): Envelope => $stack->next()->handle($envelope, $stack));
return $result;
}

View File

@@ -29,15 +29,15 @@ $postCheepHandler = new PostCheepHandler(
$bus = new MessageBus([
new HandleMessageMiddleware(new HandlersLocator([
PostCheep::class => [$postCheepHandler]
]))
PostCheep::class => [$postCheepHandler],
])),
]);
$bus->dispatch(
PostCheep::fromArray([
'author_id' => '527cab4c-30a8-4d6a-bf7a-157910d569e5',
'cheep_id' => '719ac125-83a9-4d6e-94da-493891b8f8b2',
'message' => 'New cheep!'
'message' => 'New cheep!',
])
);
//end-snippet

View File

@@ -35,15 +35,15 @@ $bus = new MessageBus([
new LoggerMiddleware($logger),
new DoctrineTransactionalMiddleware($entityManager),
new HandleMessageMiddleware(new HandlersLocator([
PostCheep::class => [$postCheepHandler]
]))
PostCheep::class => [$postCheepHandler],
])),
]);
$bus->dispatch(
PostCheep::fromArray([
'author_id' => '527cab4c-30a8-4d6a-bf7a-157910d569e5',
'cheep_id' => '719ac125-83a9-4d6e-94da-493891b8f8b2',
'message' => 'New cheep!'
'message' => 'New cheep!',
])
);
//end-snippet

View File

@@ -37,7 +37,7 @@ final class PostCheepController extends AbstractController
null,
0,
[
'Content-Type' => 'application/json'
'Content-Type' => 'application/json',
]
);
}

View File

@@ -1,4 +1,4 @@
<?php
<?php declare(strict_types=1);
namespace CheeperHexagonal;

View File

@@ -1,4 +1,4 @@
<?php
<?php declare(strict_types=1);
namespace CheeperHexagonal;

View File

@@ -1,4 +1,4 @@
<?php
<?php declare(strict_types=1);
namespace CheeperHexagonal;

View File

@@ -1,4 +1,4 @@
<?php
<?php declare(strict_types=1);
namespace CheeperHexagonal;

View File

@@ -1,4 +1,4 @@
<?php
<?php declare(strict_types=1);
namespace CheeperHexagonal;

View File

@@ -1,4 +1,4 @@
<?php
<?php declare(strict_types=1);
namespace CheeperHexagonal;

View File

@@ -1,4 +1,4 @@
<?php
<?php declare(strict_types=1);
namespace CheeperHexagonal;

View File

@@ -1,4 +1,4 @@
<?php
<?php declare(strict_types=1);
namespace CheeperLayered;

View File

@@ -1,4 +1,4 @@
<?php
<?php declare(strict_types=1);
namespace CheeperLayered;
@@ -16,7 +16,7 @@ class Authors
'user',
'pass',
[
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
]
);
}
@@ -60,14 +60,14 @@ class Authors
try {
$stmt = $this->db->prepare(<<<SQL
INSERT
INTO authors (id, username, website, bio)
VALUES (:id, :username, :website, :bio)
ON DUPLICATE KEY UPDATE
username = :username,
website = :website,
bio = :bio
SQL);
INSERT
INTO authors (id, username, website, bio)
VALUES (:id, :username, :website, :bio)
ON DUPLICATE KEY UPDATE
username = :username,
website = :website,
bio = :bio
SQL);
$stmt->execute([
'id' => $author->id(),

View File

@@ -1,4 +1,4 @@
<?php
<?php declare(strict_types=1);
namespace CheeperLayered;

View File

@@ -1,4 +1,4 @@
<?php
<?php declare(strict_types=1);
namespace CheeperLayered;

View File

@@ -1,4 +1,4 @@
<?php
<?php declare(strict_types=1);
namespace CheeperLayered;

View File

@@ -1,4 +1,4 @@
<?php
<?php declare(strict_types=1);
namespace CheeperLayered;
@@ -17,7 +17,7 @@ class Cheeps
'user',
'pass',
[
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
]
);
}
@@ -35,7 +35,7 @@ class Cheeps
$stmt->execute([
$cheep->authorId(),
$cheep->message(),
$cheep->date()->format('Y-m-d H:i:s')
$cheep->date()->format('Y-m-d H:i:s'),
]);
$cheep->setId((int) $this->db->lastInsertId());
@@ -53,14 +53,14 @@ class Cheeps
public function timelineOf(int $authorId): array
{
$sql = <<<SQL
SELECT
username, cheeps.id, message, date
FROM cheeps
JOIN authors ON cheeps.author_id = authors.id
LEFT JOIN follows ON follows.followee_id = authors.id
WHERE author_id = :author_id OR follows.followee_id = authors.id
ORDER BY date DESC
SQL;
SELECT
username, cheeps.id, message, date
FROM cheeps
JOIN authors ON cheeps.author_id = authors.id
LEFT JOIN follows ON follows.followee_id = authors.id
WHERE author_id = :author_id OR follows.followee_id = authors.id
ORDER BY date DESC
SQL;
$stmt = $this->db->prepare($sql);
$stmt->execute(['author_id' => $authorId]);
@@ -72,7 +72,7 @@ class Cheeps
'username' => $row['username'],
'id' => $row['id'],
'message' => $row['message'],
'date' => self::toDate((string) $row['date'])
'date' => self::toDate((string) $row['date']),
]);
}

View File

@@ -38,7 +38,7 @@ final class DelayedPostCheepController extends AbstractController
$command = PostCheep::fromArray([
'author_id' => $authorId,
'cheep_id' => $cheepId,
'message' => $message
'message' => $message,
]);
$queuedCommand = new QueuedCommand($command);

View File

@@ -1,4 +1,4 @@
<?php
<?php declare(strict_types=1);
/**
* The only purpose of this file is to make the spaghetti example work
@@ -15,48 +15,48 @@ if (!$link) {
mysqli_select_db($link, 'db');
$sql = <<<SQL
DROP TABLE IF EXISTS cheeps;
DROP TABLE IF EXISTS follows;
DROP TABLE IF EXISTS authors;
-- snippet cheeper-schema
CREATE TABLE authors (
id INT(11) UNSIGNED NOT NULL AUTO_INCREMENT,
username VARCHAR(100) NOT NULL UNIQUE,
website VARCHAR(255) NULL,
bio VARCHAR(255) NULL,
PRIMARY KEY (id)
);
DROP TABLE IF EXISTS cheeps;
DROP TABLE IF EXISTS follows;
DROP TABLE IF EXISTS authors;
-- snippet cheeper-schema
CREATE TABLE authors (
id INT(11) UNSIGNED NOT NULL AUTO_INCREMENT,
username VARCHAR(100) NOT NULL UNIQUE,
website VARCHAR(255) NULL,
bio VARCHAR(255) NULL,
PRIMARY KEY (id)
);
CREATE TABLE follows (
followee_id INT(11) UNSIGNED NOT NULL,
follower_id INT(11) UNSIGNED NOT NULL,
FOREIGN KEY (followee_id) REFERENCES authors(id) ON DELETE CASCADE,
FOREIGN KEY (follower_id) REFERENCES authors(id) ON DELETE CASCADE,
PRIMARY KEY (followee_id, follower_id)
);
CREATE TABLE follows (
followee_id INT(11) UNSIGNED NOT NULL,
follower_id INT(11) UNSIGNED NOT NULL,
FOREIGN KEY (followee_id) REFERENCES authors(id) ON DELETE CASCADE,
FOREIGN KEY (follower_id) REFERENCES authors(id) ON DELETE CASCADE,
PRIMARY KEY (followee_id, follower_id)
);
CREATE TABLE cheeps (
id INT(11) UNSIGNED NOT NULL AUTO_INCREMENT,
author_id INT(11) UNSIGNED NOT NULL,
message VARCHAR(240) NOT NULL,
date DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (author_id) REFERENCES authors(id) ON DELETE CASCADE,
PRIMARY KEY (id)
);
-- end-snippet
INSERT INTO authors (id, username) VALUES
(1, 'johndoe'),
(2, 'rosemary');
CREATE TABLE cheeps (
id INT(11) UNSIGNED NOT NULL AUTO_INCREMENT,
author_id INT(11) UNSIGNED NOT NULL,
message VARCHAR(240) NOT NULL,
date DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (author_id) REFERENCES authors(id) ON DELETE CASCADE,
PRIMARY KEY (id)
);
-- end-snippet
INSERT INTO authors (id, username) VALUES
(1, 'johndoe'),
(2, 'rosemary');
INSERT INTO follows (followee_id, follower_id) VALUES
(1, 2);
INSERT INTO follows (followee_id, follower_id) VALUES
(1, 2);
INSERT INTO cheeps (author_id, message, date) VALUES
(1, "Hello, I'm John!", "2020-05-26 00:21:32"),
(2, "Hello, I'm Rose!", "2020-05-26 00:18:29");
SQL;
INSERT INTO cheeps (author_id, message, date) VALUES
(1, "Hello, I'm John!", "2020-05-26 00:21:32"),
(2, "Hello, I'm Rose!", "2020-05-26 00:18:29");
SQL;
$result = mysqli_multi_query($link, $sql);
if (!$result) {

View File

@@ -1,4 +1,4 @@
<?php
<?php declare(strict_types=1);
/*
* Execute first init.php

View File

@@ -1,4 +1,4 @@
<?php
<?php declare(strict_types=1);
/*
* Execute first init.php
@@ -24,14 +24,14 @@ if (!$timeline_username = htmlspecialchars($_GET['username'])) {
}
$timeline_query = mysqli_query($link, sprintf(<<<SQL
SELECT
username, message, date
FROM cheeps
JOIN authors ON cheeps.author_id = authors.id
LEFT JOIN follows ON follows.followee_id = authors.id
WHERE username = '%s' OR follows.followee_id = authors.id
ORDER BY date DESC
SQL, mysqli_real_escape_string($link, $timeline_username)));
SELECT
username, message, date
FROM cheeps
JOIN authors ON cheeps.author_id = authors.id
LEFT JOIN follows ON follows.followee_id = authors.id
WHERE username = '%s' OR follows.followee_id = authors.id
ORDER BY date DESC
SQL, mysqli_real_escape_string($link, $timeline_username)));
?>
<html>