diff --git a/.github/workflows/rector-cs.yml b/.github/workflows/rector-cs.yml new file mode 100644 index 0000000..03b7c75 --- /dev/null +++ b/.github/workflows/rector-cs.yml @@ -0,0 +1,28 @@ +name: Rector + PHP CS Fixer + +on: + pull_request_target: + paths: + - 'config/**' + - '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.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..d3b3a3d 100644 --- a/.gitignore +++ b/.gitignore @@ -26,3 +26,7 @@ composer.phar /phpunit.phar /phpunit.xml /.phpunit.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..3cb52f9 --- /dev/null +++ b/.php-cs-fixer.dist.php @@ -0,0 +1,22 @@ +in([ + __DIR__ . '/config', + __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 fb20d16..8325685 100644 --- a/composer.json +++ b/composer.json @@ -45,12 +45,14 @@ "yiisoft/request-provider": "^1.0" }, "require-dev": { + "friendsofphp/php-cs-fixer": "^3.93", "maglnet/composer-require-checker": "^4.7.1", "phpunit/phpunit": "^10.5.45", "rector/rector": "^2.0.11", "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/di": "^1.3", "yiisoft/test-support": "^3.0.2" }, @@ -82,6 +84,7 @@ }, "scripts": { "test": "phpunit --testdox --no-interaction", - "test-watch": "phpunit-watcher watch" + "test-watch": "phpunit-watcher watch", + "cs-fix": "php-cs-fixer fix" } } diff --git a/config/di-web.php b/config/di-web.php index 826e75c..11930f3 100644 --- a/config/di-web.php +++ b/config/di-web.php @@ -12,8 +12,8 @@ RequestInputParametersResolver::class => [ '__construct()' => [ 'hydrator' => Reference::to(ValidatingHydrator::class), - 'throwInputValidationException' => - $params['yiisoft/input-http']['requestInputParametersResolver']['throwInputValidationException'], + 'throwInputValidationException' + => $params['yiisoft/input-http']['requestInputParametersResolver']['throwInputValidationException'], ], ], ]; diff --git a/src/Attribute/Data/FromBody.php b/src/Attribute/Data/FromBody.php index f44192f..5197485 100644 --- a/src/Attribute/Data/FromBody.php +++ b/src/Attribute/Data/FromBody.php @@ -29,8 +29,7 @@ public function __construct( private string|array|null $name = null, private array $map = [], private bool $strict = false, - ) { - } + ) {} /** * Get the name of the field in the request body to get data from. diff --git a/src/Attribute/Data/FromBodyResolver.php b/src/Attribute/Data/FromBodyResolver.php index b1d6ae0..d899f28 100644 --- a/src/Attribute/Data/FromBodyResolver.php +++ b/src/Attribute/Data/FromBodyResolver.php @@ -24,8 +24,7 @@ final class FromBodyResolver implements DataAttributeResolverInterface */ public function __construct( private RequestProviderInterface $requestProvider, - ) { - } + ) {} public function prepareData(DataAttributeInterface $attribute, DataInterface $data): DataInterface { diff --git a/src/Attribute/Data/FromQuery.php b/src/Attribute/Data/FromQuery.php index d08bdb8..13e3227 100644 --- a/src/Attribute/Data/FromQuery.php +++ b/src/Attribute/Data/FromQuery.php @@ -29,8 +29,7 @@ public function __construct( private string|array|null $name = null, private array $map = [], private bool $strict = false, - ) { - } + ) {} /** * Get the name of the field in the query string to get data from. diff --git a/src/Attribute/Data/FromQueryResolver.php b/src/Attribute/Data/FromQueryResolver.php index 013fd22..9028a4f 100644 --- a/src/Attribute/Data/FromQueryResolver.php +++ b/src/Attribute/Data/FromQueryResolver.php @@ -24,8 +24,7 @@ final class FromQueryResolver implements DataAttributeResolverInterface */ public function __construct( private RequestProviderInterface $requestProvider, - ) { - } + ) {} public function prepareData(DataAttributeInterface $attribute, DataInterface $data): DataInterface { diff --git a/src/Attribute/Parameter/Body.php b/src/Attribute/Parameter/Body.php index 14ea8fa..9e99ce1 100644 --- a/src/Attribute/Parameter/Body.php +++ b/src/Attribute/Parameter/Body.php @@ -18,9 +18,8 @@ final class Body implements ParameterAttributeInterface * @psalm-param string|list|null $name */ public function __construct( - private string|array|null $name = null - ) { - } + private string|array|null $name = null, + ) {} /** * Get the name of the field in the request body to get data from. diff --git a/src/Attribute/Parameter/BodyResolver.php b/src/Attribute/Parameter/BodyResolver.php index ee47f6f..4586285 100644 --- a/src/Attribute/Parameter/BodyResolver.php +++ b/src/Attribute/Parameter/BodyResolver.php @@ -23,9 +23,8 @@ final class BodyResolver implements ParameterAttributeResolverInterface * @param RequestProviderInterface $requestProvider The request provider. */ public function __construct( - private RequestProviderInterface $requestProvider - ) { - } + private RequestProviderInterface $requestProvider, + ) {} public function getParameterValue( ParameterAttributeInterface $attribute, diff --git a/src/Attribute/Parameter/Query.php b/src/Attribute/Parameter/Query.php index aa340aa..eff94b5 100644 --- a/src/Attribute/Parameter/Query.php +++ b/src/Attribute/Parameter/Query.php @@ -18,9 +18,8 @@ final class Query implements ParameterAttributeInterface * @psalm-param string|list|null $name */ public function __construct( - private string|array|null $name = null - ) { - } + private string|array|null $name = null, + ) {} /** * Get the name of the field in the query string to get data from. diff --git a/src/Attribute/Parameter/QueryResolver.php b/src/Attribute/Parameter/QueryResolver.php index ee640a2..e520b48 100644 --- a/src/Attribute/Parameter/QueryResolver.php +++ b/src/Attribute/Parameter/QueryResolver.php @@ -21,9 +21,8 @@ final class QueryResolver implements ParameterAttributeResolverInterface * @param RequestProviderInterface $requestProvider The request provider. */ public function __construct( - private RequestProviderInterface $requestProvider - ) { - } + private RequestProviderInterface $requestProvider, + ) {} public function getParameterValue( ParameterAttributeInterface $attribute, diff --git a/src/Attribute/Parameter/Request.php b/src/Attribute/Parameter/Request.php index 371f1fc..4ba032d 100644 --- a/src/Attribute/Parameter/Request.php +++ b/src/Attribute/Parameter/Request.php @@ -18,9 +18,8 @@ final class Request implements ParameterAttributeInterface * @psalm-param string|list|null $name */ public function __construct( - private string|array|null $name = null - ) { - } + private string|array|null $name = null, + ) {} /** * Get the name of the field in the request attributes to get data from. diff --git a/src/Attribute/Parameter/RequestResolver.php b/src/Attribute/Parameter/RequestResolver.php index 61bd3c4..a969412 100644 --- a/src/Attribute/Parameter/RequestResolver.php +++ b/src/Attribute/Parameter/RequestResolver.php @@ -21,9 +21,8 @@ final class RequestResolver implements ParameterAttributeResolverInterface * @param RequestProviderInterface $requestProvider The request provider. */ public function __construct( - private RequestProviderInterface $requestProvider - ) { - } + private RequestProviderInterface $requestProvider, + ) {} public function getParameterValue( ParameterAttributeInterface $attribute, diff --git a/src/Attribute/Parameter/UploadedFiles.php b/src/Attribute/Parameter/UploadedFiles.php index a08c6e7..5910b93 100644 --- a/src/Attribute/Parameter/UploadedFiles.php +++ b/src/Attribute/Parameter/UploadedFiles.php @@ -18,9 +18,8 @@ final class UploadedFiles implements ParameterAttributeInterface * @psalm-param string|list|null $name */ public function __construct( - private string|array|null $name = null - ) { - } + private string|array|null $name = null, + ) {} /** * Get the name of the field in the uploaded files to get data from. diff --git a/src/Attribute/Parameter/UploadedFilesResolver.php b/src/Attribute/Parameter/UploadedFilesResolver.php index 81ee58b..67a9664 100644 --- a/src/Attribute/Parameter/UploadedFilesResolver.php +++ b/src/Attribute/Parameter/UploadedFilesResolver.php @@ -22,8 +22,7 @@ final class UploadedFilesResolver implements ParameterAttributeResolverInterface */ public function __construct( private RequestProviderInterface $requestProvider, - ) { - } + ) {} public function getParameterValue( ParameterAttributeInterface $attribute, diff --git a/src/HydratorAttributeParametersResolver.php b/src/HydratorAttributeParametersResolver.php index cacd8ff..09a8910 100644 --- a/src/HydratorAttributeParametersResolver.php +++ b/src/HydratorAttributeParametersResolver.php @@ -58,7 +58,7 @@ private function prepareValue(Result $handleResult, ReflectionParameter $paramet $typeCastResult = $this->typeCaster->cast( $value, - new TypeCastContext($this->hydrator, $parameter) + new TypeCastContext($this->hydrator, $parameter), ); return $typeCastResult->isResolved() ? $typeCastResult->getValue() : $value; diff --git a/src/RequestInputInterface.php b/src/RequestInputInterface.php index d2dcfba..dd8eaf7 100644 --- a/src/RequestInputInterface.php +++ b/src/RequestInputInterface.php @@ -7,6 +7,4 @@ /** * `RequestInputInterface` marks a DTO as a request input. */ -interface RequestInputInterface -{ -} +interface RequestInputInterface {} diff --git a/src/RequestInputParametersResolver.php b/src/RequestInputParametersResolver.php index e440c9b..a11df16 100644 --- a/src/RequestInputParametersResolver.php +++ b/src/RequestInputParametersResolver.php @@ -24,8 +24,7 @@ final class RequestInputParametersResolver implements ParametersResolverInterfac public function __construct( private HydratorInterface $hydrator, private bool $throwInputValidationException = false, - ) { - } + ) {} /** * @param ReflectionParameter[] $parameters The parameters to resolve. diff --git a/tests/Attribute/Parameter/BodyTest.php b/tests/Attribute/Parameter/BodyTest.php index 1ea653e..eee0ed4 100644 --- a/tests/Attribute/Parameter/BodyTest.php +++ b/tests/Attribute/Parameter/BodyTest.php @@ -25,7 +25,7 @@ public function testBase(): void 'c' => 'three', ]); - $input = new class () { + $input = new class { #[Body('a')] public string $a = ''; #[Body('b')] @@ -45,7 +45,7 @@ public function testWithoutBody(): void { $hydrator = $this->createHydrator(null); - $input = new class () { + $input = new class { #[Body('a')] public string $a = ''; #[Body('b')] @@ -68,7 +68,7 @@ public function testNonExistPath(): void 'b' => 'two', ]); - $input = new class () { + $input = new class { #[Body('a.b')] public string $a = ''; }; diff --git a/tests/Attribute/Parameter/QueryTest.php b/tests/Attribute/Parameter/QueryTest.php index 0f3d48d..624b22d 100644 --- a/tests/Attribute/Parameter/QueryTest.php +++ b/tests/Attribute/Parameter/QueryTest.php @@ -25,7 +25,7 @@ public function testBase(): void 'c' => 'three', ]); - $input = new class () { + $input = new class { #[Query('a')] public string $a = ''; #[Query('b')] @@ -45,7 +45,7 @@ public function testWithoutBody(): void { $hydrator = $this->createHydrator([]); - $input = new class () { + $input = new class { #[Query('a')] public string $a = ''; #[Query('b')] @@ -68,7 +68,7 @@ public function testNonExistPath(): void 'b' => 'two', ]); - $input = new class () { + $input = new class { #[Query('a.b')] public string $a = ''; }; diff --git a/tests/Attribute/Parameter/RequestTest.php b/tests/Attribute/Parameter/RequestTest.php index 2a49a34..5cfcf35 100644 --- a/tests/Attribute/Parameter/RequestTest.php +++ b/tests/Attribute/Parameter/RequestTest.php @@ -25,7 +25,7 @@ public function testBase(): void 'c' => 'three', ]); - $input = new class () { + $input = new class { #[Request('a')] public string $a = ''; #[Request('b')] @@ -45,7 +45,7 @@ public function testWithoutBody(): void { $hydrator = $this->createHydrator([]); - $input = new class () { + $input = new class { #[Request('a')] public string $a = ''; #[Request('b')] @@ -68,7 +68,7 @@ public function testNonExistPath(): void 'b' => 'two', ]); - $input = new class () { + $input = new class { #[Request('a.b')] public string $a = ''; }; diff --git a/tests/Attribute/Parameter/UploadedFilesTest.php b/tests/Attribute/Parameter/UploadedFilesTest.php index 00df0c3..e772836 100644 --- a/tests/Attribute/Parameter/UploadedFilesTest.php +++ b/tests/Attribute/Parameter/UploadedFilesTest.php @@ -31,7 +31,7 @@ public function testBase(): void 'd' => [$file1, $file3], ]); - $input = new class () { + $input = new class { #[UploadedFiles('a')] public ?UploadedFileInterface $a = null; #[UploadedFiles('b')] @@ -54,7 +54,7 @@ public function testWithoutBody(): void { $hydrator = $this->createHydrator([]); - $input = new class () { + $input = new class { #[UploadedFiles('a')] public ?UploadedFileInterface $a = null; #[UploadedFiles('b')] @@ -77,7 +77,7 @@ public function testNonExistPath(): void 'b' => $this->createMock(UploadedFileInterface::class), ]); - $input = new class () { + $input = new class { #[UploadedFiles('a.b')] public ?UploadedFileInterface $a = null; }; diff --git a/tests/ConfigTest.php b/tests/ConfigTest.php index 877dc84..5a8f048 100644 --- a/tests/ConfigTest.php +++ b/tests/ConfigTest.php @@ -29,7 +29,7 @@ public function testDi(): void $this->assertInstanceOf(RequestProvider::class, $container->get(RequestProviderInterface::class)); $this->assertInstanceOf( RequestInputParametersResolver::class, - $container->get(RequestInputParametersResolver::class) + $container->get(RequestInputParametersResolver::class), ); } @@ -49,11 +49,11 @@ public function testResetRequestProvider(): void private function createContainer(): Container { return new Container( - ContainerConfig::create()->withDefinitions($this->getContainerDefinitions()) + ContainerConfig::create()->withDefinitions($this->getContainerDefinitions()), ); } - private function getContainerDefinitions(array|null $params = null): array + private function getContainerDefinitions(?array $params = null): array { if ($params === null) { $params = $this->getParams(); diff --git a/tests/HydratorAttributeParametersResolverTest.php b/tests/HydratorAttributeParametersResolverTest.php index bff27b6..212de88 100644 --- a/tests/HydratorAttributeParametersResolverTest.php +++ b/tests/HydratorAttributeParametersResolverTest.php @@ -30,7 +30,7 @@ public function testBase(): void TestHelper::createParameterAttributesHandler([ QueryResolver::class => new QueryResolver($requestProvider), BodyResolver::class => new BodyResolver($requestProvider), - ]) + ]), ); $parameters = TestHelper::getParameters( @@ -65,7 +65,7 @@ public function testTypeCasting(): void ]), new CallableTypeCaster( static fn($value) => 100, - ) + ), ); $parameters = TestHelper::getParameters( diff --git a/tests/RequestInputParametersResolverTest.php b/tests/RequestInputParametersResolverTest.php index a7bec33..8fb5faf 100644 --- a/tests/RequestInputParametersResolverTest.php +++ b/tests/RequestInputParametersResolverTest.php @@ -39,7 +39,7 @@ public function testBase(): void $this->assertFalse($person->getValidationResult()->isValid()); $this->assertSame( ['name' => ['Name is required.']], - $person->getValidationResult()->getErrorMessagesIndexedByPath() + $person->getValidationResult()->getErrorMessagesIndexedByPath(), ); $this->assertInstanceOf(SimpleRequestInput::class, $simple); diff --git a/tests/Support/CallableTypeCaster.php b/tests/Support/CallableTypeCaster.php index d733ee8..6251e0e 100644 --- a/tests/Support/CallableTypeCaster.php +++ b/tests/Support/CallableTypeCaster.php @@ -12,8 +12,7 @@ final class CallableTypeCaster implements TypeCasterInterface { public function __construct( private $callable, - ) { - } + ) {} public function cast(mixed $value, TypeCastContext $context): Result { diff --git a/tests/Support/Input/PersonInput.php b/tests/Support/Input/PersonInput.php index dcb1468..84860f2 100644 --- a/tests/Support/Input/PersonInput.php +++ b/tests/Support/Input/PersonInput.php @@ -14,6 +14,5 @@ final class PersonInput extends AbstractInput public function __construct( #[Required(message: 'Name is required.')] public string $name = '', - ) { - } + ) {} } diff --git a/tests/Support/PureObject.php b/tests/Support/PureObject.php index 8049d78..0f64234 100644 --- a/tests/Support/PureObject.php +++ b/tests/Support/PureObject.php @@ -4,6 +4,4 @@ namespace Yiisoft\Input\Http\Tests\Support; -final class PureObject -{ -} +final class PureObject {} diff --git a/tests/Support/TestHelper.php b/tests/Support/TestHelper.php index 06ee932..f492bb9 100644 --- a/tests/Support/TestHelper.php +++ b/tests/Support/TestHelper.php @@ -40,7 +40,7 @@ public static function createHydrator(?array $definitions = null): Hydrator return new Hydrator( attributeResolverFactory: new ContainerAttributeResolverFactory($container), objectFactory: new ContainerObjectFactory( - new Injector($container) + new Injector($container), ), ); } @@ -49,7 +49,7 @@ public static function createParameterAttributesHandler(array $definitions): Par { return new ParameterAttributesHandler( new ContainerAttributeResolverFactory( - new SimpleContainer($definitions) + new SimpleContainer($definitions), ), new Hydrator(), );