From 4446383bdce5a80abdbeefd4d2a22d73144425fe Mon Sep 17 00:00:00 2001 From: github-actions Date: Sun, 26 May 2024 11:40:36 +0000 Subject: [PATCH] style(php-cs-fixer): lint php files and fix coding standards --- .../Console/Commands/Database/ListCommand.php | 2 +- .../Console/Commands/Database/TableCommand.php | 2 +- .../Console/Commands/Migrations/MigrateCommand.php | 2 +- .../Commands/Migrations/RollbackCommand.php | 2 +- .../Console/Commands/Migrations/StatusCommand.php | 1 + .../Laravel/Providers/CycleServiceProvider.php | 2 +- src/Bridge/Laravel/Providers/Registrator.php | 7 +++++++ src/Bridge/Laravel/Rules/Exists.php | 2 +- src/Bridge/Laravel/Rules/Unique.php | 2 +- .../Telescope/Events/Database/QueryExecuted.php | 2 +- src/Bridge/Telescope/TelescopeLogger.php | 2 +- src/Bridge/Telescope/Watchers/QueryWatcher.php | 2 +- src/Contracts/GeneratorLoader.php | 2 ++ src/Schema/Compiler.php | 12 ++++++------ src/Schema/Generators/GeneratorQueue.php | 4 +++- src/Testing/Constraints/HasInDatabase.php | 2 +- .../Constraints/NotSoftDeletedInDatabase.php | 2 +- src/Testing/Constraints/SoftDeletedInDatabase.php | 2 +- tests/app/Entities/Footprint.php | 14 +++++++------- tests/app/Entities/Signature.php | 12 ++++++------ tests/app/Entities/UserId.php | 10 +++++----- tests/src/Bridge/Laravel/LoggerFactoryTest.php | 2 +- 22 files changed, 51 insertions(+), 39 deletions(-) diff --git a/src/Bridge/Laravel/Console/Commands/Database/ListCommand.php b/src/Bridge/Laravel/Console/Commands/Database/ListCommand.php index e1c1f380..badfe4b5 100644 --- a/src/Bridge/Laravel/Console/Commands/Database/ListCommand.php +++ b/src/Bridge/Laravel/Console/Commands/Database/ListCommand.php @@ -48,7 +48,7 @@ public function handle(DatabaseConfig $config, DatabaseProviderInterface $dbal): $databaseArgumentValue = $this->argument('db'); /** @var array $databases */ - $databases = (null !== $databaseArgumentValue) + $databases = ($databaseArgumentValue !== null) ? [$databaseArgumentValue] : array_keys($config->getDatabases()); diff --git a/src/Bridge/Laravel/Console/Commands/Database/TableCommand.php b/src/Bridge/Laravel/Console/Commands/Database/TableCommand.php index 51333c40..692d9793 100644 --- a/src/Bridge/Laravel/Console/Commands/Database/TableCommand.php +++ b/src/Bridge/Laravel/Console/Commands/Database/TableCommand.php @@ -226,7 +226,7 @@ private function describeType(AbstractColumn $column): string $type .= " ({$column->getSize()})"; } - if ('decimal' === $abstractType) { + if ($abstractType === 'decimal') { $type .= " ({$column->getPrecision()}, {$column->getScale()})"; } diff --git a/src/Bridge/Laravel/Console/Commands/Migrations/MigrateCommand.php b/src/Bridge/Laravel/Console/Commands/Migrations/MigrateCommand.php index ce86d801..436dfb5b 100644 --- a/src/Bridge/Laravel/Console/Commands/Migrations/MigrateCommand.php +++ b/src/Bridge/Laravel/Console/Commands/Migrations/MigrateCommand.php @@ -32,7 +32,7 @@ public function handle(): int $found = false; $count = $this->option('one') ? 1 : PHP_INT_MAX; - while (0 < $count && null !== ($migration = $this->migrator->run())) { + while ($count > 0 && null !== ($migration = $this->migrator->run())) { $found = true; --$count; diff --git a/src/Bridge/Laravel/Console/Commands/Migrations/RollbackCommand.php b/src/Bridge/Laravel/Console/Commands/Migrations/RollbackCommand.php index 7300f2fe..7ec6d67d 100644 --- a/src/Bridge/Laravel/Console/Commands/Migrations/RollbackCommand.php +++ b/src/Bridge/Laravel/Console/Commands/Migrations/RollbackCommand.php @@ -33,7 +33,7 @@ public function handle(): int $found = false; $count = ! $this->option('all') ? 1 : PHP_INT_MAX; try { - while (0 < $count && null !== ($migration = $this->migrator->rollback())) { + while ($count > 0 && null !== ($migration = $this->migrator->rollback())) { $found = true; --$count; $this->line( diff --git a/src/Bridge/Laravel/Console/Commands/Migrations/StatusCommand.php b/src/Bridge/Laravel/Console/Commands/Migrations/StatusCommand.php index 06dabd8b..72b4fc08 100644 --- a/src/Bridge/Laravel/Console/Commands/Migrations/StatusCommand.php +++ b/src/Bridge/Laravel/Console/Commands/Migrations/StatusCommand.php @@ -16,6 +16,7 @@ final class StatusCommand extends AbstractCommand { private const DATE_TIME_FORMAT = 'Y-m-d H:i:s'; + private const PENDING = 'not executed yet'; protected $signature = 'cycle:migrate:status'; diff --git a/src/Bridge/Laravel/Providers/CycleServiceProvider.php b/src/Bridge/Laravel/Providers/CycleServiceProvider.php index 3060f502..a27edde1 100644 --- a/src/Bridge/Laravel/Providers/CycleServiceProvider.php +++ b/src/Bridge/Laravel/Providers/CycleServiceProvider.php @@ -38,7 +38,7 @@ public function boot(): void $config = $this->app->get(IlluminateConfig::class); $warmup = $config->get('cycle.warmup'); - if (true === $warmup) { + if ($warmup === true) { /** @var CycleORM $orm */ $orm = $this->app->get(ORMInterface::class); $orm->prepareServices(); diff --git a/src/Bridge/Laravel/Providers/Registrator.php b/src/Bridge/Laravel/Providers/Registrator.php index 76309513..617f7cd4 100644 --- a/src/Bridge/Laravel/Providers/Registrator.php +++ b/src/Bridge/Laravel/Providers/Registrator.php @@ -7,11 +7,18 @@ interface Registrator { public const CFG_KEY = 'cycle'; + public const CFG_KEY_DATABASE = 'cycle.database'; + public const CFG_KEY_TOKENIZER = 'cycle.tokenizer'; + public const CFG_KEY_ATTRIBUTES = 'cycle.attributes'; + public const CFG_KEY_MIGRATIONS = 'cycle.migrations'; + public const CFG_KEY_SCHEMA = 'cycle.schema'; + public const CFG_KEY_WARMUP = 'cycle.warmup'; + public const CFG_KEY_RELATIONS = 'cycle.customRelations'; } diff --git a/src/Bridge/Laravel/Rules/Exists.php b/src/Bridge/Laravel/Rules/Exists.php index 93f9ab31..b51e6237 100644 --- a/src/Bridge/Laravel/Rules/Exists.php +++ b/src/Bridge/Laravel/Rules/Exists.php @@ -31,7 +31,7 @@ public function validate(string $attribute, mixed $value, Closure $fail): void $count = $table->where([$this->column => $value])->count(); - if (0 === $count) { + if ($count === 0) { $fail($this->message()); } } diff --git a/src/Bridge/Laravel/Rules/Unique.php b/src/Bridge/Laravel/Rules/Unique.php index ff419cf6..a78baa3d 100644 --- a/src/Bridge/Laravel/Rules/Unique.php +++ b/src/Bridge/Laravel/Rules/Unique.php @@ -31,7 +31,7 @@ public function validate(string $attribute, mixed $value, Closure $fail): void $count = $table->where([$this->column => $value])->count(); - if (0 < $count) { + if ($count > 0) { $fail($this->message()); } } diff --git a/src/Bridge/Telescope/Events/Database/QueryExecuted.php b/src/Bridge/Telescope/Events/Database/QueryExecuted.php index cfc249c5..9132f922 100644 --- a/src/Bridge/Telescope/Events/Database/QueryExecuted.php +++ b/src/Bridge/Telescope/Events/Database/QueryExecuted.php @@ -13,6 +13,6 @@ final class QueryExecuted public function __construct(public string $sql, public array $bindings, public ?float $time, public ?string $driver = null) { $this->time = $time * 1000; - $this->driver = null !== $driver ? 'CycleORM/' . $driver : 'CycleORM'; + $this->driver = $driver !== null ? 'CycleORM/' . $driver : 'CycleORM'; } } diff --git a/src/Bridge/Telescope/TelescopeLogger.php b/src/Bridge/Telescope/TelescopeLogger.php index 5ca7bda0..f0b14dcd 100644 --- a/src/Bridge/Telescope/TelescopeLogger.php +++ b/src/Bridge/Telescope/TelescopeLogger.php @@ -21,7 +21,7 @@ public function log($level, $message, array $context = []): void { $this->parentLogger->log($level, $message, $context); - if ('info' === $level && isset($context['elapsed'])) { + if ($level === 'info' && isset($context['elapsed'])) { event( new QueryExecuted( sql: $message, diff --git a/src/Bridge/Telescope/Watchers/QueryWatcher.php b/src/Bridge/Telescope/Watchers/QueryWatcher.php index e3e544cf..676e40f7 100644 --- a/src/Bridge/Telescope/Watchers/QueryWatcher.php +++ b/src/Bridge/Telescope/Watchers/QueryWatcher.php @@ -32,7 +32,7 @@ public function recordQuery(QueryExecuted $event): void $time = $event->time; $caller = $this->getCallerFromStackTrace(); - if (null !== $caller) { + if ($caller !== null) { Telescope::recordQuery(IncomingEntry::make([ 'connection' => $event->driver, 'bindings' => $event->bindings, diff --git a/src/Contracts/GeneratorLoader.php b/src/Contracts/GeneratorLoader.php index cc1cd0d8..3266e78f 100644 --- a/src/Contracts/GeneratorLoader.php +++ b/src/Contracts/GeneratorLoader.php @@ -9,7 +9,9 @@ interface GeneratorLoader { public const GROUP_INDEX = 'index'; + public const GROUP_RENDER = 'render'; + public const GROUP_POSTPROCESS = 'postprocess'; /** diff --git a/src/Schema/Compiler.php b/src/Schema/Compiler.php index 1466389b..250772be 100644 --- a/src/Schema/Compiler.php +++ b/src/Schema/Compiler.php @@ -17,6 +17,11 @@ final class Compiler { private const EMPTY_SCHEMA = ':empty:'; + public function __construct( + private readonly mixed $schema + ) { + } + public static function compile(Registry $registry, GeneratorLoader $queue): self { return new self((new CycleSchemaCompiler())->compile($registry, $queue->get())); @@ -27,14 +32,9 @@ public static function fromMemory(CacheManager $cache): self return new self($cache->get()); } - public function __construct( - private readonly mixed $schema - ) { - } - public function isEmpty(): bool { - return null === $this->schema || [] === $this->schema || self::EMPTY_SCHEMA === $this->schema; + return $this->schema === null || $this->schema === [] || $this->schema === self::EMPTY_SCHEMA; } public function toSchema(): SchemaInterface diff --git a/src/Schema/Generators/GeneratorQueue.php b/src/Schema/Generators/GeneratorQueue.php index 13d393a4..563978b6 100644 --- a/src/Schema/Generators/GeneratorQueue.php +++ b/src/Schema/Generators/GeneratorQueue.php @@ -16,7 +16,9 @@ final class GeneratorQueue implements GeneratorLoader { - /** @var array>> */ + /** + * @var array>> + */ private array $generators; private Container $app; diff --git a/src/Testing/Constraints/HasInDatabase.php b/src/Testing/Constraints/HasInDatabase.php index 47fe46a0..3f9426ec 100644 --- a/src/Testing/Constraints/HasInDatabase.php +++ b/src/Testing/Constraints/HasInDatabase.php @@ -37,7 +37,7 @@ public function matches(mixed $other): bool try { $count = $tableInterface->where($this->data)->count(); - return 0 < $count; + return $count > 0; } catch (Throwable $e) { return false; } diff --git a/src/Testing/Constraints/NotSoftDeletedInDatabase.php b/src/Testing/Constraints/NotSoftDeletedInDatabase.php index 218f0b8b..ef756f03 100644 --- a/src/Testing/Constraints/NotSoftDeletedInDatabase.php +++ b/src/Testing/Constraints/NotSoftDeletedInDatabase.php @@ -42,7 +42,7 @@ public function matches(mixed $other): bool ->andWhere($this->deletedAtColumn, '=', null) ->count(); - return 0 < $count; + return $count > 0; } catch (Throwable $e) { return false; } diff --git a/src/Testing/Constraints/SoftDeletedInDatabase.php b/src/Testing/Constraints/SoftDeletedInDatabase.php index 6404df49..510c2cf8 100644 --- a/src/Testing/Constraints/SoftDeletedInDatabase.php +++ b/src/Testing/Constraints/SoftDeletedInDatabase.php @@ -42,7 +42,7 @@ public function matches(mixed $other): bool ->andWhere($this->deletedAtColumn, '!=', null) ->count(); - return 0 < $count; + return $count > 0; } catch (Throwable $e) { return false; } diff --git a/tests/app/Entities/Footprint.php b/tests/app/Entities/Footprint.php index 59347e6e..34b8c3b5 100644 --- a/tests/app/Entities/Footprint.php +++ b/tests/app/Entities/Footprint.php @@ -21,6 +21,13 @@ final class Footprint implements JsonSerializable, Stringable private readonly string $realm; + private function __construct(UserId $id, string $party, string $realm) + { + $this->id = $id; + $this->party = $party; + $this->realm = $realm; + } + public static function empty(string $authorizedParty = 'guest-party', string $realm = 'guest-realm'): self { return new self(UserId::create(Uuid::NIL), $authorizedParty, $realm); @@ -86,11 +93,4 @@ public function __toString(): string { return json_encode($this->toArray(), JSON_THROW_ON_ERROR); } - - private function __construct(UserId $id, string $party, string $realm) - { - $this->id = $id; - $this->party = $party; - $this->realm = $realm; - } } diff --git a/tests/app/Entities/Signature.php b/tests/app/Entities/Signature.php index 76c9d7e7..585da467 100644 --- a/tests/app/Entities/Signature.php +++ b/tests/app/Entities/Signature.php @@ -25,6 +25,12 @@ class Signature #[Column(type: 'json', nullable: true, typecast: [Footprint::class, 'castValue'])] private ?Footprint $by = null; + public function __construct(?DateTimeImmutable $at, ?Footprint $by) + { + $this->at = $at; + $this->by = $by; + } + public static function forGuest(): self { return new self(new DateTimeImmutable(), Footprint::empty()); @@ -78,10 +84,4 @@ public function toArray(): array 'by' => $this->by?->toArray(), ]; } - - public function __construct(?DateTimeImmutable $at, ?Footprint $by) - { - $this->at = $at; - $this->by = $by; - } } diff --git a/tests/app/Entities/UserId.php b/tests/app/Entities/UserId.php index e79747bd..24dce8cf 100644 --- a/tests/app/Entities/UserId.php +++ b/tests/app/Entities/UserId.php @@ -11,6 +11,11 @@ final class UserId implements Stringable { private readonly string $id; + private function __construct(string $id) + { + $this->id = $id; + } + public static function create(string $userId): self { return new self($userId); @@ -35,9 +40,4 @@ public function __toString(): string { return $this->toString(); } - - private function __construct(string $id) - { - $this->id = $id; - } } diff --git a/tests/src/Bridge/Laravel/LoggerFactoryTest.php b/tests/src/Bridge/Laravel/LoggerFactoryTest.php index 8bf233f9..eedb725e 100644 --- a/tests/src/Bridge/Laravel/LoggerFactoryTest.php +++ b/tests/src/Bridge/Laravel/LoggerFactoryTest.php @@ -78,7 +78,7 @@ public function it_should_fire_query_executed_event_when_query_is_logged(): void // Assert that the QueryExecuted event was dispatched Event::assertDispatched(QueryExecuted::class, function ($event) { - return 'SELECT * FROM users' === $event->sql; + return $event->sql === 'SELECT * FROM users'; }); }