Skip to content

Commit cbbe9f8

Browse files
Fix phpdoc, update README.md, clean tests, and update styleci.yml configuration. (#15)
1 parent fbfb297 commit cbbe9f8

13 files changed

+117
-43
lines changed

.github/workflows/ecs.yml

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
on:
2+
pull_request:
3+
paths-ignore:
4+
- 'docs/**'
5+
- 'README.md'
6+
- 'CHANGELOG.md'
7+
- '.gitignore'
8+
- '.gitattributes'
9+
- 'infection.json.dist'
10+
- 'phpunit.xml.dist'
11+
12+
push:
13+
branches: ['main']
14+
paths-ignore:
15+
- 'docs/**'
16+
- 'README.md'
17+
- 'CHANGELOG.md'
18+
- '.gitignore'
19+
- '.gitattributes'
20+
- 'infection.json.dist'
21+
- 'phpunit.xml.dist'
22+
23+
name: ecs
24+
25+
jobs:
26+
easy-coding-standard:
27+
uses: php-forge/actions/.github/workflows/ecs.yml@main
28+
secrets:
29+
AUTH_TOKEN: ${{ secrets.AUTH_TOKEN }}
30+
with:
31+
os: >-
32+
['ubuntu-latest']
33+
php: >-
34+
['8.1']

.styleci.yml

+4-3
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,11 @@ enabled:
1717
- combine_nested_dirname
1818
- declare_strict_types
1919
- dir_constant
20+
- empty_loop_body_braces
2021
- fully_qualified_strict_types
2122
- function_to_constant
2223
- hash_to_slash_comment
24+
- integer_literal_case
2325
- is_null
2426
- logical_operators
2527
- magic_constant_casing
@@ -56,7 +58,6 @@ enabled:
5658
- phpdoc_order
5759
- phpdoc_property
5860
- phpdoc_scalar
59-
- phpdoc_separation
6061
- phpdoc_singular_inheritdoc
6162
- phpdoc_trim
6263
- phpdoc_trim_consecutive_blank_line_separation
@@ -78,9 +79,9 @@ enabled:
7879
- trailing_comma_in_multiline_array
7980
- unalign_double_arrow
8081
- unalign_equals
81-
- empty_loop_body_braces
82-
- integer_literal_case
8382
- union_type_without_spaces
8483

8584
disabled:
8685
- function_declaration
86+
- psr12_braces
87+
- psr12_class_definition

README.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,10 @@ use Yii2\Asset\BootstrapPluginCdnAsset;
8686
BootstrapPluginCdnAsset::register($this);
8787
```
8888

89+
## Testing
90+
91+
[Check the documentation testing](/docs/testing.md) to learn about testing.
92+
8993
## Quality code
9094

9195
[![static-analysis](https://github.com/yii2-extensions/asset-bootstrap5/actions/workflows/static.yml/badge.svg)](https://github.com/yii2-extensions/asset-bootstrap5/actions/workflows/static.yml)
@@ -97,10 +101,6 @@ BootstrapPluginCdnAsset::register($this);
97101
[![Yii20](https://img.shields.io/badge/Yii2%20version-2.0-blue)](https://github.com/yiisoft/yii2/tree/2.0.49.3)
98102
[![Yii22](https://img.shields.io/badge/Yii2%20version-2.2-blue)](https://github.com/yiisoft/yii2/tree/2.2)
99103

100-
## Testing
101-
102-
[Check the documentation testing](/docs/testing.md) to learn about testing.
103-
104104
## Our social networks
105105

106106
[![Twitter](https://img.shields.io/badge/twitter-follow-1DA1F2?logo=twitter&logoColor=1DA1F2&labelColor=555555?style=flat)](https://twitter.com/Terabytesoftw)

composer.json

+11-5
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,9 @@
1616
"require-dev": {
1717
"maglnet/composer-require-checker": "^4.7",
1818
"php-forge/support": "^0.1",
19-
"phpunit/phpunit": "^10.5.7",
19+
"phpunit/phpunit": "^10.5",
2020
"roave/infection-static-analysis-plugin": "^1.34",
21+
"symplify/easy-coding-standard": "^12.1",
2122
"yii2-extensions/phpstan": "dev-main"
2223
},
2324
"autoload": {
@@ -36,16 +37,21 @@
3637
}
3738
},
3839
"config": {
39-
"sort-packages": true,
4040
"allow-plugins": {
4141
"yiisoft/yii2-composer": true,
4242
"infection/extension-installer": true
43-
}
43+
},
44+
"sort-packages": true
4445
},
4546
"scripts": {
47+
4648
"check-dependencies": "composer-require-checker",
47-
"mutation": "roave-infection-static-analysis-plugin",
48-
"phpstan": "phpstan",
49+
"easy-coding-standard": "ecs check",
50+
"mutation": [
51+
"Composer\\Config::disableProcessTimeout",
52+
"roave-infection-static-analysis-plugin"
53+
],
54+
"psalm": "psalm",
4955
"test": "phpunit"
5056
},
5157
"repositories": [

docs/testing.md

+5
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@ To run the checker, execute the following command:
1010
composer run check-dependencies
1111
```
1212

13+
## Easy coding standard
14+
15+
The code is checked with [Easy Coding Standard](https://github.com/easy-coding-standard/easy-coding-standard) and
16+
[PHP CS Fixer](https://github.com/PHP-CS-Fixer/PHP-CS-Fixer). To run it:
17+
1318
## Static analysis
1419

1520
The code is statically analyzed with [Phpstan](https://phpstan.org/). To run static analysis:

ecs.php

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
use PhpCsFixer\Fixer\ClassNotation\ClassDefinitionFixer;
6+
use PhpCsFixer\Fixer\ClassNotation\OrderedClassElementsFixer;
7+
use PhpCsFixer\Fixer\ClassNotation\OrderedTraitsFixer;
8+
use PhpCsFixer\Fixer\Import\NoUnusedImportsFixer;
9+
use Symplify\EasyCodingStandard\Config\ECSConfig;
10+
11+
return ECSConfig::configure()
12+
->withConfiguredRule(
13+
ClassDefinitionFixer::class,
14+
[
15+
'space_before_parenthesis' => true,
16+
],
17+
)
18+
->withFileExtensions(['php'])
19+
->withPaths(
20+
[
21+
__DIR__ . '/src',
22+
__DIR__ . '/tests',
23+
],
24+
)
25+
->withPhpCsFixerSets(perCS20: true)
26+
->withPreparedSets(
27+
arrays: true,
28+
cleanCode: true,
29+
comments:true,
30+
docblocks: true,
31+
namespaces: true,
32+
psr12: true,
33+
strict: true
34+
)
35+
->withRules(
36+
[
37+
NoUnusedImportsFixer::class,
38+
OrderedClassElementsFixer::class,
39+
OrderedTraitsFixer::class,
40+
]
41+
);

src/BootstrapAsset.php

+6-5
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,23 @@
66

77
use yii\web\AssetBundle;
88

9+
use function defined;
10+
911
/**
10-
* Twitter Bootstrap 5 CSS bundle.
12+
* Twitter Bootstrap5 CSS bundle.
1113
*/
1214
final class BootstrapAsset extends AssetBundle
1315
{
14-
/**
15-
* @inheritDoc
16-
*/
1716
public $sourcePath = '@npm/bootstrap/dist/css';
1817

1918
public function __construct()
2019
{
20+
parent::__construct();
21+
2122
$environment = defined('YII_ENV') ? YII_ENV : 'prod';
2223
$cssFiles = $environment === 'prod' ? 'bootstrap.min.css' : 'bootstrap.css';
2324

2425
$this->css = [$cssFiles];
25-
$this->publishOptions['only'] = [$cssFiles, "{$cssFiles}.map"];
26+
$this->publishOptions['only'] = [$cssFiles, "$cssFiles.map"];
2627
}
2728
}

src/BootstrapCdnAsset.php

+1-5
Original file line numberDiff line numberDiff line change
@@ -7,22 +7,18 @@
77
use yii\web\AssetBundle;
88

99
/**
10-
* Twitter Bootstrap 5 CDN CSS bundle.
10+
* Twitter Bootstrap5 CDN CSS bundle.
1111
*/
1212
final class BootstrapCdnAsset extends AssetBundle
1313
{
1414
/**
15-
* @inheritDoc
16-
*
1715
* @phpstan-var array<array-key, mixed>
1816
*/
1917
public $css = [
2018
'https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css',
2119
];
2220

2321
/**
24-
* @inheritDoc
25-
*
2622
* @phpstan-var array<array-key, mixed>
2723
*/
2824
public $cssOptions = [

src/BootstrapPluginAsset.php

+6-7
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,16 @@
66

77
use yii\web\AssetBundle;
88

9+
use function defined;
10+
911
/**
10-
* Twitter Bootstrap 5 JavaScript bundle.
12+
* Twitter Bootstrap5 JavaScript bundle.
1113
*/
1214
final class BootstrapPluginAsset extends AssetBundle
1315
{
14-
/**
15-
* @inheritDoc
16-
*/
1716
public $sourcePath = '@npm/bootstrap/dist/js';
1817

1918
/**
20-
* @inheritDoc
21-
*
2219
* @phpstan-var array<array-key, mixed>
2320
*/
2421
public $depends = [
@@ -27,10 +24,12 @@ final class BootstrapPluginAsset extends AssetBundle
2724

2825
public function __construct()
2926
{
27+
parent::__construct();
28+
3029
$environment = defined('YII_ENV') ? YII_ENV : 'prod';
3130
$jsFiles = $environment === 'prod' ? 'bootstrap.bundle.min.js' : 'bootstrap.bundle.js';
3231

3332
$this->js = [$jsFiles];
34-
$this->publishOptions['only'] = [$jsFiles, "{$jsFiles}.map"];
33+
$this->publishOptions['only'] = [$jsFiles, "$jsFiles.map"];
3534
}
3635
}

src/BootstrapPluginCdnAsset.php

+1-7
Original file line numberDiff line numberDiff line change
@@ -7,22 +7,18 @@
77
use yii\web\AssetBundle;
88

99
/**
10-
* Twitter Bootstrap 5 CDN JavaScript bundle.
10+
* Twitter Bootstrap5 CDN JavaScript bundle.
1111
*/
1212
final class BootstrapPluginCdnAsset extends AssetBundle
1313
{
1414
/**
15-
* @inheritDoc
16-
*
1715
* @phpstan-var array<array-key, mixed>
1816
*/
1917
public $js = [
2018
'https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js',
2119
];
2220

2321
/**
24-
* @inheritDoc
25-
*
2622
* @phpstan-var array<array-key, mixed>
2723
*/
2824
public $jsOptions = [
@@ -31,8 +27,6 @@ final class BootstrapPluginCdnAsset extends AssetBundle
3127
];
3228

3329
/**
34-
* @inheritDoc
35-
*
3630
* @phpstan-var array<array-key, mixed>
3731
*/
3832
public $depends = [

tests/BootstrapAssetTest.php

+2-3
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ public function testRegister(): void
3131
$result = $view->renderFile(__DIR__ . '/Support/main.php');
3232

3333
$this->assertStringContainsString('bootstrap.css', $result);
34-
3534
$this->assertSame(['bootstrap.css'], Yii::$app->assetManager->bundles[BootstrapAsset::class]->css);
3635
$this->assertFileExists(__DIR__ . '/Support/runtime/55145ba9/bootstrap.css');
3736
$this->assertFileExists(__DIR__ . '/Support/runtime/55145ba9/bootstrap.css.map');
@@ -42,7 +41,7 @@ public function testRegister(): void
4241
#[RequiresPhp('8.1')]
4342
public function testRegisterWithEnvironmentProd(): void
4443
{
45-
runkit_constant_redefine('YII_ENV', 'prod');
44+
@runkit_constant_redefine('YII_ENV', 'prod');
4645

4746
$view = new View();
4847

@@ -63,6 +62,6 @@ public function testRegisterWithEnvironmentProd(): void
6362
$this->assertFileDoesNotExist(__DIR__ . '/Support/runtime/55145ba9/bootstrap.css');
6463
$this->assertFileDoesNotExist(__DIR__ . '/Support/runtime/55145ba9/bootstrap.css.map');
6564

66-
runkit_constant_redefine('YII_ENV', 'dev');
65+
@runkit_constant_redefine('YII_ENV', 'dev');
6766
}
6867
}

tests/BootstrapPluginAssetTest.php

-2
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ public function testRegister(): void
3333
$result = $view->renderFile(__DIR__ . '/Support/main.php');
3434

3535
$this->assertStringContainsString('bootstrap.bundle.js', $result);
36-
3736
$this->assertSame(['bootstrap.bundle.js'], Yii::$app->assetManager->bundles[BootstrapPluginAsset::class]->js);
3837
$this->assertFileExists(__DIR__ . '/Support/runtime/16b8de20/bootstrap.bundle.js');
3938
$this->assertFileExists(__DIR__ . '/Support/runtime/16b8de20/bootstrap.bundle.js.map');
@@ -59,7 +58,6 @@ public function testRegisterWithEnvironmentProd(): void
5958
$result = $view->renderFile(__DIR__ . '/Support/main.php');
6059

6160
$this->assertStringContainsString('bootstrap.bundle.min.js', $result);
62-
6361
$this->assertSame(['bootstrap.bundle.min.js'], Yii::$app->assetManager->bundles[BootstrapPluginAsset::class]->js);
6462
$this->assertFileExists(__DIR__ . '/Support/runtime/16b8de20/bootstrap.bundle.min.js');
6563
$this->assertFileExists(__DIR__ . '/Support/runtime/16b8de20/bootstrap.bundle.min.js.map');

tests/Support/main.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<?php
2-
/* @var $this \yii\web\View */
1+
<?php declare(strict_types=1);
2+
/** @var \yii\web\View $this */
33
?>
44
<?php $this->beginPage();?>1<?php $this->head();?>2<?php $this->beginBody();?>3<?php $this->endBody();?>4<?php $this->endPage();

0 commit comments

Comments
 (0)