Skip to content

Commit

Permalink
Fix GH actions
Browse files Browse the repository at this point in the history
  • Loading branch information
SerafimArts committed Aug 1, 2024
1 parent c7cd139 commit 2ef04d1
Show file tree
Hide file tree
Showing 17 changed files with 125 additions and 105 deletions.
3 changes: 2 additions & 1 deletion src/Compiler/CompilerInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@
/**
* @deprecated since phplrt 3.6 and will be removed in 4.0.
*
* @internal This is an internal library interface, please do not use it in your code.
* @internal this is an internal library interface, please do not use it in your code
* @psalm-internal Phplrt\Lexer
*/
interface CompilerInterface
{
/**
* @param array<non-empty-string, non-empty-string> $tokens
*
* @return non-empty-string
*/
public function compile(array $tokens): string;
Expand Down
4 changes: 3 additions & 1 deletion src/Compiler/Markers.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
/**
* @deprecated since phplrt 3.6 and will be removed in 4.0.
*
* @internal This is an internal library class, please do not use it in your code.
* @internal this is an internal library class, please do not use it in your code
* @psalm-internal Phplrt\Lexer
*/
class Markers extends PCRECompiler
Expand All @@ -24,6 +24,7 @@ class Markers extends PCRECompiler

/**
* @param array<array-key, string> $chunks
*
* @return non-empty-string
*
* @psalm-suppress MoreSpecificReturnType
Expand All @@ -37,6 +38,7 @@ protected function buildTokens(array $chunks): string
/**
* @param non-empty-string $name
* @param non-empty-string $pattern
*
* @return non-empty-string
*/
protected function buildToken(string $name, string $pattern): string
Expand Down
16 changes: 11 additions & 5 deletions src/Compiler/PCRECompiler.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
/**
* @deprecated since phplrt 3.6 and will be removed in 4.0.
*
* @internal This is an internal library class, please do not use it in your code.
* @internal this is an internal library class, please do not use it in your code
* @psalm-internal Phplrt\Lexer
*/
abstract class PCRECompiler implements CompilerInterface
Expand Down Expand Up @@ -172,9 +172,8 @@ abstract class PCRECompiler implements CompilerInterface

/**
* @param array<PCRECompiler::FLAG_*>|null $flags
* @param bool|null $debug
*/
public function __construct(array $flags = null, bool $debug = null)
public function __construct(?array $flags = null, ?bool $debug = null)
{
/** @psalm-suppress PropertyTypeCoercion */
$this->flags = $flags ?? self::DEFAULT_FLAGS;
Expand All @@ -189,6 +188,7 @@ public function __construct(array $flags = null, bool $debug = null)

/**
* @param array<non-empty-string, non-empty-string> $tokens
*
* @return non-empty-string
* @throws CompilationException
*/
Expand All @@ -203,12 +203,14 @@ public function compile(array $tokens): string

/**
* @param array<non-empty-string> $chunks
*
* @return non-empty-string
*/
abstract protected function buildTokens(array $chunks): string;

/**
* @param array<non-empty-string, non-empty-string> $tokens
*
* @return array<non-empty-string>
*/
private function buildChunks(array $tokens): array
Expand All @@ -227,12 +229,14 @@ private function buildChunks(array $tokens): array
/**
* @param non-empty-string $name
* @param non-empty-string $pattern
*
* @return non-empty-string
*/
abstract protected function buildToken(string $name, string $pattern): string;

/**
* @param non-empty-string $name
*
* @return non-empty-string
*/
protected function name(string $name): string
Expand All @@ -243,6 +247,7 @@ protected function name(string $name): string

/**
* @param non-empty-string $pattern
*
* @return non-empty-string
*/
protected function pattern(string $pattern): string
Expand All @@ -255,7 +260,7 @@ protected function pattern(string $pattern): string
* @param non-empty-string $pattern
* @param non-empty-string|null $original
*/
protected function test(string $pattern, string $original = null): void
protected function test(string $pattern, ?string $original = null): void
{
if ($this->debug) {
\error_clear_last();
Expand All @@ -272,14 +277,15 @@ protected function test(string $pattern, string $original = null): void

/**
* @param non-empty-string $pcre
*
* @return non-empty-string
*/
protected function wrap(string $pcre): string
{
return $this->delimiter . $pcre . $this->delimiter . \implode('', $this->flags);
}

protected function formatException(string $message, string $token = null): string
protected function formatException(string $message, ?string $token = null): string
{
$suffix = \sprintf(' in %s token definition', $token ?? '<unknown>');

Expand Down
2 changes: 1 addition & 1 deletion src/Config/HandlerInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ interface HandlerInterface
/**
* The method itself, which is executed while processing a token.
*
* @throws LexerRuntimeExceptionInterface May throw an exception while handling the token.
* @throws LexerRuntimeExceptionInterface may throw an exception while handling the token
*/
public function handle(ReadableInterface $source, TokenInterface $token): ?TokenInterface;
}
1 change: 1 addition & 0 deletions src/Config/PassthroughWhenTokenHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ final class PassthroughWhenTokenHandler implements HandlerInterface
{
/**
* @var non-empty-string
*
* @readonly
*/
private string $name;
Expand Down
4 changes: 3 additions & 1 deletion src/Driver/Driver.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
/**
* @deprecated since phplrt 3.6 and will be removed in 4.0.
*
* @internal This is an internal library class, please do not use it in your code.
* @internal this is an internal library class, please do not use it in your code
* @psalm-internal Phplrt\Lexer
*/
abstract class Driver implements DriverInterface
Expand Down Expand Up @@ -38,6 +38,7 @@ public function getCompiler(): CompilerInterface

/**
* @param array<non-empty-string, non-empty-string> $tokens
*
* @return non-empty-string
*/
protected function getPattern(array $tokens): string
Expand All @@ -51,6 +52,7 @@ protected function getPattern(array $tokens): string

/**
* @param array<non-empty-string, non-empty-string> $tokens
*
* @return non-empty-string
*/
protected function compile(array $tokens): string
Expand Down
2 changes: 1 addition & 1 deletion src/Driver/DriverInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
/**
* @deprecated since phplrt 3.6 and will be removed in 4.0.
*
* @internal This is an internal library interface, please do not use it in your code.
* @internal this is an internal library interface, please do not use it in your code
* @psalm-internal Phplrt\Lexer
*/
interface DriverInterface
Expand Down
16 changes: 8 additions & 8 deletions src/Driver/Markers.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@

namespace Phplrt\Lexer\Driver;

use Phplrt\Contracts\Source\SourceExceptionInterface;
use Phplrt\Lexer\Token\Token;
use Phplrt\Lexer\Token\Composite;
use Phplrt\Contracts\Lexer\TokenInterface;
use Phplrt\Contracts\Source\ReadableInterface;
use Phplrt\Contracts\Source\SourceExceptionInterface;
use Phplrt\Lexer\Compiler\Markers as MarkersCompiler;
use Phplrt\Lexer\Token\Composite;
use Phplrt\Lexer\Token\Token;

/**
* @deprecated since phplrt 3.6 and will be removed in 4.0.
*
* @internal This is an internal library class, please do not use it in your code.
* @internal this is an internal library class, please do not use it in your code
* @psalm-internal Phplrt\Lexer
*/
class Markers extends Driver
Expand All @@ -26,15 +26,13 @@ class Markers extends Driver

/**
* @var non-empty-string
*
* @readonly
*/
private string $unknown;

/**
* @param MarkersCompiler|null $compiler
*/
public function __construct(
MarkersCompiler $compiler = null,
?MarkersCompiler $compiler = null,
string $unknown = self::UNKNOWN_TOKEN_NAME
) {
$this->unknown = $unknown;
Expand Down Expand Up @@ -69,6 +67,7 @@ public function run(array $tokens, ReadableInterface $source, int $offset = 0):
/**
* @param non-empty-string $pattern
* @param int<0, max> $offset
*
* @return array<array<int<0, max>, array{string, int}>|array{MARK: non-empty-string}>
*/
private function match(string $pattern, string $source, int $offset): array
Expand All @@ -94,6 +93,7 @@ private function make(string $name, array $payload): TokenInterface
/**
* @param non-empty-string $name
* @param non-empty-array<array-key, array{string, int<0, max>}> $payload
*
* @return non-empty-array<int, TokenInterface>
*/
private function transform(string $name, array $payload): array
Expand Down
4 changes: 2 additions & 2 deletions src/Exception/EndlessRecursionException.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@

namespace Phplrt\Lexer\Exception;

use Phplrt\Contracts\Source\ReadableInterface;
use Phplrt\Contracts\Lexer\TokenInterface;
use Phplrt\Contracts\Source\ReadableInterface;

class EndlessRecursionException extends UnexpectedStateException
{
public static function fromState($state, ReadableInterface $src, ?TokenInterface $tok, \Throwable $e = null): self
public static function fromState($state, ReadableInterface $src, ?TokenInterface $tok, ?\Throwable $e = null): self
{
$message = \vsprintf('An unsolvable infinite lexer state transitions was found at %s', [
$state,
Expand Down
4 changes: 2 additions & 2 deletions src/Exception/LexerRuntimeException.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
namespace Phplrt\Lexer\Exception;

use Phplrt\Contracts\Lexer\LexerRuntimeExceptionInterface;
use Phplrt\Contracts\Lexer\TokenInterface;
use Phplrt\Contracts\Source\ReadableInterface;
use Phplrt\Exception\RuntimeException;
use Phplrt\Contracts\Lexer\TokenInterface;

abstract class LexerRuntimeException extends RuntimeException implements
LexerExceptionInterface,
Expand All @@ -17,7 +17,7 @@ final public function __construct(
string $message,
ReadableInterface $src,
?TokenInterface $tok = null,
\Throwable $prev = null
?\Throwable $prev = null
) {
parent::__construct($message, 0, $prev);

Expand Down
6 changes: 3 additions & 3 deletions src/Exception/UnexpectedStateException.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@

namespace Phplrt\Lexer\Exception;

use Phplrt\Contracts\Source\ReadableInterface;
use Phplrt\Contracts\Lexer\TokenInterface;
use Phplrt\Contracts\Source\ReadableInterface;

class UnexpectedStateException extends LexerRuntimeException
{
public static function fromEmptyStates(ReadableInterface $src, \Throwable $e = null): self
public static function fromEmptyStates(ReadableInterface $src, ?\Throwable $e = null): self
{
$message = 'No state defined for the selected multistate lexer';

Expand All @@ -19,7 +19,7 @@ public static function fromEmptyStates(ReadableInterface $src, \Throwable $e = n
/**
* @param string|int $state
*/
public static function fromState($state, ReadableInterface $src, ?TokenInterface $tok, \Throwable $e = null): self
public static function fromState($state, ReadableInterface $src, ?TokenInterface $tok, ?\Throwable $e = null): self
{
$message = \sprintf('Unrecognized token state #%s', $state);

Expand Down
4 changes: 2 additions & 2 deletions src/Exception/UnrecognizedTokenException.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@

namespace Phplrt\Lexer\Exception;

use Phplrt\Contracts\Lexer\TokenInterface;
use Phplrt\Contracts\Source\ReadableInterface;
use Phplrt\Lexer\Token\Renderer;
use Phplrt\Contracts\Lexer\TokenInterface;

class UnrecognizedTokenException extends LexerRuntimeException
{
public static function fromToken(ReadableInterface $src, TokenInterface $tok, \Throwable $prev = null): self
public static function fromToken(ReadableInterface $src, TokenInterface $tok, ?\Throwable $prev = null): self
{
$message = \vsprintf('Syntax error, unrecognized %s', [
(new Renderer())->render($tok),
Expand Down
Loading

0 comments on commit 2ef04d1

Please sign in to comment.