From cf5fd7b099282172c58fb68ff4b26256362355b1 Mon Sep 17 00:00:00 2001 From: Sergei Predvoditelev Date: Fri, 8 May 2026 14:33:49 +0300 Subject: [PATCH 1/2] Replace StyleCI to PHP CS Fixer --- .gitattributes | 2 +- .github/workflows/rector-cs.yml | 24 ++++++ .github/workflows/rector.yml | 24 ------ .gitignore | 3 + .php-cs-fixer.dist.php | 21 +++++ .styleci.yml | 85 ------------------- composer.json | 4 + src/ConcurrentAssignmentsStorageDecorator.php | 6 +- src/ConcurrentItemsStorageDecorator.php | 6 +- src/FileStorageTrait.php | 6 +- tests/AssignmentsStorageTest.php | 2 +- ...mentsStorageWithConcurrencyHandledTest.php | 2 + ...nmentsStorageWithConcurrencyNotHandled.php | 2 + tests/ItemsStorage/ItemsStorageTest.php | 6 +- ...ItemsStorageWithConcurrencyHandledTest.php | 2 + ...msStorageWithConcurrencyNotHandledTest.php | 2 + tests/StorageFilePathTrait.php | 2 + tests/Support/TestHelper.php | 6 +- 18 files changed, 81 insertions(+), 124 deletions(-) create mode 100644 .github/workflows/rector-cs.yml delete mode 100644 .github/workflows/rector.yml create mode 100644 .php-cs-fixer.dist.php delete mode 100644 .styleci.yml diff --git a/.gitattributes b/.gitattributes index d2354a6..7da0696 100644 --- a/.gitattributes +++ b/.gitattributes @@ -26,8 +26,8 @@ /.editorconfig export-ignore /.gitattributes export-ignore /.gitignore export-ignore +/.php-cs-fixer.dist.php export-ignore /.phpunit-watcher.yml export-ignore -/.styleci.yml export-ignore /infection.json.dist export-ignore /phpunit.xml.dist export-ignore /psalm.xml export-ignore diff --git a/.github/workflows/rector-cs.yml b/.github/workflows/rector-cs.yml new file mode 100644 index 0000000..8806605 --- /dev/null +++ b/.github/workflows/rector-cs.yml @@ -0,0 +1,24 @@ +name: Rector + PHP CS Fixer + +on: + pull_request: + paths: + - 'src/**' + - 'tests/**' + - '.github/workflows/rector-cs.yml' + - 'composer.json' + - 'rector.php' + - '.php-cs-fixer.dist.php' + +permissions: + contents: write + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +jobs: + rector: + uses: yiisoft/actions/.github/workflows/rector-cs.yml@master + with: + php: '8.1' diff --git a/.github/workflows/rector.yml b/.github/workflows/rector.yml deleted file mode 100644 index 5d6931d..0000000 --- a/.github/workflows/rector.yml +++ /dev/null @@ -1,24 +0,0 @@ -on: - pull_request_target: - paths-ignore: - - 'docs/**' - - 'README.md' - - 'CHANGELOG.md' - - '.gitignore' - - '.gitattributes' - - 'infection.json.dist' - - 'psalm.xml' - -name: rector - -jobs: - rector: - uses: yiisoft/actions/.github/workflows/rector.yml@master - secrets: - token: ${{ secrets.YIISOFT_GITHUB_TOKEN }} - with: - repository: ${{ github.event.pull_request.head.repo.full_name }} - os: >- - ['ubuntu-latest'] - php: >- - ['8.4'] diff --git a/.gitignore b/.gitignore index c913400..f1fb048 100644 --- a/.gitignore +++ b/.gitignore @@ -26,3 +26,6 @@ composer.phar /phpunit.phar /phpunit.xml /.phpunit.cache + +# PHP CS Fixer +/.php-cs-fixer.cache diff --git a/.php-cs-fixer.dist.php b/.php-cs-fixer.dist.php new file mode 100644 index 0000000..2477e66 --- /dev/null +++ b/.php-cs-fixer.dist.php @@ -0,0 +1,21 @@ +in([ + __DIR__ . '/src', + __DIR__ . '/tests', +]); + +return ConfigBuilder::build() + ->setRiskyAllowed(true) + ->setParallelConfig(ParallelConfigFactory::detect()) + ->setRules([ + '@Yiisoft/Core' => true, + '@Yiisoft/Core:risky' => true, + ]) + ->setFinder($finder); diff --git a/.styleci.yml b/.styleci.yml deleted file mode 100644 index 1ab379b..0000000 --- a/.styleci.yml +++ /dev/null @@ -1,85 +0,0 @@ -preset: psr12 -risky: true - -version: 8.1 - -finder: - exclude: - - docs - - vendor - -enabled: - - alpha_ordered_traits - - array_indentation - - array_push - - combine_consecutive_issets - - combine_consecutive_unsets - - combine_nested_dirname - - declare_strict_types - - dir_constant - - fully_qualified_strict_types - - function_to_constant - - hash_to_slash_comment - - is_null - - logical_operators - - magic_constant_casing - - magic_method_casing - - method_separation - - modernize_types_casting - - native_function_casing - - native_function_type_declaration_casing - - no_alias_functions - - no_empty_comment - - no_empty_phpdoc - - no_empty_statement - - no_extra_block_blank_lines - - no_short_bool_cast - - no_superfluous_elseif - - no_unneeded_control_parentheses - - no_unneeded_curly_braces - - no_unneeded_final_method - - no_unset_cast - - no_unused_imports - - no_unused_lambda_imports - - no_useless_else - - no_useless_return - - normalize_index_brace - - php_unit_dedicate_assert - - php_unit_dedicate_assert_internal_type - - php_unit_expectation - - php_unit_mock - - php_unit_mock_short_will_return - - php_unit_namespaced - - php_unit_no_expectation_annotation - - phpdoc_no_empty_return - - phpdoc_no_useless_inheritdoc - - phpdoc_order - - phpdoc_property - - phpdoc_scalar - - phpdoc_singular_inheritdoc - - phpdoc_trim - - phpdoc_trim_consecutive_blank_line_separation - - phpdoc_type_to_var - - phpdoc_types - - phpdoc_types_order - - print_to_echo - - regular_callable_call - - return_assignment - - self_accessor - - self_static_accessor - - set_type_to_cast - - short_array_syntax - - short_list_syntax - - simplified_if_return - - single_quote - - standardize_not_equals - - ternary_to_null_coalescing - - trailing_comma_in_multiline_array - - unalign_double_arrow - - unalign_equals - - empty_loop_body_braces - - integer_literal_case - - union_type_without_spaces - -disabled: - - function_declaration diff --git a/composer.json b/composer.json index be2155c..026491b 100644 --- a/composer.json +++ b/composer.json @@ -33,6 +33,7 @@ "yiisoft/var-dumper": "^1.7" }, "require-dev": { + "friendsofphp/php-cs-fixer": "^3.95", "maglnet/composer-require-checker": "^4.7.1", "phpunit/phpunit": "^10.5.45", "psr/clock": "^1.0", @@ -40,6 +41,7 @@ "roave/infection-static-analysis-plugin": "^1.35", "spatie/phpunit-watcher": "^1.24", "vimeo/psalm": "^5.26.1 || ^6.10", + "yiisoft/code-style": "^1.0", "yiisoft/files": "^1.0.2" }, "autoload": { @@ -61,6 +63,8 @@ } }, "scripts": { + "cs-fix": "php-cs-fixer fix", + "rector": "rector", "test": "phpunit --testdox --no-interaction", "test-watch": "phpunit-watcher watch" } diff --git a/src/ConcurrentAssignmentsStorageDecorator.php b/src/ConcurrentAssignmentsStorageDecorator.php index 7528ac6..5862859 100644 --- a/src/ConcurrentAssignmentsStorageDecorator.php +++ b/src/ConcurrentAssignmentsStorageDecorator.php @@ -14,9 +14,9 @@ final class ConcurrentAssignmentsStorageDecorator implements AssignmentsStorageI /** * @param AssignmentsStorageInterface&FileStorageInterface $storage */ - public function __construct(private AssignmentsStorageInterface|FileStorageInterface $storage) - { - } + public function __construct( + private AssignmentsStorageInterface|FileStorageInterface $storage, + ) {} public function getAll(): array { diff --git a/src/ConcurrentItemsStorageDecorator.php b/src/ConcurrentItemsStorageDecorator.php index e3a6913..751d4c1 100644 --- a/src/ConcurrentItemsStorageDecorator.php +++ b/src/ConcurrentItemsStorageDecorator.php @@ -15,9 +15,9 @@ final class ConcurrentItemsStorageDecorator implements ItemsStorageInterface, Fi /** * @param FileStorageInterface&ItemsStorageInterface $storage */ - public function __construct(private ItemsStorageInterface|FileStorageInterface $storage) - { - } + public function __construct( + private ItemsStorageInterface|FileStorageInterface $storage, + ) {} public function clear(): void { diff --git a/src/FileStorageTrait.php b/src/FileStorageTrait.php index d755192..1a80925 100644 --- a/src/FileStorageTrait.php +++ b/src/FileStorageTrait.php @@ -9,6 +9,10 @@ use function dirname; use function function_exists; +use function is_int; +use function sprintf; + +use const LOCK_EX; trait FileStorageTrait { @@ -97,6 +101,6 @@ private function invalidateScriptCache(): void private function initFileProperties(string $filePath, ?callable $getFileUpdatedAt): void { $this->filePath = $filePath; - $this->getFileUpdatedAt = $getFileUpdatedAt ?? static fn (string $filePath): int|false => @filemtime($filePath); + $this->getFileUpdatedAt = $getFileUpdatedAt ?? static fn(string $filePath): int|false => @filemtime($filePath); } } diff --git a/tests/AssignmentsStorageTest.php b/tests/AssignmentsStorageTest.php index 2fa2eca..f2b2783 100644 --- a/tests/AssignmentsStorageTest.php +++ b/tests/AssignmentsStorageTest.php @@ -40,7 +40,7 @@ public function testGetFileUpdatedAtException(): void $this->expectExceptionMessage('getFileUpdatedAt callable must return a UNIX timestamp.'); new AssignmentsStorage( $this->getAssignmentsStorageFilePath(), - getFileUpdatedAt: static fn (string $filePath): string => 'test', + getFileUpdatedAt: static fn(string $filePath): string => 'test', ); } diff --git a/tests/AssignmentsStorageWithConcurrencyHandledTest.php b/tests/AssignmentsStorageWithConcurrencyHandledTest.php index 1a4d059..a8d9668 100644 --- a/tests/AssignmentsStorageWithConcurrencyHandledTest.php +++ b/tests/AssignmentsStorageWithConcurrencyHandledTest.php @@ -14,6 +14,8 @@ use Yiisoft\Rbac\Php\ItemsStorage; use Yiisoft\Rbac\Tests\Common\AssignmentsStorageTestTrait; +use function count; + final class AssignmentsStorageWithConcurrencyHandledTest extends TestCase { use AssignmentsStorageTestTrait { diff --git a/tests/AssignmentsStorageWithConcurrencyNotHandled.php b/tests/AssignmentsStorageWithConcurrencyNotHandled.php index 7e18063..c30592a 100644 --- a/tests/AssignmentsStorageWithConcurrencyNotHandled.php +++ b/tests/AssignmentsStorageWithConcurrencyNotHandled.php @@ -12,6 +12,8 @@ use Yiisoft\Rbac\Php\ItemsStorage; use Yiisoft\Rbac\Tests\Common\AssignmentsStorageTestTrait; +use function count; + final class AssignmentsStorageWithConcurrencyNotHandled extends TestCase { use AssignmentsStorageTestTrait { diff --git a/tests/ItemsStorage/ItemsStorageTest.php b/tests/ItemsStorage/ItemsStorageTest.php index 77bdb54..2ce3011 100644 --- a/tests/ItemsStorage/ItemsStorageTest.php +++ b/tests/ItemsStorage/ItemsStorageTest.php @@ -15,6 +15,8 @@ use function in_array; +use const DIRECTORY_SEPARATOR; + final class ItemsStorageTest extends TestCase { use ItemsStorageTestTrait { @@ -93,7 +95,7 @@ public function testLoadWithCustomGetFileUpdatedAt(): void $storage = new ItemsStorage( $this->getItemsStorageFilePath(), - getFileUpdatedAt: static fn (string $filePath): int|false => $time, + getFileUpdatedAt: static fn(string $filePath): int|false => $time, ); $this->assertSame($time, $storage->get('test')->getCreatedAt()); } @@ -104,7 +106,7 @@ public function testGetFileUpdatedAtException(): void $this->expectExceptionMessage('getFileUpdatedAt callable must return a UNIX timestamp.'); new ItemsStorage( $this->getItemsStorageFilePath(), - getFileUpdatedAt: static fn (string $filePath): string => 'test', + getFileUpdatedAt: static fn(string $filePath): string => 'test', ); } diff --git a/tests/ItemsStorageWithConcurrencyHandledTest.php b/tests/ItemsStorageWithConcurrencyHandledTest.php index 900ae5f..d455b9d 100644 --- a/tests/ItemsStorageWithConcurrencyHandledTest.php +++ b/tests/ItemsStorageWithConcurrencyHandledTest.php @@ -12,6 +12,8 @@ use Yiisoft\Rbac\Role; use Yiisoft\Rbac\Tests\Common\ItemsStorageTestTrait; +use function count; + final class ItemsStorageWithConcurrencyHandledTest extends TestCase { use ItemsStorageTestTrait { diff --git a/tests/ItemsStorageWithConcurrencyNotHandledTest.php b/tests/ItemsStorageWithConcurrencyNotHandledTest.php index 33ca0d4..d350e56 100644 --- a/tests/ItemsStorageWithConcurrencyNotHandledTest.php +++ b/tests/ItemsStorageWithConcurrencyNotHandledTest.php @@ -11,6 +11,8 @@ use Yiisoft\Rbac\Role; use Yiisoft\Rbac\Tests\Common\ItemsStorageTestTrait; +use function count; + final class ItemsStorageWithConcurrencyNotHandledTest extends TestCase { use ItemsStorageTestTrait { diff --git a/tests/StorageFilePathTrait.php b/tests/StorageFilePathTrait.php index 9f3422a..1a6ec2a 100644 --- a/tests/StorageFilePathTrait.php +++ b/tests/StorageFilePathTrait.php @@ -6,6 +6,8 @@ use Yiisoft\Files\FileHelper; +use const DIRECTORY_SEPARATOR; + trait StorageFilePathTrait { private ?string $dataPath = null; diff --git a/tests/Support/TestHelper.php b/tests/Support/TestHelper.php index 2913650..076c7e1 100644 --- a/tests/Support/TestHelper.php +++ b/tests/Support/TestHelper.php @@ -8,11 +8,9 @@ final class TestHelper { - private function __construct() - { - } + private function __construct() {} - public static function getCurrentErrorHandler(): callable|null + public static function getCurrentErrorHandler(): ?callable { $currentHandler = set_error_handler(static fn() => true); restore_error_handler(); From da4dfe4e430e8ec63804209d6a69c20736d2bc9e Mon Sep 17 00:00:00 2001 From: Sergei Predvoditelev Date: Sat, 9 May 2026 13:05:52 +0300 Subject: [PATCH 2/2] changelog --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7f43585..e38261c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,8 @@ - Enh #110: Bump `yiisoft/rbac` version to `^2.1` (@vjik) - Chg #111: Change PHP constraint in `composer.json` to `8.1 - 8.4` (@vjik) +- Enh #115: Apply code style fixes (@vjik) +- Enh #115: Explicitly import functions and constants in "use" section (@vjik) ## 2.0.0 March 07, 2024