Skip to content

Commit 3f64109

Browse files
authored
Merge pull request #734 from wayofdev/feat/infra-dx
2 parents d5ac074 + 4446383 commit 3f64109

26 files changed

+248
-45
lines changed
File renamed without changes.
Lines changed: 196 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,196 @@
1+
---
2+
3+
on: # yamllint disable-line rule:truthy
4+
pull_request:
5+
branches:
6+
- master
7+
push:
8+
branches:
9+
- master
10+
11+
name: 🧹 Fix PHP coding standards
12+
13+
jobs:
14+
commit-linting:
15+
timeout-minutes: 4
16+
runs-on: ubuntu-latest
17+
permissions:
18+
contents: read
19+
pull-requests: read
20+
steps:
21+
- name: 📦 Check out the codebase
22+
uses: actions/[email protected]
23+
24+
- name: 🧐 Lint commits using "commitlint"
25+
uses: wagoid/[email protected]
26+
with:
27+
configFile: ${{ github.workspace }}/.github/.commitlint.config.mjs
28+
failOnWarnings: false
29+
failOnErrors: false
30+
helpURL: 'https://github.com/conventional-changelog/commitlint/#what-is-commitlint'
31+
32+
yaml-linting:
33+
timeout-minutes: 4
34+
runs-on: ubuntu-latest
35+
permissions:
36+
contents: read
37+
pull-requests: read
38+
steps:
39+
- name: 📦 Check out the codebase
40+
uses: actions/[email protected]
41+
42+
- name: 🧐 Lint YAML files
43+
uses: ibiqlik/[email protected]
44+
with:
45+
config_file: .github/.yamllint.yaml
46+
file_or_dir: '.'
47+
strict: true
48+
49+
markdown-linting:
50+
timeout-minutes: 4
51+
runs-on: ubuntu-latest
52+
concurrency:
53+
cancel-in-progress: true
54+
group: markdown-linting-${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
55+
steps:
56+
- name: 📦 Check out the codebase
57+
uses: actions/[email protected]
58+
59+
- name: 🧐 Lint Markdown files
60+
uses: DavidAnson/[email protected]
61+
with:
62+
globs: |
63+
**/*.md
64+
!CHANGELOG.md
65+
66+
composer-linting:
67+
timeout-minutes: 4
68+
runs-on: ${{ matrix.os }}
69+
concurrency:
70+
cancel-in-progress: true
71+
group: composer-linting-${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
72+
strategy:
73+
matrix:
74+
os:
75+
- ubuntu-latest
76+
php-version:
77+
- '8.2'
78+
dependencies:
79+
- locked
80+
permissions:
81+
contents: write
82+
steps:
83+
- name: 🛠️ Setup PHP
84+
uses: shivammathur/[email protected]
85+
with:
86+
php-version: ${{ matrix.php-version }}
87+
extensions: none, ctype, dom, json, mbstring, simplexml, tokenizer, xml, xmlwriter, pdo, curl, fileinfo, pdo_mysql
88+
ini-values: error_reporting=E_ALL
89+
coverage: none
90+
tools: phive
91+
92+
- name: 📦 Check out the codebase
93+
uses: actions/[email protected]
94+
95+
- name: 🛠️ Setup problem matchers
96+
run: |
97+
echo "::add-matcher::${{ runner.tool_cache }}/php.json"
98+
99+
- name: 🤖 Validate composer.json and composer.lock
100+
run: composer validate --ansi --strict
101+
102+
- name: 🔍 Get composer cache directory
103+
uses: wayofdev/gh-actions/actions/composer/[email protected]
104+
105+
- name: ♻️ Restore cached dependencies installed with composer
106+
uses: actions/[email protected]
107+
with:
108+
path: ${{ env.COMPOSER_CACHE_DIR }}
109+
key: php-${{ matrix.php-version }}-composer-${{ matrix.dependencies }}-${{ hashFiles('composer.lock') }}
110+
restore-keys: php-${{ matrix.php-version }}-composer-${{ matrix.dependencies }}-
111+
112+
- name: 📥 Install "${{ matrix.dependencies }}" dependencies with composer
113+
uses: wayofdev/gh-actions/actions/composer/[email protected]
114+
with:
115+
dependencies: ${{ matrix.dependencies }}
116+
117+
- name: 📥 Install dependencies with phive
118+
uses: wayofdev/gh-actions/actions/phive/[email protected]
119+
with:
120+
phive-home: '.phive'
121+
trust-gpg-keys: '0xC00543248C87FB13,0x033E5F8D801A2F8D'
122+
123+
- name: 🔍 Run ergebnis/composer-normalize
124+
run: .phive/composer-normalize --ansi --dry-run
125+
126+
coding-standards:
127+
timeout-minutes: 4
128+
runs-on: ${{ matrix.os }}
129+
concurrency:
130+
cancel-in-progress: true
131+
group: coding-standards-${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
132+
strategy:
133+
matrix:
134+
os:
135+
- ubuntu-latest
136+
php-version:
137+
- '8.2'
138+
dependencies:
139+
- locked
140+
permissions:
141+
contents: write
142+
steps:
143+
- name: ⚙️ Set git to use LF line endings
144+
run: |
145+
git config --global core.autocrlf false
146+
git config --global core.eol lf
147+
148+
- name: 🛠️ Setup PHP
149+
uses: shivammathur/[email protected]
150+
with:
151+
php-version: ${{ matrix.php-version }}
152+
extensions: none, ctype, dom, json, mbstring, simplexml, tokenizer, xml, xmlwriter, pdo, curl, fileinfo, pdo_mysql
153+
ini-values: error_reporting=E_ALL
154+
coverage: none
155+
156+
- name: 📦 Check out the codebase
157+
uses: actions/[email protected]
158+
159+
- name: 🛠️ Setup problem matchers
160+
run: |
161+
echo "::add-matcher::${{ runner.tool_cache }}/php.json"
162+
163+
- name: 🤖 Validate composer.json and composer.lock
164+
run: composer validate --ansi --strict
165+
166+
- name: 🔍 Get composer cache directory
167+
uses: wayofdev/gh-actions/actions/composer/[email protected]
168+
169+
- name: ♻️ Restore cached dependencies installed with composer
170+
uses: actions/[email protected]
171+
with:
172+
path: ${{ env.COMPOSER_CACHE_DIR }}
173+
key: php-${{ matrix.php-version }}-composer-${{ matrix.dependencies }}-${{ hashFiles('composer.lock') }}
174+
restore-keys: php-${{ matrix.php-version }}-composer-${{ matrix.dependencies }}-
175+
176+
- name: 📥 Install "${{ matrix.dependencies }}" dependencies with composer
177+
uses: wayofdev/gh-actions/actions/composer/[email protected]
178+
with:
179+
dependencies: ${{ matrix.dependencies }}
180+
181+
- name: 🛠️ Prepare environment
182+
run: make prepare
183+
184+
- name: 🚨 Run coding standards task
185+
run: composer cs:fix
186+
env:
187+
PHP_CS_FIXER_IGNORE_ENV: true
188+
189+
- name: 📤 Commit and push changed files back to GitHub
190+
uses: stefanzweifel/[email protected]
191+
with:
192+
commit_message: 'style(php-cs-fixer): lint php files and fix coding standards'
193+
branch: ${{ github.head_ref }}
194+
commit_author: 'github-actions <[email protected]>'
195+
env:
196+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ ENVSUBST ?= $(BUILDER) envsubst
3232
YAML_LINT_RUNNER ?= $(DOCKER) run --rm $$(tty -s && echo "-it" || echo) \
3333
-v $(PWD):/data \
3434
cytopia/yamllint:latest \
35+
-c ./.github/.yamllint.yaml \
3536
-f colored .
3637

3738
ACTION_LINT_RUNNER ?= $(DOCKER) run --rm $$(tty -s && echo "-it" || echo) \

package.json

Lines changed: 0 additions & 6 deletions
This file was deleted.

src/Bridge/Laravel/Console/Commands/Database/ListCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public function handle(DatabaseConfig $config, DatabaseProviderInterface $dbal):
4848
$databaseArgumentValue = $this->argument('db');
4949

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

src/Bridge/Laravel/Console/Commands/Database/TableCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ private function describeType(AbstractColumn $column): string
226226
$type .= " ({$column->getSize()})";
227227
}
228228

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

src/Bridge/Laravel/Console/Commands/Migrations/MigrateCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public function handle(): int
3232
$found = false;
3333
$count = $this->option('one') ? 1 : PHP_INT_MAX;
3434

35-
while (0 < $count && null !== ($migration = $this->migrator->run())) {
35+
while ($count > 0 && null !== ($migration = $this->migrator->run())) {
3636
$found = true;
3737
--$count;
3838

src/Bridge/Laravel/Console/Commands/Migrations/RollbackCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public function handle(): int
3333
$found = false;
3434
$count = ! $this->option('all') ? 1 : PHP_INT_MAX;
3535
try {
36-
while (0 < $count && null !== ($migration = $this->migrator->rollback())) {
36+
while ($count > 0 && null !== ($migration = $this->migrator->rollback())) {
3737
$found = true;
3838
--$count;
3939
$this->line(

src/Bridge/Laravel/Console/Commands/Migrations/StatusCommand.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
final class StatusCommand extends AbstractCommand
1717
{
1818
private const DATE_TIME_FORMAT = 'Y-m-d H:i:s';
19+
1920
private const PENDING = '<fg=red>not executed yet</fg=red>';
2021

2122
protected $signature = 'cycle:migrate:status';

src/Bridge/Laravel/Providers/CycleServiceProvider.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public function boot(): void
3838
$config = $this->app->get(IlluminateConfig::class);
3939
$warmup = $config->get('cycle.warmup');
4040

41-
if (true === $warmup) {
41+
if ($warmup === true) {
4242
/** @var CycleORM $orm */
4343
$orm = $this->app->get(ORMInterface::class);
4444
$orm->prepareServices();

src/Bridge/Laravel/Providers/Registrator.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,18 @@
77
interface Registrator
88
{
99
public const CFG_KEY = 'cycle';
10+
1011
public const CFG_KEY_DATABASE = 'cycle.database';
12+
1113
public const CFG_KEY_TOKENIZER = 'cycle.tokenizer';
14+
1215
public const CFG_KEY_ATTRIBUTES = 'cycle.attributes';
16+
1317
public const CFG_KEY_MIGRATIONS = 'cycle.migrations';
18+
1419
public const CFG_KEY_SCHEMA = 'cycle.schema';
20+
1521
public const CFG_KEY_WARMUP = 'cycle.warmup';
22+
1623
public const CFG_KEY_RELATIONS = 'cycle.customRelations';
1724
}

src/Bridge/Laravel/Rules/Exists.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public function validate(string $attribute, mixed $value, Closure $fail): void
3131

3232
$count = $table->where([$this->column => $value])->count();
3333

34-
if (0 === $count) {
34+
if ($count === 0) {
3535
$fail($this->message());
3636
}
3737
}

src/Bridge/Laravel/Rules/Unique.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public function validate(string $attribute, mixed $value, Closure $fail): void
3131

3232
$count = $table->where([$this->column => $value])->count();
3333

34-
if (0 < $count) {
34+
if ($count > 0) {
3535
$fail($this->message());
3636
}
3737
}

src/Bridge/Telescope/Events/Database/QueryExecuted.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,6 @@ final class QueryExecuted
1313
public function __construct(public string $sql, public array $bindings, public ?float $time, public ?string $driver = null)
1414
{
1515
$this->time = $time * 1000;
16-
$this->driver = null !== $driver ? 'CycleORM/' . $driver : 'CycleORM';
16+
$this->driver = $driver !== null ? 'CycleORM/' . $driver : 'CycleORM';
1717
}
1818
}

