diff --git a/.github/workflows/grumphp.yaml b/.github/workflows/grumphp.yaml index b99ffd2..ddecc4e 100644 --- a/.github/workflows/grumphp.yaml +++ b/.github/workflows/grumphp.yaml @@ -7,7 +7,7 @@ jobs: strategy: matrix: operating-system: [ubuntu-latest] - php-versions: ['7.3', '7.4', '8.0'] + php-versions: ['8.0', '8.1'] composer-options: ['', '--prefer-lowest'] fail-fast: false name: PHP ${{ matrix.php-versions }} @ ${{ matrix.operating-system }} with ${{ matrix.composer-options }} @@ -34,14 +34,7 @@ jobs: path: ${{ steps.composercache.outputs.dir }} key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }} restore-keys: ${{ runner.os }}-composer- - - name: Install dependencies setFinder( - \Symfony\Component\Finder\Finder::create() + PhpCsFixer\Finder::create() ->in([ __DIR__ . '/src', __DIR__ . '/spec', @@ -15,7 +15,7 @@ 'array_indentation' => true, 'array_syntax' => ['syntax' => 'short'], 'backtick_to_shell_exec' => true, - 'blank_line_before_statement' => true, + 'blank_line_before_statement' => ['statements' => ['return']], 'class_keyword_remove' => false, 'combine_consecutive_issets' => true, 'combine_consecutive_unsets' => true, @@ -30,13 +30,13 @@ 'escape_implicit_backslashes' => true, 'explicit_indirect_variable' => true, 'explicit_string_variable' => true, - 'final_internal_class' => false, + 'final_internal_class' => true, 'fully_qualified_strict_types' => true, 'general_phpdoc_annotation_remove' => false, 'header_comment' => false, 'heredoc_to_nowdoc' => false, 'linebreak_after_opening_tag' => true, - 'list_syntax' => true, + 'list_syntax' => ['syntax' => 'short'], 'mb_str_functions' => true, 'method_chaining_indentation' => true, 'multiline_comment_opening_closing' => true, @@ -46,7 +46,7 @@ 'no_blank_lines_before_namespace' => false, 'no_null_property_initialization' => true, 'no_php4_constructor' => true, - 'no_short_echo_tag' => false, + 'echo_tag_syntax' => ['format'=> 'long'], 'no_superfluous_elseif' => true, 'no_unreachable_default_argument_value' => true, 'no_useless_else' => true, @@ -60,16 +60,17 @@ 'php_unit_mock' => false, 'php_unit_namespaced' => false, 'php_unit_no_expectation_annotation' => false, - 'php_unit_ordered_covers' => true, + 'phpdoc_order_by_value' => ['annotations' => ['covers']], 'php_unit_set_up_tear_down_visibility' => true, 'php_unit_strict' => false, 'php_unit_test_annotation' => false, 'php_unit_test_class_requires_covers' => false, + 'php_unit_method_casing' => ['case' => 'snake_case'], 'phpdoc_add_missing_param_annotation' => true, 'phpdoc_order' => true, 'phpdoc_types_order' => ['null_adjustment' => 'always_last'], 'pow_to_exponentiation' => true, - 'psr0' => true, + 'psr_autoloading' => ['dir' => 'src'], 'random_api_migration' => false, 'simplified_null_return' => true, 'static_lambda' => false, @@ -79,5 +80,13 @@ 'ternary_to_null_coalescing' => true, 'void_return' => true, 'yoda_style' => true, + 'single_line_throw' => false, + 'phpdoc_align' => ['align' => 'left'], + 'phpdoc_to_comment' => false, + 'global_namespace_import' => [ + 'import_classes' => true, + 'import_constants' => true, + 'import_functions' => true, + ], ]) ; diff --git a/composer.json b/composer.json index 94269a3..035d20e 100644 --- a/composer.json +++ b/composer.json @@ -3,11 +3,11 @@ "description": "RFC7807 Problem details implementation", "type": "library", "require-dev": { - "friendsofphp/php-cs-fixer": "^2.16.7", - "phpro/grumphp-shim": "^1.2", - "phpspec/phpspec": "^6.3", - "symfony/validator": "^4.4", - "sebastian/comparator": "^1.2.4" + "friendsofphp/php-cs-fixer": "^3.3", + "phpro/grumphp-shim": "^1.6", + "phpspec/phpspec": "^7.0", + "symfony/validator": "^5.3 || ^6.0", + "sebastian/comparator": "^4.0" }, "license": "MIT", "authors": [ @@ -17,7 +17,7 @@ } ], "require": { - "php": "^7.3 || ^8.0" + "php": "^8.0" }, "config": { "sort-packages": true diff --git a/grumphp.yml.dist b/grumphp.yml.dist index e7389bb..d81f891 100644 --- a/grumphp.yml.dist +++ b/grumphp.yml.dist @@ -1,7 +1,7 @@ grumphp: tasks: phpcsfixer2: - config: ".php_cs.dist" + config: ".php-cs-fixer.dist.php" config_contains_finder: true phpspec: format: dot diff --git a/spec/Exception/ApiProblemExceptionSpec.php b/spec/Exception/ApiProblemExceptionSpec.php index f16c1f6..f30dc82 100644 --- a/spec/Exception/ApiProblemExceptionSpec.php +++ b/spec/Exception/ApiProblemExceptionSpec.php @@ -4,6 +4,7 @@ namespace spec\Phpro\ApiProblem\Exception; +use Exception; use Phpro\ApiProblem\ApiProblemInterface; use Phpro\ApiProblem\Exception\ApiProblemException; use PhpSpec\ObjectBehavior; @@ -23,7 +24,7 @@ public function it_is_initializable(): void public function it_is_an_excpetion(): void { - $this->shouldHaveType(\Exception::class); + $this->shouldHaveType(Exception::class); } public function it_contains_an_api_problem(ApiProblemInterface $apiProblem): void diff --git a/spec/Http/ExceptionApiProblemSpec.php b/spec/Http/ExceptionApiProblemSpec.php index c9e1b8b..d87575f 100644 --- a/spec/Http/ExceptionApiProblemSpec.php +++ b/spec/Http/ExceptionApiProblemSpec.php @@ -5,6 +5,7 @@ namespace spec\Phpro\ApiProblem\Http; use Exception; +use InvalidArgumentException; use Phpro\ApiProblem\DebuggableApiProblemInterface; use Phpro\ApiProblem\Http\ExceptionApiProblem; use Phpro\ApiProblem\Http\HttpApiProblem; @@ -148,7 +149,7 @@ public function it_should_deal_with_string_exception_codes(): void public function it_should_use_code_as_status_code_when_valid_http_status_code_error(): void { $message = 'an honest error'; - $this->beConstructedWith(new \InvalidArgumentException($message, 400)); + $this->beConstructedWith(new InvalidArgumentException($message, 400)); $this->toArray()->shouldBe([ 'status' => 400, diff --git a/src/Exception/ApiProblemException.php b/src/Exception/ApiProblemException.php index 7b91162..d93b195 100644 --- a/src/Exception/ApiProblemException.php +++ b/src/Exception/ApiProblemException.php @@ -4,9 +4,10 @@ namespace Phpro\ApiProblem\Exception; +use Exception; use Phpro\ApiProblem\ApiProblemInterface; -class ApiProblemException extends \Exception +class ApiProblemException extends Exception { /** * @var ApiProblemInterface diff --git a/src/Http/ExceptionApiProblem.php b/src/Http/ExceptionApiProblem.php index 669e68e..493ea9c 100644 --- a/src/Http/ExceptionApiProblem.php +++ b/src/Http/ExceptionApiProblem.php @@ -4,6 +4,7 @@ namespace Phpro\ApiProblem\Http; +use function get_class; use Phpro\ApiProblem\DebuggableApiProblemInterface; use Throwable; @@ -23,7 +24,7 @@ public function __construct(Throwable $exception) : 500; parent::__construct($statusCode, [ - 'detail' => $exception->getMessage() ?: \get_class($exception), + 'detail' => $exception->getMessage() ?: get_class($exception), ]); } @@ -51,7 +52,7 @@ public function toDebuggableArray(): array private function serializeException(Throwable $throwable): array { return [ - 'type' => \get_class($throwable), + 'type' => get_class($throwable), 'message' => $throwable->getMessage(), 'code' => $throwable->getCode(), 'line' => $throwable->getLine(),