diff --git a/src/ErrorInformationRenderer.php b/src/ErrorInformationRenderer.php index e0fab0b..18ae6b8 100644 --- a/src/ErrorInformationRenderer.php +++ b/src/ErrorInformationRenderer.php @@ -36,13 +36,11 @@ class ErrorInformationRenderer private string $highlightChar = self::DEFAULT_HIGHLIGHT_CHAR; - private TokenInterface $token; - - public function __construct(ReadableInterface $source, TokenInterface $token) - { - $this->token = $token; - - $this->position = Position::fromOffset($source, $token->getOffset()); + public function __construct( + ReadableInterface $source, + private readonly TokenInterface $token, + ) { + $this->position = Position::fromOffset($source, $this->token->getOffset()); $this->reader = new LineReader($source); } diff --git a/src/RuntimeException.php b/src/RuntimeException.php index f22d7a8..2bffed5 100644 --- a/src/RuntimeException.php +++ b/src/RuntimeException.php @@ -18,13 +18,12 @@ abstract class RuntimeException extends \RuntimeException implements RuntimeExce private ?ReadableInterface $source = null; - private string $original; - - public function __construct(string $message = '', int $code = 0, ?\Throwable $previous = null) - { - $this->original = $message; - - parent::__construct($message, $code, $previous); + public function __construct( + private readonly string $original = '', + int $code = 0, + ?\Throwable $previous = null, + ) { + parent::__construct($this->original, $code, $previous); } public function getOriginalMessage(): string diff --git a/src/UndefinedToken.php b/src/UndefinedToken.php index 7b244a8..7577be9 100644 --- a/src/UndefinedToken.php +++ b/src/UndefinedToken.php @@ -6,22 +6,20 @@ use Phplrt\Contracts\Lexer\TokenInterface; use Phplrt\Contracts\Position\PositionInterface; +use Phplrt\Lexer\Token\EndOfInput; /** * @internal This class can be used for internal representation of exceptions */ final class UndefinedToken implements TokenInterface { - private PositionInterface $position; - - public function __construct(PositionInterface $position) - { - $this->position = $position; - } + public function __construct( + private readonly PositionInterface $position, + ) {} public function getName(): string { - return TokenInterface::END_OF_INPUT; + return EndOfInput::DEFAULT_TOKEN_NAME; } public function getOffset(): int diff --git a/tests/Unit/UndefinedTokenTest.php b/tests/Unit/UndefinedTokenTest.php index dcb1efa..eb49fbc 100644 --- a/tests/Unit/UndefinedTokenTest.php +++ b/tests/Unit/UndefinedTokenTest.php @@ -6,6 +6,7 @@ use Phplrt\Contracts\Lexer\TokenInterface; use Phplrt\Exception\UndefinedToken; +use Phplrt\Lexer\Token\EndOfInput; use Phplrt\Position\Position; class UndefinedTokenTest extends TestCase @@ -19,7 +20,7 @@ public function testName(): void { $token = $this->create(); - $this->assertSame(TokenInterface::END_OF_INPUT, $token->getName()); + $this->assertSame(EndOfInput::DEFAULT_TOKEN_NAME, $token->getName()); } public function testOffset(): void