diff --git a/CHANGELOG.md b/CHANGELOG.md index 856607b..d294eec 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ class (@olegbaturin) - Chg #137: Add separate parameters for each of `HtmlRenderer` settings in constructor. Mark `$settings` parameter as deprecated (@vjik) +- Enh #138: Raise the minimum PHP version to 8.1 and minor refactoring (@vjik) ## 3.3.0 July 11, 2024 diff --git a/rector.php b/rector.php index 8dbe349..75ff290 100644 --- a/rector.php +++ b/rector.php @@ -6,24 +6,19 @@ use Rector\Config\RectorConfig; use Rector\Php71\Rector\FuncCall\RemoveExtraParametersRector; use Rector\Php74\Rector\Closure\ClosureToArrowFunctionRector; -use Rector\Set\ValueObject\LevelSetList; +use Rector\Php81\Rector\FuncCall\NullToStrictStringFuncCallArgRector; -return static function (RectorConfig $rectorConfig): void { - $rectorConfig->paths([ +return RectorConfig::configure() + ->withPaths([ __DIR__ . '/src', __DIR__ . '/tests', - ]); - - // register a single rule - $rectorConfig->rule(InlineConstructorDefaultToPropertyRector::class); - - // define sets of rules - $rectorConfig->sets([ - LevelSetList::UP_TO_PHP_80, - ]); - - $rectorConfig->skip([ + ]) + ->withPhpSets(php81: true) + ->withRules([ + InlineConstructorDefaultToPropertyRector::class, + ]) + ->withSkip([ ClosureToArrowFunctionRector::class, + NullToStrictStringFuncCallArgRector::class, RemoveExtraParametersRector::class, ]); -}; diff --git a/src/CompositeException.php b/src/CompositeException.php index 75cb211..36862ef 100644 --- a/src/CompositeException.php +++ b/src/CompositeException.php @@ -15,10 +15,10 @@ final class CompositeException extends Exception /** * @var Throwable[] */ - private array $rest; + private readonly array $rest; public function __construct( - private Throwable $first, + private readonly Throwable $first, Throwable ...$rest, ) { $this->rest = $rest; diff --git a/src/ErrorData.php b/src/ErrorData.php index 7a5f686..e446a57 100644 --- a/src/ErrorData.php +++ b/src/ErrorData.php @@ -17,8 +17,8 @@ final class ErrorData implements Stringable * @param array $headers The headers to add to the response. */ public function __construct( - private string $content, - private array $headers = [], + private readonly string $content, + private readonly array $headers = [], ) { } diff --git a/src/ErrorHandler.php b/src/ErrorHandler.php index fbf159d..b3d9ae0 100644 --- a/src/ErrorHandler.php +++ b/src/ErrorHandler.php @@ -47,10 +47,10 @@ final class ErrorHandler * @param int $exitShutdownHandlerDepth Depth of the exit() shutdown handler to ensure it's executed last. */ public function __construct( - private LoggerInterface $logger, - private ThrowableRendererInterface $defaultRenderer, - private ?EventDispatcherInterface $eventDispatcher = null, - private int $exitShutdownHandlerDepth = 2 + private readonly LoggerInterface $logger, + private readonly ThrowableRendererInterface $defaultRenderer, + private readonly ?EventDispatcherInterface $eventDispatcher = null, + private readonly int $exitShutdownHandlerDepth = 2 ) { } diff --git a/src/Event/ApplicationError.php b/src/Event/ApplicationError.php index 75791b5..0a5fb66 100644 --- a/src/Event/ApplicationError.php +++ b/src/Event/ApplicationError.php @@ -11,8 +11,9 @@ */ final class ApplicationError { - public function __construct(private Throwable $throwable) - { + public function __construct( + private readonly Throwable $throwable, + ) { } public function getThrowable(): Throwable diff --git a/src/Exception/ErrorException.php b/src/Exception/ErrorException.php index 2c27edf..1ae9627 100644 --- a/src/Exception/ErrorException.php +++ b/src/Exception/ErrorException.php @@ -40,8 +40,15 @@ class ErrorException extends \ErrorException implements FriendlyExceptionInterfa ]; /** @psalm-param DebugBacktraceType $backtrace */ - public function __construct(string $message = '', int $code = 0, int $severity = 1, string $filename = __FILE__, int $line = __LINE__, Exception $previous = null, private array $backtrace = []) - { + public function __construct( + string $message = '', + int $code = 0, + int $severity = 1, + string $filename = __FILE__, + int $line = __LINE__, + Exception $previous = null, + private readonly array $backtrace = [], + ) { parent::__construct($message, $code, $severity, $filename, $line, $previous); $this->addXDebugTraceToFatalIfAvailable(); } diff --git a/src/Middleware/ErrorCatcher.php b/src/Middleware/ErrorCatcher.php index 73ec0a6..097e3da 100644 --- a/src/Middleware/ErrorCatcher.php +++ b/src/Middleware/ErrorCatcher.php @@ -21,8 +21,8 @@ final class ErrorCatcher implements MiddlewareInterface { public function __construct( - private ThrowableResponseFactoryInterface $throwableResponseFactory, - private ?EventDispatcherInterface $eventDispatcher = null, + private readonly ThrowableResponseFactoryInterface $throwableResponseFactory, + private readonly ?EventDispatcherInterface $eventDispatcher = null, ) { } diff --git a/src/Middleware/ExceptionResponder.php b/src/Middleware/ExceptionResponder.php index 21334ab..b912c44 100644 --- a/src/Middleware/ExceptionResponder.php +++ b/src/Middleware/ExceptionResponder.php @@ -55,10 +55,10 @@ final class ExceptionResponder implements MiddlewareInterface * catching exceptions that can be thrown in the process of body generation. */ public function __construct( - private array $exceptionMap, - private ResponseFactoryInterface $responseFactory, - private Injector $injector, - private bool $checkResponseBody = false, + private readonly array $exceptionMap, + private readonly ResponseFactoryInterface $responseFactory, + private readonly Injector $injector, + private readonly bool $checkResponseBody = false, ) { } diff --git a/src/Renderer/HtmlRenderer.php b/src/Renderer/HtmlRenderer.php index 86ba30e..9449187 100644 --- a/src/Renderer/HtmlRenderer.php +++ b/src/Renderer/HtmlRenderer.php @@ -51,36 +51,36 @@ */ final class HtmlRenderer implements ThrowableRendererInterface { - private GithubMarkdown $markdownParser; + private readonly GithubMarkdown $markdownParser; /** * @var string The full path to the default template directory. */ - private string $defaultTemplatePath; + private readonly string $defaultTemplatePath; /** * @var string The full path of the template file for rendering exceptions without call stack information. * * This template should be used in production. */ - private string $template; + private readonly string $template; /** * @var string The full path of the template file for rendering exceptions with call stack information. * * This template should be used in development. */ - private string $verboseTemplate; + private readonly string $verboseTemplate; /** * @var int The maximum number of source code lines to be displayed. Defaults to 19. */ - private int $maxSourceLines; + private readonly int $maxSourceLines; /** * @var int The maximum number of trace source code lines to be displayed. Defaults to 13. */ - private int $maxTraceLines; + private readonly int $maxTraceLines; /** * @var string|null The trace header line with placeholders to be be substituted. Defaults to null. @@ -94,7 +94,7 @@ final class HtmlRenderer implements ThrowableRendererInterface * {icon} * ``` */ - private ?string $traceHeaderLine; + private readonly ?string $traceHeaderLine; /** * @var string[]|null The list of vendor paths is determined automatically.