src/Bridge/Telescope/TelescopeLogger.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public function log($level, $message, array $context = []): void
2121
{
2222
$this->parentLogger->log($level, $message, $context);
2323

24-
if ('info' === $level && isset($context['elapsed'])) {
24+
if ($level === 'info' && isset($context['elapsed'])) {
2525
event(
2626
new QueryExecuted(
2727
sql: $message,

src/Bridge/Telescope/Watchers/QueryWatcher.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public function recordQuery(QueryExecuted $event): void
3232
$time = $event->time;
3333
$caller = $this->getCallerFromStackTrace();
3434

35-
if (null !== $caller) {
35+
if ($caller !== null) {
3636
Telescope::recordQuery(IncomingEntry::make([
3737
'connection' => $event->driver,
3838
'bindings' => $event->bindings,

src/Contracts/GeneratorLoader.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@
99
interface GeneratorLoader
1010
{
1111
public const GROUP_INDEX = 'index';
12+
1213
public const GROUP_RENDER = 'render';
14+
1315
public const GROUP_POSTPROCESS = 'postprocess';
1416

1517
/**

src/Schema/Compiler.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@ final class Compiler
1717
{
1818
private const EMPTY_SCHEMA = ':empty:';
1919

20+
public function __construct(
21+
private readonly mixed $schema
22+
) {
23+
}
24+
2025
public static function compile(Registry $registry, GeneratorLoader $queue): self
2126
{
2227
return new self((new CycleSchemaCompiler())->compile($registry, $queue->get()));
@@ -27,14 +32,9 @@ public static function fromMemory(CacheManager $cache): self
2732
return new self($cache->get());
2833
}
2934

30-
public function __construct(
31-
private readonly mixed $schema
32-
) {
33-
}
34-
3535
public function isEmpty(): bool
3636
{
37-
return null === $this->schema || [] === $this->schema || self::EMPTY_SCHEMA === $this->schema;
37+
return $this->schema === null || $this->schema === [] || $this->schema === self::EMPTY_SCHEMA;
3838
}
3939

4040
public function toSchema(): SchemaInterface

src/Schema/Generators/GeneratorQueue.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@
1616

1717
final class GeneratorQueue implements GeneratorLoader
1818
{
19-
/** @var array<array<GeneratorInterface|class-string<GeneratorInterface>>> */
19+
/**
20+
* @var array<array<GeneratorInterface|class-string<GeneratorInterface>>>
21+
*/
2022
private array $generators;
2123

2224
private Container $app;

src/Testing/Constraints/HasInDatabase.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public function matches(mixed $other): bool
3737
try {
3838
$count = $tableInterface->where($this->data)->count();
3939

40-
return 0 < $count;
40+
return $count > 0;
4141
} catch (Throwable $e) {
4242
return false;
4343
}

src/Testing/Constraints/NotSoftDeletedInDatabase.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public function matches(mixed $other): bool
4242
->andWhere($this->deletedAtColumn, '=', null)
4343
->count();
4444

45-
return 0 < $count;
45+
return $count > 0;
4646
} catch (Throwable $e) {
4747
return false;
4848
}

0 commit comments

Comments
 (0)