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

Enable Rector in CI and process the entire project #214

Merged
merged 20 commits into from
Jun 28, 2024
Merged
Show file tree
Hide file tree
Changes from 19 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 .github/workflows/docker-dev-image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: 'Get Previous tag'
id: previoustag
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/docker-image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: 'Get Previous tag'
id: previoustag
Expand Down Expand Up @@ -52,7 +52,7 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4

- name: 'Get Previous tag'
id: previoustag
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/phpunit-mysql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ jobs:
git config --global core.eol lf

- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Configure environment
run: |
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/phpunit-pgsql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ jobs:
git config --global core.eol lf

- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Configure environment
run: |
Expand Down
58 changes: 58 additions & 0 deletions .github/workflows/rector.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
on:
pull_request: null
workflow_call:
inputs:
extensions:
description: List of extensions to PHP.
default: sockets
required: false
type: string
push:
branches:
- '*.*'

name: Rector

jobs:
rector:
runs-on: ${{ matrix.os }}

strategy:
fail-fast: false
matrix:
php: [ '8.3' ]
os: [ 'ubuntu-latest' ]

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Configure environment
run: |
export COMPOSER_ROOT_VERSION=$(/usr/bin/jq --null-input --raw-output 'first(inputs["extra"]["branch-alias"])[]' composer.json)
echo COMPOSER_ROOT_VERSION=$COMPOSER_ROOT_VERSION >> $GITHUB_ENV

- name: Setup PHP ${{ matrix.php }}
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
# PHP Extras
coverage: ${{ matrix.coverage }}
tools: pecl

- name: Get Composer Cache Directory
id: composer-cache
run: echo "::set-output name=dir::$(composer config cache-files-dir)"

- name: Restore Composer Cache
uses: actions/cache@v4
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-${{ matrix.php }}-composer-${{ hashFiles('**/composer.json') }}
restore-keys: ${{ runner.os }}-${{ matrix.php }}-composer

- name: Install Dependencies
run: composer install --prefer-dist --no-interaction --no-progress

- name: Run Rector checks
run: vendor/bin/rector process --dry-run
12 changes: 6 additions & 6 deletions app/config/cycle.php
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
<?php

declare(strict_types=1);

use Cycle\ORM\Collection\ArrayCollectionFactory;
use Cycle\ORM\SchemaInterface;
use Cycle\ORM\Parser\Typecast;
use App\Application\Domain\Entity\ExtendedTypecast;
use Cycle\ORM\Collection\DoctrineCollectionFactory;
use Cycle\ORM\Collection\IlluminateCollectionFactory;

