Skip to content

Commit b0f9811

Browse files
committed
Check the code style fully on CI
1 parent c53e397 commit b0f9811

10 files changed

Lines changed: 117 additions & 7 deletions

File tree

‎.gitattributes‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
/.git-blame-ignore-revs export-ignore
2929
/.gitattributes export-ignore
3030
/.gitignore export-ignore
31+
/.php-cs-fixer.dist.php export-ignore
3132
/phpcs.xml.dist export-ignore
3233
/phpstan-baseline.neon export-ignore
3334
/phpstan.dist.neon export-ignore

‎.github/workflows/php-cs-fixer.yml‎

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
name: php-cs-fixer
2+
3+
permissions:
4+
contents: read
5+
6+
on:
7+
pull_request: &ignore-paths
8+
paths-ignore:
9+
- ".github/CONTRIBUTING.md"
10+
- ".github/FUNDING.yml"
11+
- ".github/ISSUE_TEMPLATE.md"
12+
- ".github/PULL_REQUEST_TEMPLATE.md"
13+
- ".github/SECURITY.md"
14+
- ".editorconfig"
15+
- ".git-blame-ignore-revs"
16+
- ".gitattributes"
17+
- ".gitignore"
18+
- "LICENSE.md"
19+
- "README.md"
20+
- "CHANGELOG.md"
21+
- "UPGRADE.md"
22+
23+
push: *ignore-paths
24+
25+
jobs:
26+
php-cs-fixer:
27+
uses: yiisoft/yii2-actions/.github/workflows/php-cs-fixer.yml@9bfbe47bd91bc31a6ff9f0ea77ba3724d7816c3d # master
28+
with:
29+
composer-root-version: 2.0.x-dev
30+
configuration: .php-cs-fixer.dist.php
31+
php-version: '["7.4"]'
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: linter
1+
name: phpcs
22

33
permissions:
44
contents: read

‎.gitignore‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,3 +46,7 @@ phpstan.neon
4646

4747
# local phpcs config
4848
phpcs.xml
49+
50+
# PHP CS Fixer
51+
.php-cs-fixer.php
52+
.php-cs-fixer.cache

‎.php-cs-fixer.dist.php‎

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
3+
use PhpCsFixer\Config;
4+
use PhpCsFixer\Finder;
5+
6+
$header = '@link https://www.yiiframework.com/
7+
@copyright Copyright (c) 2008 Yii Software LLC
8+
@license https://www.yiiframework.com/license/';
9+
10+
$finder = (new Finder())
11+
->in([
12+
__DIR__ . '/commands',
13+
__DIR__ . '/components',
14+
__DIR__ . '/helpers',
15+
__DIR__ . '/models',
16+
__DIR__ . '/renderers',
17+
__DIR__ . '/templates',
18+
__DIR__ . '/tests',
19+
])
20+
->notPath([
21+
'#(^|/)data/#',
22+
'#(^|/)layouts/#',
23+
'#(^|/)views/#',
24+
]);
25+
26+
return (new Config())
27+
->setFinder($finder)
28+
->setRules([
29+
'phpdoc_scalar' => true,
30+
'header_comment' => [
31+
'comment_type' => 'PHPDoc',
32+
'header' => $header,
33+
'location' => 'after_open',
34+
],
35+
]);

