diff --git a/.github/workflows/rector-cs.yml b/.github/workflows/rector-cs.yml new file mode 100644 index 0000000..2351349 --- /dev/null +++ b/.github/workflows/rector-cs.yml @@ -0,0 +1,27 @@ +name: Rector + PHP CS Fixer + +on: + pull_request_target: + paths: + - 'src/**' + - 'tests/**' + - '.github/workflows/rector-cs.yml' + - 'composer.json' + - 'rector.php' + - '.php-cs-fixer.dist.php' + +permissions: + contents: read + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +jobs: + rector: + uses: yiisoft/actions/.github/workflows/rector-cs.yml@master + secrets: + token: ${{ secrets.YIISOFT_GITHUB_TOKEN }} + with: + repository: ${{ github.event.pull_request.head.repo.full_name }} + php: '8.0' diff --git a/.github/workflows/rector.yml b/.github/workflows/rector.yml deleted file mode 100644 index adacd73..0000000 --- a/.github/workflows/rector.yml +++ /dev/null @@ -1,21 +0,0 @@ -on: - pull_request: - 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 - with: - os: >- - ['ubuntu-latest'] - php: >- - ['8.0'] diff --git a/.gitignore b/.gitignore index ffca5ff..5e58ce0 100644 --- a/.gitignore +++ b/.gitignore @@ -28,3 +28,7 @@ phpunit.phar /phpunit.xml # phpunit cache .phpunit.result.cache + +# PHP CS Fixer +/.php-cs-fixer.cache +/.php-cs-fixer.php diff --git a/.php-cs-fixer.dist.php b/.php-cs-fixer.dist.php new file mode 100644 index 0000000..b106135 --- /dev/null +++ b/.php-cs-fixer.dist.php @@ -0,0 +1,40 @@ +in([ + __DIR__ . '/src', + __DIR__ . '/tests', +]); + +// TODO: Update the configuration after raising the minimum PHP version +return (new Config()) + ->setRiskyAllowed(true) + ->setParallelConfig(ParallelConfigFactory::detect()) + ->setRules([ + '@PER-CS2.0' => true, + 'nullable_type_declaration' => true, + 'operator_linebreak' => true, + 'ordered_types' => ['null_adjustment' => 'always_last', 'sort_algorithm' => 'none'], + 'single_class_element_per_statement' => true, + 'types_spaces' => true, + 'no_unused_imports' => true, + 'ordered_class_elements' => true, + 'class_attributes_separation' => ['elements' => ['method' => 'one']], + 'declare_strict_types' => true, + 'native_function_invocation' => true, + 'native_constant_invocation' => true, + 'fully_qualified_strict_types' => [ + 'import_symbols' => true + ], + 'global_namespace_import' => [ + 'import_classes' => true, + 'import_constants' => true, + 'import_functions' => 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 4bdbb41..684e09c 100644 --- a/composer.json +++ b/composer.json @@ -34,6 +34,7 @@ "symfony/finder": "^5.4|^6.0|^7.1" }, "require-dev": { + "friendsofphp/php-cs-fixer": "^3.66", "maglnet/composer-require-checker": "^4.2", "phpunit/phpunit": "^9.5", "rector/rector": "^2.0.3", diff --git a/src/Classifier.php b/src/Classifier.php index 65f3f07..9bbf0ce 100644 --- a/src/Classifier.php +++ b/src/Classifier.php @@ -8,6 +8,10 @@ use ReflectionClass; use Symfony\Component\Finder\Finder; +use function count; + +use const DIRECTORY_SEPARATOR; + /** * Classifier traverses file system to find classes by a certain criteria. */ @@ -108,7 +112,7 @@ public function find(): iterable $matchedDirs = array_filter( $directories, - static fn($directory) => str_starts_with($reflection->getFileName(), $directory) + static fn($directory) => str_starts_with($reflection->getFileName(), $directory), ); if (count($matchedDirs) === 0) { @@ -128,7 +132,7 @@ public function find(): iterable $attributes = $reflection->getAttributes(); $attributes = array_map( static fn(ReflectionAttribute $attribute) => $attribute->getName(), - $attributes + $attributes, ); if (count(array_intersect($this->attributes, $attributes)) !== $countAttributes) { diff --git a/tests/Support/Attributes/AuthorAttribute.php b/tests/Support/Attributes/AuthorAttribute.php index bc02910..27af9b9 100644 --- a/tests/Support/Attributes/AuthorAttribute.php +++ b/tests/Support/Attributes/AuthorAttribute.php @@ -7,6 +7,4 @@ use Attribute; #[Attribute] -class AuthorAttribute -{ -} +class AuthorAttribute {} diff --git a/tests/Support/Author.php b/tests/Support/Author.php index b720cd7..9105917 100644 --- a/tests/Support/Author.php +++ b/tests/Support/Author.php @@ -7,6 +7,4 @@ use Yiisoft\Classifier\Tests\Support\Attributes\AuthorAttribute; #[AuthorAttribute] -class Author -{ -} +class Author {} diff --git a/tests/Support/AuthorPost.php b/tests/Support/AuthorPost.php index 1c9e01e..d0d290e 100644 --- a/tests/Support/AuthorPost.php +++ b/tests/Support/AuthorPost.php @@ -8,6 +8,4 @@ use Yiisoft\Classifier\Tests\Support\Interfaces\PostInterface; #[AuthorAttribute] -class AuthorPost implements PostInterface -{ -} +class AuthorPost implements PostInterface {} diff --git a/tests/Support/Dir1/UserInDir1.php b/tests/Support/Dir1/UserInDir1.php index e3631e2..3018094 100644 --- a/tests/Support/Dir1/UserInDir1.php +++ b/tests/Support/Dir1/UserInDir1.php @@ -6,6 +6,4 @@ use Yiisoft\Classifier\Tests\Support\Interfaces\UserInterface; -class UserInDir1 implements UserInterface -{ -} +class UserInDir1 implements UserInterface {} diff --git a/tests/Support/Dir2/UserInDir2.php b/tests/Support/Dir2/UserInDir2.php index 9d64833..6f442ee 100644 --- a/tests/Support/Dir2/UserInDir2.php +++ b/tests/Support/Dir2/UserInDir2.php @@ -6,6 +6,4 @@ use Yiisoft\Classifier\Tests\Support\Interfaces\UserInterface; -class UserInDir2 implements UserInterface -{ -} +class UserInDir2 implements UserInterface {} diff --git a/tests/Support/Interfaces/PostInterface.php b/tests/Support/Interfaces/PostInterface.php index 55cc95d..edd7e8b 100644 --- a/tests/Support/Interfaces/PostInterface.php +++ b/tests/Support/Interfaces/PostInterface.php @@ -4,6 +4,4 @@ namespace Yiisoft\Classifier\Tests\Support\Interfaces; -interface PostInterface -{ -} +interface PostInterface {} diff --git a/tests/Support/Interfaces/UserInterface.php b/tests/Support/Interfaces/UserInterface.php index 5e6831b..b05d2de 100644 --- a/tests/Support/Interfaces/UserInterface.php +++ b/tests/Support/Interfaces/UserInterface.php @@ -4,6 +4,4 @@ namespace Yiisoft\Classifier\Tests\Support\Interfaces; -interface UserInterface -{ -} +interface UserInterface {} diff --git a/tests/Support/Post.php b/tests/Support/Post.php index 4484629..e7603ea 100644 --- a/tests/Support/Post.php +++ b/tests/Support/Post.php @@ -6,6 +6,4 @@ use Yiisoft\Classifier\Tests\Support\Interfaces\PostInterface; -class Post implements PostInterface -{ -} +class Post implements PostInterface {} diff --git a/tests/Support/PostUser.php b/tests/Support/PostUser.php index 171b2ac..5b1d8d8 100644 --- a/tests/Support/PostUser.php +++ b/tests/Support/PostUser.php @@ -7,6 +7,4 @@ use Yiisoft\Classifier\Tests\Support\Interfaces\PostInterface; use Yiisoft\Classifier\Tests\Support\Interfaces\UserInterface; -class PostUser implements UserInterface, PostInterface -{ -} +class PostUser implements UserInterface, PostInterface {} diff --git a/tests/Support/SuperSuperUser.php b/tests/Support/SuperSuperUser.php index d2dcde9..5241d3a 100644 --- a/tests/Support/SuperSuperUser.php +++ b/tests/Support/SuperSuperUser.php @@ -4,6 +4,4 @@ namespace Yiisoft\Classifier\Tests\Support; -class SuperSuperUser extends SuperUser -{ -} +class SuperSuperUser extends SuperUser {} diff --git a/tests/Support/SuperUser.php b/tests/Support/SuperUser.php index 886c564..bed6d56 100644 --- a/tests/Support/SuperUser.php +++ b/tests/Support/SuperUser.php @@ -4,6 +4,4 @@ namespace Yiisoft\Classifier\Tests\Support; -class SuperUser extends User implements UserSubInterface -{ -} +class SuperUser extends User implements UserSubInterface {} diff --git a/tests/Support/User.php b/tests/Support/User.php index 073bb18..dcbefc2 100644 --- a/tests/Support/User.php +++ b/tests/Support/User.php @@ -6,6 +6,4 @@ use Yiisoft\Classifier\Tests\Support\Interfaces\UserInterface; -class User implements UserInterface -{ -} +class User implements UserInterface {} diff --git a/tests/Support/UserSubInterface.php b/tests/Support/UserSubInterface.php index 6ae4ddc..24ae2f0 100644 --- a/tests/Support/UserSubInterface.php +++ b/tests/Support/UserSubInterface.php @@ -6,6 +6,4 @@ use Yiisoft\Classifier\Tests\Support\Interfaces\UserInterface; -interface UserSubInterface extends UserInterface -{ -} +interface UserSubInterface extends UserInterface {} diff --git a/tests/Support/UserSubclass.php b/tests/Support/UserSubclass.php index ae24200..1fbaf13 100644 --- a/tests/Support/UserSubclass.php +++ b/tests/Support/UserSubclass.php @@ -4,6 +4,4 @@ namespace Yiisoft\Classifier\Tests\Support; -class UserSubclass implements UserSubInterface -{ -} +class UserSubclass implements UserSubInterface {}