return [
'schema' => [
'cache' => env('CYCLE_SCHEMA_CACHE', true),
'defaults' => [
\Cycle\ORM\SchemaInterface::TYPECAST_HANDLER => [
\Cycle\ORM\Parser\Typecast::class,
\App\Application\Domain\Entity\ExtendedTypecast::class,
SchemaInterface::TYPECAST_HANDLER => [
Typecast::class,
ExtendedTypecast::class,
],
],
'collections' => [
Expand Down
19 changes: 12 additions & 7 deletions app/config/database.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@

declare(strict_types=1);

use Cycle\Database\Config;
use Cycle\Database\Config\PostgresDriverConfig;
use Cycle\Database\Config\Postgres\TcpConnectionConfig as PgTcpConnectionConfig;
use Cycle\Database\Config\MySQL\TcpConnectionConfig as MysqlTcpConnectionConfig;
use Cycle\Database\Config\MySQLDriverConfig;
use Cycle\Database\Config\SQLiteDriverConfig;
use Cycle\Database\Config\SQLite\FileConnectionConfig;

return [
'logger' => [
Expand All @@ -19,8 +24,8 @@
],

'drivers' => [
'pgsql' => new Config\PostgresDriverConfig(
connection: new Config\Postgres\TcpConnectionConfig(
'pgsql' => new PostgresDriverConfig(
connection: new PgTcpConnectionConfig(
database: env('DB_DATABASE', 'buggregator'),
host: env('DB_HOST', '127.0.0.1'),
port: env('DB_PORT', 5432),
Expand All @@ -34,8 +39,8 @@
'logQueryParameters' => env('DB_LOG_QUERY_PARAMETERS', false),
],
),
'mysql' => new Config\MySQLDriverConfig(
connection: new Config\MySQL\TcpConnectionConfig(
'mysql' => new MySQLDriverConfig(
connection: new MysqlTcpConnectionConfig(
database: env('DB_DATABASE', 'buggregator'),
host: env('DB_HOST', '127.0.0.1'),
port: env('DB_PORT', 3306),
Expand All @@ -51,8 +56,8 @@

// Only for testing purposes
// SQLite does not support multiple connections in the same time
'sqlite' => new Config\SQLiteDriverConfig(
connection: new Config\SQLite\FileConnectionConfig(database: directory('runtime') . 'test.db'),
'sqlite' => new SQLiteDriverConfig(
connection: new FileConnectionConfig(database: directory('runtime') . 'test.db'),
options: [
'logQueryParameters' => env('DB_LOG_QUERY_PARAMETERS', false),
],
Expand Down
7 changes: 5 additions & 2 deletions app/config/events.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@

declare(strict_types=1);

use Modules\Webhooks\Application\Broadcasting\WebhookEventInterceptor;
use App\Application\Broadcasting\BroadcastEventInterceptor;

return [
'interceptors' => [
\Modules\Webhooks\Application\Broadcasting\WebhookEventInterceptor::class,
\App\Application\Broadcasting\BroadcastEventInterceptor::class,
WebhookEventInterceptor::class,
BroadcastEventInterceptor::class,
]
];
4 changes: 3 additions & 1 deletion app/config/migration.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

declare(strict_types=1);

use Cycle\Schema\Generator\Migrations\Strategy\MultipleFilesStrategy;

return [
/**
* Directory to store migration files
Expand All @@ -13,7 +15,7 @@
*/
'table' => 'migrations',

'strategy' => \Cycle\Schema\Generator\Migrations\Strategy\MultipleFilesStrategy::class,
'strategy' => MultipleFilesStrategy::class,

/**
* When set to true no confirmation will be requested on migration run.
Expand Down
7 changes: 2 additions & 5 deletions app/config/monolog.php
Original file line number Diff line number Diff line change
@@ -1,18 +1,15 @@
<?php

declare(strict_types=1);

use Monolog\Handler\ErrorLogHandler;
use Monolog\Handler\SyslogHandler;
use Spiral\RoadRunnerBridge\Logger\Handler;
use Monolog\Logger;
use Monolog\Processor\PsrLogMessageProcessor;

return [
'default' => env('MONOLOG_DEFAULT_CHANNEL', 'roadrunner'),
'globalLevel' => Logger::toMonologLevel(env('MONOLOG_DEFAULT_LEVEL', Logger::DEBUG)),
'handlers' => [
'roadrunner' => [
\Spiral\RoadRunnerBridge\Logger\Handler::class,
Handler::class,
],
],
'processors' => [],
Expand Down
3 changes: 2 additions & 1 deletion app/database/Factory/AttachmentFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Database\Factory;

use Faker\Generator;
use App\Application\Domain\ValueObjects\Uuid;
use Modules\Events\Domain\Event;
use Modules\Smtp\Domain\Attachment;
Expand Down Expand Up @@ -57,7 +58,7 @@ public function forEvent(Uuid|Event $uuid): self
{
$uuid = $uuid instanceof Event ? $uuid->getUuid() : $uuid;

return $this->state(fn(\Faker\Generator $faker, array $definition) => [
return $this->state(fn(Generator $faker, array $definition) => [
'event_uuid' => $uuid,
]);
}
Expand Down
13 changes: 4 additions & 9 deletions app/modules/Events/Integration/CycleOrm/EventRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public function __construct(

public function store(Event $event): bool
{
if ($found = $this->findByPK($event->getUuid())) {
if (($found = $this->findByPK($event->getUuid())) !== null) {
$found->setPayload($event->getPayload());
$this->em->persist($found);
} else {
Expand All @@ -43,16 +43,11 @@ public function deleteAll(array $scope = []): void
->where($this->buildScope($scope))
->fetchAll();

$batchSize = 100;

$batch = 0;
foreach ($events as $event) {
$this->em->delete($event);

if ($batch++ % $batchSize === 0) {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

???

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably there was batch deletion. I want to refactor this.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$batch++ % $batchSize === 0 is always true. It should be like: ++$batch % $batchSize === 0

$this->em->run();
$batch = 0;
}
$this->em->run();
$batch = 0;
}

$this->em->run();
Expand All @@ -62,7 +57,7 @@ public function deleteByPK(string $uuid): bool
{
$event = $this->findByPK($uuid);

if (!$event) {
if ($event === null) {
return false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public function __construct(
public function __invoke(DeleteEvent $command): void
{
$event = $this->events->findByPK((string) $command->uuid);
if (!$event) {
if ($event === null) {
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
use Modules\Events\Interfaces\Http\Resources\EventCollection;
use Modules\Events\Interfaces\Http\Resources\EventResource;
use Spiral\Cqrs\QueryBusInterface;
use Spiral\Router\Annotation\Route;
use OpenApi\Attributes as OA;

#[OA\Get(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Modules\HttpDumps\Application\Storage;

use Spiral\Storage\Exception\FileOperationException;
use App\Application\Domain\ValueObjects\Uuid;
use Modules\HttpDumps\Domain\AttachmentFactoryInterface;
use Modules\HttpDumps\Domain\AttachmentRepositoryInterface;
Expand Down Expand Up @@ -59,7 +60,7 @@ public function deleteByEvent(Uuid $eventUuid): void
}

/**
* @throws \Spiral\Storage\Exception\FileOperationException
* @throws FileOperationException
*/
public function getContent(string $path)
{
Expand Down
3 changes: 2 additions & 1 deletion app/modules/HttpDumps/EventHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@

namespace Modules\HttpDumps;

use Modules\HttpDumps\Application\EventHandlerInterface;
use Psr\Container\ContainerInterface;

final readonly class EventHandler implements Application\EventHandlerInterface
final readonly class EventHandler implements EventHandlerInterface
{
/**
* @param class-string<\Modules\Sentry\Application\EventHandlerInterface>[] $handlers
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public function handle(ServerRequestInterface $request, \Closure $next): Respons
{
$eventType = $this->listenEvent($request);

if ($eventType === null) {
if (!$eventType instanceof EventType) {
return $next($request);
}

Expand Down Expand Up @@ -71,14 +71,12 @@ private function createPayload(ServerRequestInterface $request): array
'post' => $request->getParsedBody() ?? [],
'cookies' => $request->getCookieParams(),
'files' => \array_map(
function (Attachment $attachment) {
return [
'uuid' => (string) $attachment->getUuid(),
'name' => $attachment->getFilename(),
'size' => $attachment->getSize(),
'mime' => $attachment->getMime(),
];
},
fn(Attachment $attachment) => [
'uuid' => (string) $attachment->getUuid(),
'name' => $attachment->getFilename(),
'size' => $attachment->getSize(),
'mime' => $attachment->getMime(),
],
$result,
),
],
Expand Down
3 changes: 2 additions & 1 deletion app/modules/Inspector/Application/InspectorBootloader.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Modules\Inspector\Application;

use Modules\Inspector\Application\Mapper\EventTypeMapper;
use App\Application\Event\EventTypeRegistryInterface;
use Spiral\Boot\Bootloader\Bootloader;
use Spiral\Boot\EnvironmentInterface;
Expand All @@ -23,6 +24,6 @@ public function defineSingletons(): array

public function boot(EventTypeRegistryInterface $registry): void
{
$registry->register('inspector', new Mapper\EventTypeMapper());
$registry->register('inspector', new EventTypeMapper());
}
}
Loading
Loading