‎composer.json‎

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,9 @@
3838
"phpstan/phpstan": "^2.1",
3939
"yiisoft/yii2-coding-standards": "^3.0",
4040
"rector/rector": "^2.3",
41-
"mspirkov/yii2-rector": "^0.1"
41+
"mspirkov/yii2-rector": "^0.1",
42+
"slevomat/coding-standard": "^8.31",
43+
"friendsofphp/php-cs-fixer": "^3.95"
4244
},
4345
"repositories": [
4446
{
@@ -64,12 +66,13 @@
6466
"bin": ["apidoc"],
6567
"config": {
6668
"allow-plugins": {
67-
"yiisoft/yii2-composer": true
69+
"yiisoft/yii2-composer": true,
70+
"dealerdirect/phpcodesniffer-composer-installer": true
6871
}
6972
},
7073
"scripts": {
71-
"cs": "./vendor/bin/phpcs",
72-
"cs-fix": "./vendor/bin/phpcbf",
74+
"cs": "./vendor/bin/phpcs && ./vendor/bin/php-cs-fixer check",
75+
"cs-fix": "./vendor/bin/phpcbf && ./vendor/bin/php-cs-fixer fix",
7376
"static": "./vendor/bin/phpstan --memory-limit=-1",
7477
"tests": "./vendor/bin/phpunit",
7578
"rector": "./vendor/bin/rector"

‎models/BaseDoc.php‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ class BaseDoc extends BaseObject
4343
private const PSALM_IMPORT_TYPE_ANNOTATION_NAME = 'psalm-import-type';
4444
public const INHERITDOC_TAG_NAME = 'inheritdoc';
4545
private const TODO_TAG_NAME = 'todo';
46+
4647
/**
4748
* @var \phpDocumentor\Reflection\Types\Context|null
4849
*/
@@ -103,8 +104,6 @@ class BaseDoc extends BaseObject
103104
* @var array<string, Template>
104105
*/
105106
public $templates = [];
106-
107-
108107
/**
109108
* @var array<string, PseudoTypeDoc>
110109
*/
@@ -121,6 +120,8 @@ class BaseDoc extends BaseObject
121120
* @var array<string, PseudoTypeImportDoc>
122121
*/
123122
public array $psalmTypeImports = [];
123+
124+
124125
/**
125126
* Checks if doc has tag of a given name
126127
* @param string $name tag name

‎phpcs.xml.dist‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,29 @@
22
<ruleset name="Yii2">
33
<rule ref="vendor/yiisoft/yii2-coding-standards/Yii2"></rule>
44

5+
<rule ref="SlevomatCodingStandard.Classes.TraitUseSpacing">
6+
<properties>
7+
<property name="linesCountBeforeFirstUseWhenFirstInClass" value="0"/>
8+
<property name="linesCountAfterLastUseWhenLastInClass" value="0"/>
9+
</properties>
10+
</rule>
11+
<rule ref="SlevomatCodingStandard.Classes.ConstantSpacing">
12+
<properties>
13+
<property name="minLinesCountBeforeWithComment" value="0"/>
14+
</properties>
15+
</rule>
16+
<rule ref="SlevomatCodingStandard.Classes.PropertySpacing">
17+
<properties>
18+
<property name="minLinesCountBeforeWithComment" value="0"/>
19+
</properties>
20+
</rule>
21+
<rule ref="SlevomatCodingStandard.Classes.MethodSpacing">
22+
<properties>
23+
<property name="minLinesCount" value="1"/>
24+
<property name="maxLinesCount" value="2"/>
25+
</properties>
26+
</rule>
27+
528
<rule ref="PSR1.Files.SideEffects.FoundWithSymbols">
629
<exclude-pattern>tests/bootstrap.php</exclude-pattern>
730
</rule>

‎tests/TestCase.php‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
<?php
22

3+
/**
4+
* @link https://www.yiiframework.com/
5+
* @copyright Copyright (c) 2008 Yii Software LLC
6+
* @license https://www.yiiframework.com/license/
7+
*/
8+
39
namespace yiiunit\apidoc;
410

511
use Exception;

‎tests/bootstrap.php‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
<?php
22

3+
/**
4+
* @link https://www.yiiframework.com/
5+
* @copyright Copyright (c) 2008 Yii Software LLC
6+
* @license https://www.yiiframework.com/license/
7+
*/
8+
39
// ensure we get report on all possible php errors
410
error_reporting(-1);
511

0 commit comments

Comments
 (0)