Skip to content

Commit c8550d3

Browse files
authored
Replace StyleCI to PHP CS Fixer (#356)
1 parent 02c7a4e commit c8550d3

File tree

13 files changed

+87
-119
lines changed

13 files changed

+87
-119
lines changed

.github/workflows/cs.yml

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
name: Code Style
2+
3+
on:
4+
pull_request:
5+
paths-ignore:
6+
- 'docs/**'
7+
- 'README.md'
8+
- 'CHANGELOG.md'
9+
- '.gitignore'
10+
- '.gitattributes'
11+
- 'infection.json.dist'
12+
- 'psalm.xml'
13+
14+
jobs:
15+
cs-fix:
16+
runs-on: ubuntu-latest
17+
permissions:
18+
contents: write
19+
steps:
20+
- name: Checkout code
21+
uses: actions/checkout@v4
22+
with:
23+
token: ${{ secrets.YIISOFT_GITHUB_TOKEN }}
24+
ref: ${{ github.head_ref }}
25+
repository: ${{ github.event.pull_request.head.repo.full_name }}
26+
27+
- name: Install PHP
28+
uses: shivammathur/setup-php@v2
29+
with:
30+
php-version: 8.4
31+
tools: composer:v2
32+
coverage: none
33+
34+
- name: Install Composer dependencies
35+
uses: "ramsey/composer-install@v3"
36+
37+
- name: Run PHP CS Fixer
38+
run: ./vendor/bin/php-cs-fixer fix --config=.php-cs-fixer.php
39+
40+
- name: Run Rector
41+
run: ./vendor/bin/rector --output-format=github
42+
43+
- name: Commit changes
44+
uses: stefanzweifel/git-auto-commit-action@v5
45+
with:
46+
commit_message: "Apply PHP CS Fixer and Rector changes (CI)"
47+
file_pattern: '*.php'
48+
disable_globbing: true

.github/workflows/rector.yml

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

.php-cs-fixer.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
use PhpCsFixer\Config;
6+
use PhpCsFixer\Finder;
7+
use PhpCsFixer\Runner\Parallel\ParallelConfigFactory;
8+
9+
ini_set('memory_limit', '512M');
10+
11+
$root = __DIR__;
12+
$finder = (new Finder())
13+
->in([
14+
$root . '/src',
15+
$root . '/tests',
16+
])
17+
->append([
18+
$root . '/public/index.php',
19+
]);
20+
21+
return (new Config())
22+
->setCacheFile(__DIR__ . '/runtime/.php-cs-fixer.cache')
23+
->setParallelConfig(ParallelConfigFactory::detect())
24+
->setRules([
25+
'@PER-CS2.0' => true,
26+
'no_unused_imports' => true,
27+
])
28+
->setFinder($finder);

.styleci.yml

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

Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ psalm: run
5050
rector: CMD="./vendor/bin/rector" ## Run Rector.
5151
rector: run
5252

53+
cs-fix:
54+
docker compose -f docker/compose.yml -f docker/compose.dev.yml run --rm --entrypoint ./vendor/bin/php-cs-fixer app fix --config=.php-cs-fixer.php --diff
55+
5356
build-prod: ## Build an image.
5457
docker build --file docker/Dockerfile --target prod --pull -t ${IMAGE}:${IMAGE_TAG} .
5558

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@
8484
"codeception/module-asserts": "^3.2",
8585
"codeception/module-cli": "^2.0.1",
8686
"codeception/module-phpbrowser": "^3.0.1",
87+
"friendsofphp/php-cs-fixer": "^3.75",
8788
"maglnet/composer-require-checker": "^4.16.1",
8889
"rector/rector": "^2.1.0",
8990
"roave/infection-static-analysis-plugin": "^1.38",

src/Environment.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ private static function setEnvironment(): void
6565
$environment = self::getRawValue('APP_ENV');
6666
if (!in_array($environment, [self::DEV, self::TEST, self::PROD], true)) {
6767
throw new RuntimeException(
68-
sprintf('"%s" is invalid environment.', $environment ?? '')
68+
sprintf('"%s" is invalid environment.', $environment ?? ''),
6969
);
7070
}
7171
self::$values['APP_ENV'] = $environment;

src/Handler/NotFoundHandler.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ final class NotFoundHandler implements RequestHandlerInterface
1717
public function __construct(
1818
private readonly UrlGeneratorInterface $urlGenerator,
1919
private readonly CurrentRoute $currentRoute,
20-
private ViewRenderer $viewRenderer
20+
private ViewRenderer $viewRenderer,
2121
) {
2222
$this->viewRenderer = $viewRenderer->withControllerName('site');
2323
}

src/Installer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ private static function chmodRecursive(string $path, int $mode): void
2626
/** @psalm-var iterable<array-key, string> $iterator */
2727
$iterator = new RIterator(
2828
new DirIterator($path, FSIterator::SKIP_DOTS | FSIterator::CURRENT_AS_PATHNAME),
29-
RIterator::SELF_FIRST
29+
RIterator::SELF_FIRST,
3030
);
3131

3232
foreach ($iterator as $item) {

src/ViewInjection/CommonViewInjection.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@
1313
public function __construct(
1414
private ApplicationParameters $applicationParameters,
1515
private UrlGeneratorInterface $urlGenerator,
16-
) {
17-
}
16+
) {}
1817

1918
public function getCommonParameters(): array
2019
{

0 commit comments

Comments
 (0)