From f641e889030cf785818ca33b99a33efb4fc554a1 Mon Sep 17 00:00:00 2001 From: Wilmer Arambula Date: Wed, 28 Feb 2024 04:35:03 -0300 Subject: [PATCH] Prepare for first release. --- .github/workflows/ecs.yml | 34 ++++++++++++ .styleci.yml | 7 ++- CHANGELOG.md | 3 + LICENSE | 27 ++++----- README.md | 14 ++--- changelog.md | 2 - composer.json | 39 +++++-------- docs/test.html | 47 ++++++++++++++++ docs/testing.md | 17 ++++++ ecs.php | 39 +++++++++++++ infection.log | 11 ++++ phpstan-yii-config.php => phpstan-config.php | 0 phpstan.neon | 2 +- phpunit.xml.dist | 38 ++++++------- src/Asset/DateTimePickerAsset.php | 23 +++----- src/Asset/DateTimePickerCdnAsset.php | 2 - src/DateTimePicker.php | 34 ++++++++---- tests/AssetTest.php | 27 ++++++--- tests/DateTimePickerTest.php | 58 ++++++++++++++------ tests/TestCase.php | 9 +-- 20 files changed, 301 insertions(+), 132 deletions(-) create mode 100644 .github/workflows/ecs.yml create mode 100644 CHANGELOG.md delete mode 100644 changelog.md create mode 100644 docs/test.html create mode 100644 ecs.php create mode 100644 infection.log rename phpstan-yii-config.php => phpstan-config.php (100%) diff --git a/.github/workflows/ecs.yml b/.github/workflows/ecs.yml new file mode 100644 index 0000000..dff0db6 --- /dev/null +++ b/.github/workflows/ecs.yml @@ -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'] diff --git a/.styleci.yml b/.styleci.yml index 5b7ddb2..6f428b6 100644 --- a/.styleci.yml +++ b/.styleci.yml @@ -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 @@ -56,7 +58,6 @@ enabled: - phpdoc_order - phpdoc_property - phpdoc_scalar - - phpdoc_separation - phpdoc_singular_inheritdoc - phpdoc_trim - phpdoc_trim_consecutive_blank_line_separation @@ -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 diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..e8ec381 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,3 @@ +# Change Log + +## 0.1.0 February 28, 2024 diff --git a/LICENSE b/LICENSE index d89684f..136b000 100644 --- a/LICENSE +++ b/LICENSE @@ -1,21 +1,16 @@ MIT License -Copyright (c) 2023 yii2-extensions +Copyright (c) 2024 by Wilmer Arámbula (https://github.com/terabytesoftw) All rights reserved. -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated +documentation files (the "Software"), to deal in the Software without restriction, including without limitation the +rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit +persons to whom the Software is furnished to do so, subject to the following conditions: -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the +Software. -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE +WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR +COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR +OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/README.md b/README.md index e794425..06f9d53 100644 --- a/README.md +++ b/README.md @@ -36,17 +36,17 @@ The preferred way to install this extension is through [composer](https://getcom Either run -``` -composer require --dev --prefer-dist yii2-extensions/datetime-picker +```shell +composer require --dev --prefer-dist yii2-extensions/datetime-picker:^0.1 ``` or add -``` -"yii2-extensions/datetime-picker": "dev-main" +```json +"yii2-extensions/datetime-picker": "^0.1" ``` -to the require-dev section of your `composer.json` file. +to the require section of your `composer.json` file. ## Usage @@ -158,7 +158,7 @@ for default the extension supports the following languages. ## Testing -[Check the documentation testing](/docs/testing.md) to learn about testing. +[Check the documentation testing](docs/testing.md) to learn about testing. ## Our social networks @@ -166,4 +166,4 @@ for default the extension supports the following languages. ## License -The MIT License. Please see [License File](LICENSE.md) for more information. +The MIT License. Please see [License File](LICENSE) for more information. diff --git a/changelog.md b/changelog.md deleted file mode 100644 index 9a203e1..0000000 --- a/changelog.md +++ /dev/null @@ -1,2 +0,0 @@ -Change Log -========== diff --git a/composer.json b/composer.json index b5097ac..2466800 100644 --- a/composer.json +++ b/composer.json @@ -9,22 +9,20 @@ "picker" ], "license": "mit", - "minimum-stability": "dev", - "prefer-stable": true, "require": { "php": ">=8.1", - "npm-asset/eonasdan--tempus-dominus": "^6.7", - "oomphinc/composer-installers-extender": "^2.0", - "php-forge/html": "dev-main", - "yii2-extensions/asset-popper": "dev-main", - "yiisoft/yii2": "^2.2" + "npm-asset/eonasdan--tempus-dominus": "^6.9", + "php-forge/html": "^0.2", + "yii2-extensions/asset-popper": "^0.1", + "yiisoft/yii2": "^2.0.49 || ^2.2" }, "require-dev": { - "maglnet/composer-require-checker": "^4.6", - "php-forge/support": "dev-main", - "phpunit/phpunit": "10.5.3", + "maglnet/composer-require-checker": "^4.7", + "php-forge/support": "^0.1", + "phpunit/phpunit": "^10.5", "roave/infection-static-analysis-plugin": "^1.34", - "yii2-extensions/phpstan": "dev-main" + "symplify/easy-coding-standard": "^12.1", + "yii2-extensions/phpstan": "^0.1" }, "autoload": { "psr-4": { @@ -38,7 +36,7 @@ }, "extra": { "branch-alias": { - "dev-main": "1.0.x-dev" + "dev-main": "0.1-dev" }, "config-plugin": { "params": "params.php", @@ -46,16 +44,6 @@ }, "config-plugin-options": { "source-directory": "config" - }, - "installer-types": [ - "bower-asset", - "npm-asset" - ], - "installer-paths": { - "./node_modules/{$name}": [ - "type:bower-asset", - "type:npm-asset" - ] } }, "config": { @@ -63,13 +51,16 @@ "allow-plugins": { "yiisoft/yii2-composer": true, "composer/installers": true, - "oomphinc/composer-installers-extender": true, "infection/extension-installer": true } }, "scripts": { "check-dependencies": "composer-require-checker", - "mutation": "roave-infection-static-analysis-plugin", + "easy-coding-standard": "ecs check", + "mutation": [ + "Composer\\Config::disableProcessTimeout", + "roave-infection-static-analysis-plugin" + ], "phpstan": "phpstan", "test": "phpunit" }, diff --git a/docs/test.html b/docs/test.html new file mode 100644 index 0000000..ad39e24 --- /dev/null +++ b/docs/test.html @@ -0,0 +1,47 @@ + + + + + + + + + + + + + + + + +
+ + + + + + + +
El formato de Date es inválido.
+
+ + + + + + + + + + + + + diff --git a/docs/testing.md b/docs/testing.md index 46a4946..6b5902a 100644 --- a/docs/testing.md +++ b/docs/testing.md @@ -10,6 +10,23 @@ 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: + +```shell +composer run ecs +``` + +## Mutation testing + +Mutation testing is checked with [Infection](https://infection.github.io/). To run it: + +```shell +composer run mutation +``` + ## Static analysis The code is statically analyzed with [Phpstan](https://phpstan.org/). To run static analysis: diff --git a/ecs.php b/ecs.php new file mode 100644 index 0000000..d360125 --- /dev/null +++ b/ecs.php @@ -0,0 +1,39 @@ +withConfiguredRule( + ClassDefinitionFixer::class, + [ + 'space_before_parenthesis' => true, + ], + ) + ->withFileExtensions(['php']) + ->withPaths( + [ + __DIR__ . '/src', + __DIR__ . '/tests', + ], + ) + ->withPhpCsFixerSets(perCS20: true) + ->withPreparedSets( + cleanCode: true, + comments:true, + docblocks: true, + namespaces: true, + psr12: true + ) + ->withRules( + [ + NoUnusedImportsFixer::class, + OrderedClassElementsFixer::class, + OrderedTraitsFixer::class, + ] + ); diff --git a/infection.log b/infection.log new file mode 100644 index 0000000..d874a4b --- /dev/null +++ b/infection.log @@ -0,0 +1,11 @@ +Escaped mutants: +================ + +Timed Out mutants: +================== + +Skipped mutants: +================ + +Not Covered mutants: +==================== diff --git a/phpstan-yii-config.php b/phpstan-config.php similarity index 100% rename from phpstan-yii-config.php rename to phpstan-config.php diff --git a/phpstan.neon b/phpstan.neon index 6719314..aa0b8cd 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -17,5 +17,5 @@ parameters: - vendor/yiisoft/yii2/Yii.php yii2: - config_path: %currentWorkingDirectory%/phpstan-yii-config.php + config_path: %currentWorkingDirectory%/phpstan-config.php diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 4245edd..c7f072f 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,24 +1,24 @@ - - - tests - - + + + tests + + - - - ./src - - + + + ./src + + diff --git a/src/Asset/DateTimePickerAsset.php b/src/Asset/DateTimePickerAsset.php index b00b107..bd54ae4 100644 --- a/src/Asset/DateTimePickerAsset.php +++ b/src/Asset/DateTimePickerAsset.php @@ -12,32 +12,25 @@ */ final class DateTimePickerAsset extends AssetBundle { - /** - * @inheritDoc - */ public $sourcePath = '@npm/eonasdan--tempus-dominus/dist'; /** - * @inheritDoc - * * @phpstan-var array */ public $depends = [ PopperAsset::class, ]; - public function init(): void + public function __construct() { - parent::init(); + parent::__construct(); - $this->css = YII_ENV === 'prod' ? ['css/tempus-dominus.min.css'] : ['css/tempus-dominus.css']; - $this->js = YII_ENV === 'prod' - ? ['js/tempus-dominus.min.js', 'js/jQuery-provider.min.js'] : ['js/tempus-dominus.js', 'js/jQuery-provider.js']; + $environment = defined('YII_ENV') ? YII_ENV : 'prod'; + $cssFiles = $environment === 'prod' ? 'css/tempus-dominus.min.css' : 'css/tempus-dominus.css'; + $jsFiles = $environment === 'prod' ? 'js/tempus-dominus.min.js' : 'js/tempus-dominus.js'; - $this->publishOptions['only'] = array_merge( - $this->css, - YII_ENV === 'prod' ? [] : ['css/bootstrap.js.map', 'js/bootstrap.js.map'], - $this->js, - ); + $this->css = [$cssFiles]; + $this->js = [$jsFiles]; + $this->publishOptions['only'] = [$cssFiles, "$cssFiles.map", $jsFiles, "$jsFiles.map"]; } } diff --git a/src/Asset/DateTimePickerCdnAsset.php b/src/Asset/DateTimePickerCdnAsset.php index b7f230d..f3a797e 100644 --- a/src/Asset/DateTimePickerCdnAsset.php +++ b/src/Asset/DateTimePickerCdnAsset.php @@ -13,8 +13,6 @@ final class DateTimePickerCdnAsset extends AssetBundle { /** - * @inheritDoc - * * @phpstan-var array */ public $depends = [ diff --git a/src/DateTimePicker.php b/src/DateTimePicker.php index 15a4e42..af16229 100644 --- a/src/DateTimePicker.php +++ b/src/DateTimePicker.php @@ -5,15 +5,9 @@ namespace Yii2\Extensions\DateTimePicker; use JsonException; -use PHPForge\Html\Div; -use PHPForge\Html\Helper\CssClass; -use PHPForge\Html\Input\Text; -use PHPForge\Html\Label; -use PHPForge\Html\Span; +use PHPForge\Html\{Group\Div, Helper\CssClass, FormControl\Input\Text, FormControl\Label, Textual\Span}; use Yii; -use yii\base\InvalidConfigException; -use yii\helpers\Html; -use yii\widgets\InputWidget; +use yii\{base\InvalidConfigException, helpers\Html, widgets\InputWidget}; final class DateTimePicker extends InputWidget { @@ -84,7 +78,7 @@ public function init(): void } /** - * @inheritdoc + * @throws JsonException */ public function run(): string { @@ -141,10 +135,21 @@ private function renderDateTimePicker(): string ->class($this->labelClass) ->content(Yii::t('yii2.extensions.datetime.picker', $this->labelContent)); $span = Span::widget() - ->dataAttributes(['td-target' => "#$this->id", 'td-toggle' => 'datetimepicker']) + ->dataAttributes( + [ + 'td-target' => "#$this->id", + 'td-toggle' => 'datetimepicker', + ] + ) ->class($this->spanClass) ->content($this->icon); - $input = Text::widget()->attributes($this->options)->dataAttributes(['td-target' => "#$this->id"]); + $input = Text::widget() + ->attributes($this->options) + ->dataAttributes( + [ + 'td-target' => "#$this->id", + ] + ); $input = match ($this->hasModel()) { true => $input @@ -166,7 +171,12 @@ private function renderDateTimePicker(): string $div = Div::widget() ->attributes($containerOptions) ->content($content) - ->dataAttributes(['td-target-input' => 'nearest', 'td-target-toggle' => 'nearest']) + ->dataAttributes( + [ + 'td-target-input' => 'nearest', + 'td-target-toggle' => 'nearest', + ] + ) ->id($this->id) ->render(); diff --git a/tests/AssetTest.php b/tests/AssetTest.php index 98bd765..86133ae 100644 --- a/tests/AssetTest.php +++ b/tests/AssetTest.php @@ -4,11 +4,8 @@ namespace Yii2\Extensions\DateTimePicker\Tests; -use Yii2\Asset\PopperAsset; -use Yii2\Asset\PopperCdnAsset; -use Yii2\Extensions\DateTimePicker\Asset\DateTimePickerAsset; -use Yii2\Extensions\DateTimePicker\Asset\DateTimePickerCdnAsset; -use Yii2\Extensions\DateTimePicker\DateTimePicker; +use Yii2\Asset\{PopperAsset, PopperCdnAsset}; +use Yii2\Extensions\DateTimePicker\{Asset\DateTimePickerAsset, Asset\DateTimePickerCdnAsset, DateTimePicker}; use Yii; use yii\web\AssetBundle; @@ -46,12 +43,18 @@ public function testDateTimePickerAssetRegister(): void $result = $this->view->renderFile( __DIR__ . '/Support/main.php', - ['widget' => DateTimePicker::widget(['name' => 'tags', 'id' => 'tests-id'])], + [ + 'widget' => DateTimePicker::widget( + [ + 'name' => 'tags', + 'id' => 'tests-id', + ] + ), + ], ); $this->assertStringContainsString('css/tempus-dominus.css', $result); $this->assertStringContainsString('js/tempus-dominus.js', $result); - $this->assertStringContainsString('js/jQuery-provider.js', $result); $this->assertStringContainsString('jquery.js', $result); } @@ -77,7 +80,15 @@ public function testDateTimePickerCdnAssetRegister(): void $result = $this->view->renderFile( __DIR__ . '/Support/main.php', - ['widget' => DateTimePicker::widget(['cdn' => true, 'id' => 'tests-id', 'name' => 'tags'])], + [ + 'widget' => DateTimePicker::widget( + [ + 'cdn' => true, + 'id' => 'tests-id', + 'name' => 'tags', + ] + ), + ], ); $this->assertStringContainsString( diff --git a/tests/DateTimePickerTest.php b/tests/DateTimePickerTest.php index 47813ce..cd33808 100644 --- a/tests/DateTimePickerTest.php +++ b/tests/DateTimePickerTest.php @@ -4,10 +4,8 @@ namespace Yii2\Extensions\DateTimePicker\Tests; -use PHPForge\Html\I; -use PHPForge\Support\Assert; -use Yii2\Extensions\DateTimePicker\DateTimePicker; -use Yii2\Extensions\DateTimePicker\Tests\Support\DateTimePickerModel; +use PHPForge\{Html\Textual\I, Support\Assert}; +use Yii2\Extensions\DateTimePicker\{DateTimePicker, Tests\Support\DateTimePickerModel}; use Yii; final class DateTimePickerTest extends TestCase @@ -32,7 +30,9 @@ public function testContainerClass(): void ], ); - $render = $this->view->renderFile(__DIR__ . '/Support/main.php', ['widget' => $dateTimePicker]); + $render = $this->view->renderFile(__DIR__ . '/Support/main.php', [ + 'widget' => $dateTimePicker, + ]); Assert::equalsWithoutLE( <<view->renderFile(__DIR__ . '/Support/main.php', ['widget' => $dateTimePicker]); + $render = $this->view->renderFile(__DIR__ . '/Support/main.php', [ + 'widget' => $dateTimePicker, + ]); Assert::equalsWithoutLE( <<view->renderFile(__DIR__ . '/Support/main.php', ['widget' => $dateTimePicker]); + $render = $this->view->renderFile(__DIR__ . '/Support/main.php', [ + 'widget' => $dateTimePicker, + ]); Assert::equalsWithoutLE( <<view->renderFile(__DIR__ . '/Support/main.php', ['widget' => $dateTimePicker]); + $render = $this->view->renderFile(__DIR__ . '/Support/main.php', [ + 'widget' => $dateTimePicker, + ]); Assert::equalsWithoutLE( <<view->renderFile(__DIR__ . '/Support/main.php', ['widget' => $dateTimePicker]); + $render = $this->view->renderFile(__DIR__ . '/Support/main.php', [ + 'widget' => $dateTimePicker, + ]); Assert::equalsWithoutLE( <<view->renderFile(__DIR__ . '/Support/main.php', ['widget' => $dateTimePicker]); + $render = $this->view->renderFile(__DIR__ . '/Support/main.php', [ + 'widget' => $dateTimePicker, + ]); Assert::equalsWithoutLE( <<view->renderFile(__DIR__ . '/Support/main.php', ['widget' => $dateTimePicker]); + $render = $this->view->renderFile(__DIR__ . '/Support/main.php', [ + 'widget' => $dateTimePicker, + ]); Assert::equalsWithoutLE( <<view->renderFile(__DIR__ . '/Support/main.php', ['widget' => $dateTimePicker]); + $render = $this->view->renderFile(__DIR__ . '/Support/main.php', [ + 'widget' => $dateTimePicker, + ]); Assert::equalsWithoutLE( <<view->renderFile(__DIR__ . '/Support/main.php', ['widget' => $dateTimePicker]); + $render = $this->view->renderFile(__DIR__ . '/Support/main.php', [ + 'widget' => $dateTimePicker, + ]); Assert::equalsWithoutLE( <<view->renderFile(__DIR__ . '/Support/main.php', ['widget' => $dateTimePicker]); + $render = $this->view->renderFile(__DIR__ . '/Support/main.php', [ + 'widget' => $dateTimePicker, + ]); Assert::equalsWithoutLE( <<view->renderFile(__DIR__ . '/Support/main.php', ['widget' => $dateTimePicker]); + $render = $this->view->renderFile(__DIR__ . '/Support/main.php', [ + 'widget' => $dateTimePicker, + ]); Assert::equalsWithoutLE( <<view->renderFile(__DIR__ . '/Support/main.php', ['widget' => $dateTimePicker]); + $render = $this->view->renderFile(__DIR__ . '/Support/main.php', [ + 'widget' => $dateTimePicker, + ]); Assert::equalsWithoutLE( <<view->renderFile(__DIR__ . '/Support/main.php', ['widget' => $dateTimePicker]); + $render = $this->view->renderFile(__DIR__ . '/Support/main.php', [ + 'widget' => $dateTimePicker, + ]); Assert::equalsWithoutLE( << 'testapp', 'aliases' => [ '@root' => dirname(__DIR__), - '@bower' => '@root/node_modules', - '@npm' => '@root/node_modules', + '@bower' => '@vendor/bower-asset', + '@npm' => '@vendor/npm-asset', ], 'basePath' => dirname(__DIR__), 'components' => [