Skip to content

Commit

Permalink
rector
Browse files Browse the repository at this point in the history
  • Loading branch information
vjik committed Feb 2, 2025
1 parent 96f6ff1 commit 840fb8e
Show file tree
Hide file tree
Showing 10 changed files with 44 additions and 40 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
25 changes: 10 additions & 15 deletions rector.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
]);
};
4 changes: 2 additions & 2 deletions src/CompositeException.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions src/ErrorData.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ final class ErrorData implements Stringable
* @param array<string, string|string[]> $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 = [],
) {
}

Expand Down
8 changes: 4 additions & 4 deletions src/ErrorHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
) {
}

Expand Down
5 changes: 3 additions & 2 deletions src/Event/ApplicationError.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@
*/
final class ApplicationError
{
public function __construct(private Throwable $throwable)
{
public function __construct(
private readonly Throwable $throwable,
) {
}

public function getThrowable(): Throwable
Expand Down
11 changes: 9 additions & 2 deletions src/Exception/ErrorException.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
4 changes: 2 additions & 2 deletions src/Middleware/ErrorCatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
) {
}

Expand Down
8 changes: 4 additions & 4 deletions src/Middleware/ExceptionResponder.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
) {
}

Expand Down
14 changes: 7 additions & 7 deletions src/Renderer/HtmlRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -94,7 +94,7 @@ final class HtmlRenderer implements ThrowableRendererInterface
* <a href="ide://open?file={file}&line={line}">{icon}</a>
* ```
*/
private ?string $traceHeaderLine;
private readonly ?string $traceHeaderLine;

/**
* @var string[]|null The list of vendor paths is determined automatically.
Expand Down

0 comments on commit 840fb8e

Please sign in to comment.