Skip to content

Commit f34c48e

Browse files
rustamwinvjik
andauthored
Fix #184: Replace StyleCI with PHP CS Fixer (#216)
Co-authored-by: Sergei Predvoditelev <sergei@predvoditelev.ru>
1 parent 9edf6b9 commit f34c48e

18 files changed

Lines changed: 107 additions & 144 deletions

.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 & 24 deletions
This file was deleted.

.php-cs-fixer.php

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
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 . '/config',
15+
$root . '/src',
16+
$root . '/tests',
17+
])
18+
->append([
19+
$root . '/public/index.php',
20+
]);
21+
22+
return (new Config())
23+
->setCacheFile(__DIR__ . '/runtime/cache/.php-cs-fixer.cache')
24+
->setParallelConfig(ParallelConfigFactory::detect())
25+
->setRules([
26+
'@PER-CS2.0' => true,
27+
'no_unused_imports' => true,
28+
])
29+
->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
@@ -29,6 +29,9 @@ exec: ## Run a command within the existing container.
2929
run: ## Run a command within a temporary container.
3030
docker compose -f docker/compose.yml -f docker/compose.dev.yml run --rm --entrypoint $(CMD) app $(RUN_ARGS)
3131

32+
cs-fix: ## Run PHP CS Fixer
33+
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
34+
3235
shell: CMD="/bin/sh" ## Get into container shell.
3336
shell: exec
3437

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,11 +83,12 @@
8383
"codeception/module-db": "^3.2.2",
8484
"codeception/module-phpbrowser": "^3.0.1",
8585
"codeception/module-rest": "^3.4.1",
86+
"friendsofphp/php-cs-fixer": "^3.75",
8687
"maglnet/composer-require-checker": "^4.16.1",
8788
"phpunit/phpunit": "^11.5.28",
89+
"rector/rector": "^2.1.2",
8890
"roave/infection-static-analysis-plugin": "^1.38",
8991
"spatie/phpunit-watcher": "^1.24",
90-
"rector/rector": "^2.1.2",
9192
"vimeo/psalm": "^6.13.0",
9293
"yiisoft/json": "^1.0",
9394
"yiisoft/yii-debug-api": "dev-master"

config/common/routes.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
->routes(
2525
Route::get('')
2626
->middleware(FormatDataResponseAsHtml::class)
27-
->action(fn (SwaggerUi $swaggerUi) => $swaggerUi->withJsonUrl('/docs/openapi.json')),
27+
->action(fn(SwaggerUi $swaggerUi) => $swaggerUi->withJsonUrl('/docs/openapi.json')),
2828
Route::get('/openapi.json')
2929
->middleware(FormatDataResponseAsJson::class)
3030
->middleware(CorsAllowAllMiddleware::class)

src/Controller/IndexController.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
use Psr\Http\Message\ResponseInterface;
99
use Yiisoft\DataResponse\DataResponseFactoryInterface;
1010

11-
#[OA\Info(title:'Yii API application', version:'1.0')]
11+
#[OA\Info(title: 'Yii API application', version: '1.0')]
1212
final class IndexController
1313
{
1414
#[OA\Get(
@@ -17,8 +17,8 @@ final class IndexController
1717
summary: 'Returns info about the API',
1818
responses: [
1919
new OA\Response(
20-
response:'200',
21-
description:'Success',
20+
response: '200',
21+
description: 'Success',
2222
content: new OA\JsonContent(
2323
allOf: [
2424
new OA\Schema(ref: '#/components/schemas/Response'),
@@ -28,10 +28,10 @@ final class IndexController
2828
new OA\Property(property: 'author', type: 'string', example: 'yiisoft'),
2929
], type: 'object'),
3030
]),
31-
]
31+
],
3232
),
3333
),
34-
]
34+
],
3535
)]
3636
public function index(DataResponseFactoryInterface $responseFactory): ResponseInterface
3737
{

src/Exception/ApplicationException.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,4 @@
44

55
namespace App\Exception;
66

7-
interface ApplicationException extends \Throwable
8-
{
9-
}
7+
interface ApplicationException extends \Throwable {}

src/Http/ApiResponseData.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
use OpenApi\Attributes as OA;
88

99
#[OA\Schema(
10-
schema: 'Response'
10+
schema: 'Response',
1111
)]
1212
#[OA\Schema(
1313
schema: 'BadResponse',
@@ -19,37 +19,37 @@
1919
new OA\Property(property: 'error_code', example: '400', nullable: true),
2020
new OA\Property(property: 'data', example: null),
2121
]),
22-
]
22+
],
2323
)]
2424
final class ApiResponseData
2525
{
2626
#[OA\Property(
2727
property: 'status',
2828
format: 'string',
2929
enum: ['success', 'failed'],
30-
example: 'success'
30+
example: 'success',
3131
)]
3232
private string $status = '';
3333

3434
#[OA\Property(
3535
property: 'error_message',
3636
format: 'string',
37-
example: ''
37+
example: '',
3838
)]
3939
private string $errorMessage = '';
4040

4141
#[OA\Property(
4242
property: 'error_code',
4343
format: 'integer',
4444
example: null,
45-
nullable: true
45+
nullable: true,
4646
)]
4747
private ?int $errorCode = null;
4848

4949
#[OA\Property(
5050
property: 'data',
5151
type: 'object',
52-
nullable: true
52+
nullable: true,
5353
)]
5454
private ?array $data = null;
5555

0 commit comments

Comments
 (0)