Skip to content

Commit

Permalink
style(php-cs-fixer): lint php files and fix coding standards
Browse files Browse the repository at this point in the history
  • Loading branch information
github-actions authored and github-actions[bot] committed May 26, 2024
1 parent 07382b6 commit 4446383
Show file tree
Hide file tree
Showing 22 changed files with 51 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public function handle(DatabaseConfig $config, DatabaseProviderInterface $dbal):
$databaseArgumentValue = $this->argument('db');

/** @var array<string> $databases */
$databases = (null !== $databaseArgumentValue)
$databases = ($databaseArgumentValue !== null)
? [$databaseArgumentValue]
: array_keys($config->getDatabases());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ private function describeType(AbstractColumn $column): string
$type .= " ({$column->getSize()})";
}

if ('decimal' === $abstractType) {
if ($abstractType === 'decimal') {
$type .= " ({$column->getPrecision()}, {$column->getScale()})";
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
final class StatusCommand extends AbstractCommand
{
private const DATE_TIME_FORMAT = 'Y-m-d H:i:s';

private const PENDING = '<fg=red>not executed yet</fg=red>';

protected $signature = 'cycle:migrate:status';
Expand Down
2 changes: 1 addition & 1 deletion src/Bridge/Laravel/Providers/CycleServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
7 changes: 7 additions & 0 deletions src/Bridge/Laravel/Providers/Registrator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
}
2 changes: 1 addition & 1 deletion src/Bridge/Laravel/Rules/Exists.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/Bridge/Laravel/Rules/Unique.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/Bridge/Telescope/Events/Database/QueryExecuted.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
}
}
2 changes: 1 addition & 1 deletion src/Bridge/Telescope/TelescopeLogger.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion src/Bridge/Telescope/Watchers/QueryWatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 2 additions & 0 deletions src/Contracts/GeneratorLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
interface GeneratorLoader
{
public const GROUP_INDEX = 'index';

public const GROUP_RENDER = 'render';

public const GROUP_POSTPROCESS = 'postprocess';

/**
Expand Down
12 changes: 6 additions & 6 deletions src/Schema/Compiler.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()));
Expand All @@ -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
Expand Down
4 changes: 3 additions & 1 deletion src/Schema/Generators/GeneratorQueue.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@

final class GeneratorQueue implements GeneratorLoader
{
/** @var array<array<GeneratorInterface|class-string<GeneratorInterface>>> */
/**
* @var array<array<GeneratorInterface|class-string<GeneratorInterface>>>
*/
private array $generators;

private Container $app;
Expand Down
2 changes: 1 addition & 1 deletion src/Testing/Constraints/HasInDatabase.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Testing/Constraints/NotSoftDeletedInDatabase.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Testing/Constraints/SoftDeletedInDatabase.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
14 changes: 7 additions & 7 deletions tests/app/Entities/Footprint.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
}
}
12 changes: 6 additions & 6 deletions tests/app/Entities/Signature.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down Expand Up @@ -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;
}
}
10 changes: 5 additions & 5 deletions tests/app/Entities/UserId.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -35,9 +40,4 @@ public function __toString(): string
{
return $this->toString();
}

private function __construct(string $id)
{
$this->id = $id;
}
}
2 changes: 1 addition & 1 deletion tests/src/Bridge/Laravel/LoggerFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
});
}

Expand Down

0 comments on commit 4446383

Please sign in to comment.