Skip to content

Commit

Permalink
Merge pull request #734 from wayofdev/feat/infra-dx
Browse files Browse the repository at this point in the history
  • Loading branch information
lotyp authored May 26, 2024
2 parents d5ac074 + 4446383 commit 3f64109
Show file tree
Hide file tree
Showing 26 changed files with 248 additions and 45 deletions.
File renamed without changes.
196 changes: 196 additions & 0 deletions .github/workflows/coding-standards.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,196 @@
---

on: # yamllint disable-line rule:truthy
pull_request:
branches:
- master
push:
branches:
- master

name: 🧹 Fix PHP coding standards

jobs:
commit-linting:
timeout-minutes: 4
runs-on: ubuntu-latest
permissions:
contents: read
pull-requests: read
steps:
- name: 📦 Check out the codebase
uses: actions/[email protected]

- name: 🧐 Lint commits using "commitlint"
uses: wagoid/[email protected]
with:
configFile: ${{ github.workspace }}/.github/.commitlint.config.mjs
failOnWarnings: false
failOnErrors: false
helpURL: 'https://github.com/conventional-changelog/commitlint/#what-is-commitlint'

yaml-linting:
timeout-minutes: 4
runs-on: ubuntu-latest
permissions:
contents: read
pull-requests: read
steps:
- name: 📦 Check out the codebase
uses: actions/[email protected]

- name: 🧐 Lint YAML files
uses: ibiqlik/[email protected]
with:
config_file: .github/.yamllint.yaml
file_or_dir: '.'
strict: true

markdown-linting:
timeout-minutes: 4
runs-on: ubuntu-latest
concurrency:
cancel-in-progress: true
group: markdown-linting-${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
steps:
- name: 📦 Check out the codebase
uses: actions/[email protected]

- name: 🧐 Lint Markdown files
uses: DavidAnson/[email protected]
with:
globs: |
**/*.md
!CHANGELOG.md
composer-linting:
timeout-minutes: 4
runs-on: ${{ matrix.os }}
concurrency:
cancel-in-progress: true
group: composer-linting-${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
strategy:
matrix:
os:
- ubuntu-latest
php-version:
- '8.2'
dependencies:
- locked
permissions:
contents: write
steps:
- name: 🛠️ Setup PHP
uses: shivammathur/[email protected]
with:
php-version: ${{ matrix.php-version }}
extensions: none, ctype, dom, json, mbstring, simplexml, tokenizer, xml, xmlwriter, pdo, curl, fileinfo, pdo_mysql
ini-values: error_reporting=E_ALL
coverage: none
tools: phive

- name: 📦 Check out the codebase
uses: actions/[email protected]

- name: 🛠️ Setup problem matchers
run: |
echo "::add-matcher::${{ runner.tool_cache }}/php.json"
- name: 🤖 Validate composer.json and composer.lock
run: composer validate --ansi --strict

- name: 🔍 Get composer cache directory
uses: wayofdev/gh-actions/actions/composer/[email protected]

- name: ♻️ Restore cached dependencies installed with composer
uses: actions/[email protected]
with:
path: ${{ env.COMPOSER_CACHE_DIR }}
key: php-${{ matrix.php-version }}-composer-${{ matrix.dependencies }}-${{ hashFiles('composer.lock') }}
restore-keys: php-${{ matrix.php-version }}-composer-${{ matrix.dependencies }}-

- name: 📥 Install "${{ matrix.dependencies }}" dependencies with composer
uses: wayofdev/gh-actions/actions/composer/[email protected]
with:
dependencies: ${{ matrix.dependencies }}

- name: 📥 Install dependencies with phive
uses: wayofdev/gh-actions/actions/phive/[email protected]
with:
phive-home: '.phive'
trust-gpg-keys: '0xC00543248C87FB13,0x033E5F8D801A2F8D'

- name: 🔍 Run ergebnis/composer-normalize
run: .phive/composer-normalize --ansi --dry-run

coding-standards:
timeout-minutes: 4
runs-on: ${{ matrix.os }}
concurrency:
cancel-in-progress: true
group: coding-standards-${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
strategy:
matrix:
os:
- ubuntu-latest
php-version:
- '8.2'
dependencies:
- locked
permissions:
contents: write
steps:
- name: ⚙️ Set git to use LF line endings
run: |
git config --global core.autocrlf false
git config --global core.eol lf
- name: 🛠️ Setup PHP
uses: shivammathur/[email protected]
with:
php-version: ${{ matrix.php-version }}
extensions: none, ctype, dom, json, mbstring, simplexml, tokenizer, xml, xmlwriter, pdo, curl, fileinfo, pdo_mysql
ini-values: error_reporting=E_ALL
coverage: none

- name: 📦 Check out the codebase
uses: actions/[email protected]

- name: 🛠️ Setup problem matchers
run: |
echo "::add-matcher::${{ runner.tool_cache }}/php.json"
- name: 🤖 Validate composer.json and composer.lock
run: composer validate --ansi --strict

- name: 🔍 Get composer cache directory
uses: wayofdev/gh-actions/actions/composer/[email protected]

- name: ♻️ Restore cached dependencies installed with composer
uses: actions/[email protected]
with:
path: ${{ env.COMPOSER_CACHE_DIR }}
key: php-${{ matrix.php-version }}-composer-${{ matrix.dependencies }}-${{ hashFiles('composer.lock') }}
restore-keys: php-${{ matrix.php-version }}-composer-${{ matrix.dependencies }}-

- name: 📥 Install "${{ matrix.dependencies }}" dependencies with composer
uses: wayofdev/gh-actions/actions/composer/[email protected]
with:
dependencies: ${{ matrix.dependencies }}

- name: 🛠️ Prepare environment
run: make prepare

- name: 🚨 Run coding standards task
run: composer cs:fix
env:
PHP_CS_FIXER_IGNORE_ENV: true

- name: 📤 Commit and push changed files back to GitHub
uses: stefanzweifel/[email protected]
with:
commit_message: 'style(php-cs-fixer): lint php files and fix coding standards'
branch: ${{ github.head_ref }}
commit_author: 'github-actions <[email protected]>'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ ENVSUBST ?= $(BUILDER) envsubst
YAML_LINT_RUNNER ?= $(DOCKER) run --rm $$(tty -s && echo "-it" || echo) \
-v $(PWD):/data \
cytopia/yamllint:latest \
-c ./.github/.yamllint.yaml \
-f colored .

ACTION_LINT_RUNNER ?= $(DOCKER) run --rm $$(tty -s && echo "-it" || echo) \
Expand Down
6 changes: 0 additions & 6 deletions package.json

This file was deleted.

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
Loading

0 comments on commit 3f64109

Please sign in to comment.