Skip to content

Commit

Permalink
Fix phpdoc, update README.md, clean tests, and update styleci.yml
Browse files Browse the repository at this point in the history
… configuration. (#15)
  • Loading branch information
terabytesoftw authored Jan 23, 2024
1 parent fbfb297 commit cbbe9f8
Show file tree
Hide file tree
Showing 13 changed files with 117 additions and 43 deletions.
34 changes: 34 additions & 0 deletions .github/workflows/ecs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
on:
pull_request:
paths-ignore:
- 'docs/**'
- 'README.md'
- 'CHANGELOG.md'
- '.gitignore'
- '.gitattributes'
- 'infection.json.dist'
- 'phpunit.xml.dist'

push:
branches: ['main']
paths-ignore:
- 'docs/**'
- 'README.md'
- 'CHANGELOG.md'
- '.gitignore'
- '.gitattributes'
- 'infection.json.dist'
- 'phpunit.xml.dist'

name: ecs

jobs:
easy-coding-standard:
uses: php-forge/actions/.github/workflows/ecs.yml@main
secrets:
AUTH_TOKEN: ${{ secrets.AUTH_TOKEN }}
with:
os: >-
['ubuntu-latest']
php: >-
['8.1']
7 changes: 4 additions & 3 deletions .styleci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@ enabled:
- combine_nested_dirname
- declare_strict_types
- dir_constant
- empty_loop_body_braces
- fully_qualified_strict_types
- function_to_constant
- hash_to_slash_comment
- integer_literal_case
- is_null
- logical_operators
- magic_constant_casing
Expand Down Expand Up @@ -56,7 +58,6 @@ enabled:
- phpdoc_order
- phpdoc_property
- phpdoc_scalar
- phpdoc_separation
- phpdoc_singular_inheritdoc
- phpdoc_trim
- phpdoc_trim_consecutive_blank_line_separation
Expand All @@ -78,9 +79,9 @@ enabled:
- trailing_comma_in_multiline_array
- unalign_double_arrow
- unalign_equals
- empty_loop_body_braces
- integer_literal_case
- union_type_without_spaces

disabled:
- function_declaration
- psr12_braces
- psr12_class_definition
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,10 @@ use Yii2\Asset\BootstrapPluginCdnAsset;
BootstrapPluginCdnAsset::register($this);
```

## Testing

[Check the documentation testing](/docs/testing.md) to learn about testing.

## Quality code

[![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)
Expand All @@ -97,10 +101,6 @@ BootstrapPluginCdnAsset::register($this);
[![Yii20](https://img.shields.io/badge/Yii2%20version-2.0-blue)](https://github.com/yiisoft/yii2/tree/2.0.49.3)
[![Yii22](https://img.shields.io/badge/Yii2%20version-2.2-blue)](https://github.com/yiisoft/yii2/tree/2.2)

## Testing

[Check the documentation testing](/docs/testing.md) to learn about testing.

## Our social networks

[![Twitter](https://img.shields.io/badge/twitter-follow-1DA1F2?logo=twitter&logoColor=1DA1F2&labelColor=555555?style=flat)](https://twitter.com/Terabytesoftw)
Expand Down
16 changes: 11 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@
"require-dev": {
"maglnet/composer-require-checker": "^4.7",
"php-forge/support": "^0.1",
"phpunit/phpunit": "^10.5.7",
"phpunit/phpunit": "^10.5",
"roave/infection-static-analysis-plugin": "^1.34",
"symplify/easy-coding-standard": "^12.1",
"yii2-extensions/phpstan": "dev-main"
},
"autoload": {
Expand All @@ -36,16 +37,21 @@
}
},
"config": {
"sort-packages": true,
"allow-plugins": {
"yiisoft/yii2-composer": true,
"infection/extension-installer": true
}
},
"sort-packages": true
},
"scripts": {

"check-dependencies": "composer-require-checker",
"mutation": "roave-infection-static-analysis-plugin",
"phpstan": "phpstan",
"easy-coding-standard": "ecs check",
"mutation": [
"Composer\\Config::disableProcessTimeout",
"roave-infection-static-analysis-plugin"
],
"psalm": "psalm",
"test": "phpunit"
},
"repositories": [
Expand Down
5 changes: 5 additions & 0 deletions docs/testing.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ To run the checker, execute the following command:
composer run check-dependencies
```

## Easy coding standard

The code is checked with [Easy Coding Standard](https://github.com/easy-coding-standard/easy-coding-standard) and
[PHP CS Fixer](https://github.com/PHP-CS-Fixer/PHP-CS-Fixer). To run it:

## Static analysis

The code is statically analyzed with [Phpstan](https://phpstan.org/). To run static analysis:
Expand Down
41 changes: 41 additions & 0 deletions ecs.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php

declare(strict_types=1);

use PhpCsFixer\Fixer\ClassNotation\ClassDefinitionFixer;
use PhpCsFixer\Fixer\ClassNotation\OrderedClassElementsFixer;
use PhpCsFixer\Fixer\ClassNotation\OrderedTraitsFixer;
use PhpCsFixer\Fixer\Import\NoUnusedImportsFixer;
use Symplify\EasyCodingStandard\Config\ECSConfig;

return ECSConfig::configure()
->withConfiguredRule(
ClassDefinitionFixer::class,
[
'space_before_parenthesis' => true,
],
)
->withFileExtensions(['php'])
->withPaths(
[
__DIR__ . '/src',
__DIR__ . '/tests',
],
)
->withPhpCsFixerSets(perCS20: true)
->withPreparedSets(
arrays: true,
cleanCode: true,
comments:true,
docblocks: true,
namespaces: true,
psr12: true,
strict: true
)
->withRules(
[
NoUnusedImportsFixer::class,
OrderedClassElementsFixer::class,
OrderedTraitsFixer::class,
]
);
11 changes: 6 additions & 5 deletions src/BootstrapAsset.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,23 @@

use yii\web\AssetBundle;

use function defined;

/**
* Twitter Bootstrap 5 CSS bundle.
* Twitter Bootstrap5 CSS bundle.
*/
final class BootstrapAsset extends AssetBundle
{
/**
* @inheritDoc
*/
public $sourcePath = '@npm/bootstrap/dist/css';

public function __construct()
{
parent::__construct();

$environment = defined('YII_ENV') ? YII_ENV : 'prod';
$cssFiles = $environment === 'prod' ? 'bootstrap.min.css' : 'bootstrap.css';

$this->css = [$cssFiles];
$this->publishOptions['only'] = [$cssFiles, "{$cssFiles}.map"];
$this->publishOptions['only'] = [$cssFiles, "$cssFiles.map"];
}
}
6 changes: 1 addition & 5 deletions src/BootstrapCdnAsset.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,18 @@
use yii\web\AssetBundle;

/**
* Twitter Bootstrap 5 CDN CSS bundle.
* Twitter Bootstrap5 CDN CSS bundle.
*/
final class BootstrapCdnAsset extends AssetBundle
{
/**
* @inheritDoc
*
* @phpstan-var array<array-key, mixed>
*/
public $css = [
'https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css',
];

/**
* @inheritDoc
*
* @phpstan-var array<array-key, mixed>
*/
public $cssOptions = [
Expand Down
13 changes: 6 additions & 7 deletions src/BootstrapPluginAsset.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,16 @@

use yii\web\AssetBundle;

use function defined;

/**
* Twitter Bootstrap 5 JavaScript bundle.
* Twitter Bootstrap5 JavaScript bundle.
*/
final class BootstrapPluginAsset extends AssetBundle
{
/**
* @inheritDoc
*/
public $sourcePath = '@npm/bootstrap/dist/js';

/**
* @inheritDoc
*
* @phpstan-var array<array-key, mixed>
*/
public $depends = [
Expand All @@ -27,10 +24,12 @@ final class BootstrapPluginAsset extends AssetBundle

public function __construct()
{
parent::__construct();

$environment = defined('YII_ENV') ? YII_ENV : 'prod';
$jsFiles = $environment === 'prod' ? 'bootstrap.bundle.min.js' : 'bootstrap.bundle.js';

$this->js = [$jsFiles];
$this->publishOptions['only'] = [$jsFiles, "{$jsFiles}.map"];
$this->publishOptions['only'] = [$jsFiles, "$jsFiles.map"];
}
}
8 changes: 1 addition & 7 deletions src/BootstrapPluginCdnAsset.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,18 @@
use yii\web\AssetBundle;

/**
* Twitter Bootstrap 5 CDN JavaScript bundle.
* Twitter Bootstrap5 CDN JavaScript bundle.
*/
final class BootstrapPluginCdnAsset extends AssetBundle
{
/**
* @inheritDoc
*
* @phpstan-var array<array-key, mixed>
*/
public $js = [
'https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js',
];

/**
* @inheritDoc
*
* @phpstan-var array<array-key, mixed>
*/
public $jsOptions = [
Expand All @@ -31,8 +27,6 @@ final class BootstrapPluginCdnAsset extends AssetBundle
];

/**
* @inheritDoc
*
* @phpstan-var array<array-key, mixed>
*/
public $depends = [
Expand Down
5 changes: 2 additions & 3 deletions tests/BootstrapAssetTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ public function testRegister(): void
$result = $view->renderFile(__DIR__ . '/Support/main.php');

$this->assertStringContainsString('bootstrap.css', $result);

$this->assertSame(['bootstrap.css'], Yii::$app->assetManager->bundles[BootstrapAsset::class]->css);
$this->assertFileExists(__DIR__ . '/Support/runtime/55145ba9/bootstrap.css');
$this->assertFileExists(__DIR__ . '/Support/runtime/55145ba9/bootstrap.css.map');
Expand All @@ -42,7 +41,7 @@ public function testRegister(): void
#[RequiresPhp('8.1')]
public function testRegisterWithEnvironmentProd(): void
{
runkit_constant_redefine('YII_ENV', 'prod');
@runkit_constant_redefine('YII_ENV', 'prod');

$view = new View();

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

runkit_constant_redefine('YII_ENV', 'dev');
@runkit_constant_redefine('YII_ENV', 'dev');
}
}
2 changes: 0 additions & 2 deletions tests/BootstrapPluginAssetTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ public function testRegister(): void
$result = $view->renderFile(__DIR__ . '/Support/main.php');

$this->assertStringContainsString('bootstrap.bundle.js', $result);

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

$this->assertStringContainsString('bootstrap.bundle.min.js', $result);

$this->assertSame(['bootstrap.bundle.min.js'], Yii::$app->assetManager->bundles[BootstrapPluginAsset::class]->js);
$this->assertFileExists(__DIR__ . '/Support/runtime/16b8de20/bootstrap.bundle.min.js');
$this->assertFileExists(__DIR__ . '/Support/runtime/16b8de20/bootstrap.bundle.min.js.map');
Expand Down
4 changes: 2 additions & 2 deletions tests/Support/main.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?php
/* @var $this \yii\web\View */
<?php declare(strict_types=1);
/** @var \yii\web\View $this */
?>
<?php $this->beginPage();?>1<?php $this->head();?>2<?php $this->beginBody();?>3<?php $this->endBody();?>4<?php $this->endPage();

0 comments on commit cbbe9f8

Please sign in to comment.