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

refactor: apply PHP 8.3 features #372

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
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
2 changes: 1 addition & 1 deletion apps/backoffice/backend/public/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

if ($trustedProxies = $_SERVER['TRUSTED_PROXIES'] ?? $_ENV['TRUSTED_PROXIES'] ?? false) {
Request::setTrustedProxies(
explode(',', $trustedProxies),
explode(',', (string) $trustedProxies),

Check failure on line 19 in apps/backoffice/backend/public/index.php

View workflow job for this annotation

GitHub Actions / build

RedundantCast

apps/backoffice/backend/public/index.php:19:16: RedundantCast: Redundant cast to string (see https://psalm.dev/262)
Request::HEADER_X_FORWARDED_FOR | Request::HEADER_X_FORWARDED_PORT | Request::HEADER_X_FORWARDED_PROTO
);
}
Expand Down
7 changes: 5 additions & 2 deletions apps/backoffice/backend/src/BackofficeBackendKernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,22 @@

namespace CodelyTv\Apps\Backoffice\Backend;

use Override;
use Symfony\Bundle\FrameworkBundle\Kernel\MicroKernelTrait;
use Symfony\Component\Config\Loader\LoaderInterface;
use Symfony\Component\Config\Resource\FileResource;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\HttpKernel\Kernel;

use Symfony\Component\HttpKernel\Kernel;
use function dirname;

class BackofficeBackendKernel extends Kernel
{
use MicroKernelTrait;

private const CONFIG_EXTS = '.{xml,yaml}';
private const string CONFIG_EXTS = '.{xml,yaml}';

#[Override]
public function registerBundles(): iterable
{
$contents = require $this->getProjectDir() . '/config/bundles.php';
Expand All @@ -28,6 +30,7 @@ public function registerBundles(): iterable
}
}

#[Override]
public function getProjectDir(): string
{
return dirname(__DIR__);
Expand Down
2 changes: 1 addition & 1 deletion apps/backoffice/frontend/public/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

if ($trustedProxies = $_SERVER['TRUSTED_PROXIES'] ?? $_ENV['TRUSTED_PROXIES'] ?? false) {
Request::setTrustedProxies(
explode(',', $trustedProxies),
explode(',', (string) $trustedProxies),

Check failure on line 19 in apps/backoffice/frontend/public/index.php

View workflow job for this annotation

GitHub Actions / build

RedundantCast

apps/backoffice/frontend/public/index.php:19:16: RedundantCast: Redundant cast to string (see https://psalm.dev/262)
Request::HEADER_X_FORWARDED_FOR | Request::HEADER_X_FORWARDED_PORT | Request::HEADER_X_FORWARDED_PROTO
);
}
Expand Down
7 changes: 5 additions & 2 deletions apps/backoffice/frontend/src/BackofficeFrontendKernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,22 @@

namespace CodelyTv\Apps\Backoffice\Frontend;

use Override;
use Symfony\Bundle\FrameworkBundle\Kernel\MicroKernelTrait;
use Symfony\Component\Config\Loader\LoaderInterface;
use Symfony\Component\Config\Resource\FileResource;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\HttpKernel\Kernel;

use Symfony\Component\HttpKernel\Kernel;
use function dirname;

class BackofficeFrontendKernel extends Kernel
{
use MicroKernelTrait;

private const CONFIG_EXTS = '.{xml,yaml}';
private const string CONFIG_EXTS = '.{xml,yaml}';

#[Override]
public function registerBundles(): iterable
{
$contents = require $this->getProjectDir() . '/config/bundles.php';
Expand All @@ -28,6 +30,7 @@ public function registerBundles(): iterable
}
}

#[Override]
public function getProjectDir(): string
{
return dirname(__DIR__);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use CodelyTv\Backoffice\Courses\Infrastructure\Persistence\ElasticsearchBackofficeCourseRepository;
use CodelyTv\Backoffice\Courses\Infrastructure\Persistence\MySqlBackofficeCourseRepository;
use Override;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
Expand All @@ -19,6 +20,7 @@ public function __construct(
parent::__construct();
}

#[Override]
public function execute(InputInterface $input, OutputInterface $output): int
{
$courses = $this->mySqlRepository->searchAll();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use CodelyTv\Mooc\CoursesCounter\Application\Find\FindCoursesCounterQuery;
use CodelyTv\Shared\Domain\ValueObject\SimpleUuid;
use CodelyTv\Shared\Infrastructure\Symfony\WebController;
use Override;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;

Expand All @@ -29,6 +30,7 @@ public function __invoke(Request $request): Response
);
}

#[Override]
protected function exceptions(): array
{
return [];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use CodelyTv\Mooc\Courses\Application\Create\CreateCourseCommand;
use CodelyTv\Shared\Infrastructure\Symfony\WebController;
use Override;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Validator\Constraints as Assert;
Expand All @@ -23,6 +24,7 @@ public function __invoke(Request $request): RedirectResponse
: $this->createCourse($request);
}

#[Override]
protected function exceptions(): array
{
return [];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace CodelyTv\Apps\Backoffice\Frontend\Controller\Home;

use CodelyTv\Shared\Infrastructure\Symfony\WebController;
use Override;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;

Expand All @@ -18,6 +19,7 @@ public function __invoke(Request $request): Response
]);
}

#[Override]
protected function exceptions(): array
{
return [];
Expand Down
2 changes: 1 addition & 1 deletion apps/mooc/backend/public/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

if ($trustedProxies = $_SERVER['TRUSTED_PROXIES'] ?? $_ENV['TRUSTED_PROXIES'] ?? false) {
Request::setTrustedProxies(
explode(',', $trustedProxies),
explode(',', (string) $trustedProxies),

Check failure on line 19 in apps/mooc/backend/public/index.php

View workflow job for this annotation

GitHub Actions / build

RedundantCast

apps/mooc/backend/public/index.php:19:16: RedundantCast: Redundant cast to string (see https://psalm.dev/262)
Request::HEADER_X_FORWARDED_FOR | Request::HEADER_X_FORWARDED_PORT | Request::HEADER_X_FORWARDED_PROTO
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,13 @@
use CodelyTv\Shared\Infrastructure\Bus\Event\DomainEventSubscriberLocator;
use CodelyTv\Shared\Infrastructure\Bus\Event\MySql\MySqlDoctrineDomainEventsConsumer;
use CodelyTv\Shared\Infrastructure\Doctrine\DatabaseConnections;
use Override;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

use Symfony\Component\Console\Output\OutputInterface;
use function Lambdish\Phunctional\pipe;

#[AsCommand(name: 'codely:domain-events:mysql:consume', description: 'Consume domain events from MySql',)]
Expand All @@ -27,11 +28,13 @@ public function __construct(
parent::__construct();
}

#[Override]
protected function configure(): void
{
$this->addArgument('quantity', InputArgument::REQUIRED, 'Quantity of events to process');
}

#[Override]
protected function execute(InputInterface $input, OutputInterface $output): int
{
$quantityEventsToProcess = (int) $input->getArgument('quantity');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use CodelyTv\Shared\Infrastructure\Cdc\DatabaseMutationAction;
use CodelyTv\Shared\Infrastructure\Cdc\DatabaseMutationToDomainEvent;
use Doctrine\ORM\EntityManager;
use Override;
use RuntimeException;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
Expand Down Expand Up @@ -39,16 +40,18 @@
];
}

#[Override]
protected function configure(): void
{
$this->addArgument('quantity', InputArgument::REQUIRED, 'Quantity of mutations to process');
}

#[Override]
protected function execute(InputInterface $input, OutputInterface $output): int
{
$totalMutations = (int) $input->getArgument('quantity');

$this->entityManager->wrapInTransaction(function (EntityManager $entityManager) use ($totalMutations) {
$this->entityManager->wrapInTransaction(function (EntityManager $entityManager) use ($totalMutations): void {
$mutations = $entityManager->getConnection()
->executeQuery("SELECT * FROM mutations ORDER BY id ASC LIMIT $totalMutations FOR UPDATE")
->fetchAllAssociative();
Expand Down Expand Up @@ -78,7 +81,7 @@
{
if (!array_key_exists($tableName, $this->transformers) && array_key_exists(
$operation,
$this->transformers[$tableName]

Check failure on line 84 in apps/mooc/backend/src/Command/DomainEvents/PublishDomainEventsFromMutationsCommand.php

View workflow job for this annotation

GitHub Actions / build

PossiblyUndefinedArrayOffset

apps/mooc/backend/src/Command/DomainEvents/PublishDomainEventsFromMutationsCommand.php:84:4: PossiblyUndefinedArrayOffset: Possibly undefined array key $this->transformers[$tableName] on array<array-key, mixed> (see https://psalm.dev/167)
)) {
throw new RuntimeException("Transformer not found for table $tableName and operation $operation");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace CodelyTv\Apps\Mooc\Backend\Command\DomainEvents\RabbitMq;

use CodelyTv\Shared\Infrastructure\Bus\Event\RabbitMq\RabbitMqConfigurer;
use Override;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
Expand All @@ -25,6 +26,7 @@ public function __construct(
parent::__construct();
}

#[Override]
protected function execute(InputInterface $input, OutputInterface $output): int
{
$this->configurer->configure($this->exchangeName, ...iterator_to_array($this->subscribers));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@
use CodelyTv\Shared\Infrastructure\Bus\Event\DomainEventSubscriberLocator;
use CodelyTv\Shared\Infrastructure\Bus\Event\RabbitMq\RabbitMqDomainEventsConsumer;
use CodelyTv\Shared\Infrastructure\Doctrine\DatabaseConnections;
use Override;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

use Symfony\Component\Console\Output\OutputInterface;
use function Lambdish\Phunctional\repeat;

#[AsCommand(
Expand All @@ -29,13 +30,15 @@ public function __construct(
parent::__construct();
}

#[Override]
protected function configure(): void
{
$this
->addArgument('queue', InputArgument::REQUIRED, 'Queue name')
->addArgument('quantity', InputArgument::REQUIRED, 'Quantity of events to process');
}

#[Override]
protected function execute(InputInterface $input, OutputInterface $output): int
{
$queueName = $input->getArgument('queue');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@
use CodelyTv\Shared\Domain\Bus\Event\DomainEventSubscriber;
use CodelyTv\Shared\Infrastructure\Bus\Event\DomainEventSubscriberLocator;
use CodelyTv\Shared\Infrastructure\Bus\Event\RabbitMq\RabbitMqQueueNameFormatter;
use Override;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

use Symfony\Component\Console\Output\OutputInterface;
use function Lambdish\Phunctional\each;

#[AsCommand(
Expand All @@ -21,20 +22,22 @@
)]
final class GenerateSupervisorRabbitMqConsumerFilesCommand extends Command
{
private const EVENTS_TO_PROCESS_AT_TIME = 200;
private const NUMBERS_OF_PROCESSES_PER_SUBSCRIBER = 1;
private const int EVENTS_TO_PROCESS_AT_TIME = 200;
private const int NUMBERS_OF_PROCESSES_PER_SUBSCRIBER = 1;
private const SUPERVISOR_PATH = __DIR__ . '/../../../../build/supervisor';

public function __construct(private readonly DomainEventSubscriberLocator $locator)
{
parent::__construct();
}

#[Override]
protected function configure(): void
{
$this->addArgument('command-path', InputArgument::OPTIONAL, 'Path on this is gonna be deployed', '/var/www');
}

#[Override]
protected function execute(InputInterface $input, OutputInterface $output): int
{
$path = $input->getArgument('command-path');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use CodelyTv\Mooc\Courses\Application\Create\CreateCourseCommand;
use CodelyTv\Shared\Infrastructure\Symfony\ApiController;
use Override;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;

Expand All @@ -24,6 +25,7 @@ public function __invoke(string $id, Request $request): Response
return new Response('', Response::HTTP_CREATED);
}

#[Override]
protected function exceptions(): array
{
return [];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use CodelyTv\Mooc\CoursesCounter\Application\Find\FindCoursesCounterQuery;
use CodelyTv\Mooc\CoursesCounter\Domain\CoursesCounterNotExist;
use CodelyTv\Shared\Infrastructure\Symfony\ApiController;
use Override;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Response;

Expand All @@ -25,6 +26,7 @@ public function __invoke(): JsonResponse
);
}

#[Override]
protected function exceptions(): array
{
return [
Expand Down
7 changes: 5 additions & 2 deletions apps/mooc/backend/src/MoocBackendKernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,22 @@

namespace CodelyTv\Apps\Mooc\Backend;

use Override;
use Symfony\Bundle\FrameworkBundle\Kernel\MicroKernelTrait;
use Symfony\Component\Config\Loader\LoaderInterface;
use Symfony\Component\Config\Resource\FileResource;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\HttpKernel\Kernel;

use Symfony\Component\HttpKernel\Kernel;
use function dirname;

class MoocBackendKernel extends Kernel
{
use MicroKernelTrait;

private const CONFIG_EXTS = '.{xml,yaml}';
private const string CONFIG_EXTS = '.{xml,yaml}';

#[Override]
public function registerBundles(): iterable
{
$contents = require $this->getProjectDir() . '/config/bundles.php';
Expand All @@ -28,6 +30,7 @@ public function registerBundles(): iterable
}
}

#[Override]
public function getProjectDir(): string
{
return dirname(__DIR__);
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,10 @@
"symfony/error-handler": "^6",

"symplify/easy-coding-standard": "^12.0",
"vimeo/psalm": "^5.15",
"vimeo/psalm": "^5.18",
"rector/rector": "^0.18.12",
"psalm/plugin-mockery": "^1.1",
"psalm/plugin-symfony": "^5.0",
"psalm/plugin-symfony": "^5.1",
"psalm/plugin-phpunit": "^0.18.4",
"phpstan/phpstan": "^1.10",
"phpat/phpat": "^0.10.10",
Expand Down
Loading
Loading