Skip to content

Commit

Permalink
Remove php 7.4 and 8.0 from CI
Browse files Browse the repository at this point in the history
  • Loading branch information
SerafimArts committed Aug 2, 2024
1 parent 61ecbce commit 3bb6f85
Show file tree
Hide file tree
Showing 13 changed files with 41 additions and 202 deletions.
3 changes: 1 addition & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@
"ext-mbstring": "*",
"phplrt/source": "^4.0",
"phplrt/lexer-contracts": "^4.0",
"phplrt/exception": "^4.0",
"symfony/deprecation-contracts": "^2.5|^3.0"
"phplrt/exception": "^4.0"
},
"autoload": {
"psr-4": {
Expand Down
33 changes: 0 additions & 33 deletions resources/.deprecations.php

This file was deleted.

14 changes: 3 additions & 11 deletions src/Config/PassthroughWhenTokenHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,12 @@
*/
final class PassthroughWhenTokenHandler implements HandlerInterface
{
/**
* @var non-empty-string
*
* @readonly
*/
private string $name;

/**
* @param non-empty-string $name
*/
public function __construct(string $name)
{
$this->name = $name;
}
public function __construct(
private readonly string $name,
) {}

public function handle(ReadableInterface $source, TokenInterface $token): ?TokenInterface
{
Expand Down
9 changes: 3 additions & 6 deletions src/Driver/Driver.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,9 @@ abstract class Driver implements DriverInterface
*/
private ?string $pattern = null;

private CompilerInterface $compiler;

public function __construct(CompilerInterface $compiler)
{
$this->compiler = $compiler;
}
public function __construct(
private readonly CompilerInterface $compiler,
) {}

public function reset(): void
{
Expand Down
11 changes: 1 addition & 10 deletions src/Driver/Markers.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,10 @@ class Markers extends Driver
*/
private const UNKNOWN_PATTERN = '.+?';

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

public function __construct(
?MarkersCompiler $compiler = null,
string $unknown = self::UNKNOWN_TOKEN_NAME
private readonly string $unknown = self::UNKNOWN_TOKEN_NAME
) {
$this->unknown = $unknown;

parent::__construct($compiler ?? new MarkersCompiler());
}

Expand Down
85 changes: 8 additions & 77 deletions src/Lexer.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,6 @@ class Lexer implements PositionalLexerInterface, MutableLexerInterface
*/
public const DEFAULT_EOI_TOKEN_NAME = EndOfInput::DEFAULT_TOKEN_NAME;

/**
* @var array<array-key, non-empty-string>
*/
protected array $tokens = [];

/**
* @var list<non-empty-string>
*/
protected array $skip = [];

private DriverInterface $driver;

private HandlerInterface $onHiddenToken;
Expand All @@ -65,22 +55,10 @@ class Lexer implements PositionalLexerInterface, MutableLexerInterface

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

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

/**
* @readonly
*/
private SourceFactoryInterface $sources;
private readonly SourceFactoryInterface $sources;

/**
* @param array<array-key, non-empty-string> $tokens list of
Expand Down Expand Up @@ -117,22 +95,20 @@ class Lexer implements PositionalLexerInterface, MutableLexerInterface
* @param non-empty-string $eoi
*/
public function __construct(
array $tokens = [],
array $skip = [],
protected array $tokens = [],
protected array $skip = [],
?DriverInterface $driver = null,
?HandlerInterface $onHiddenToken = null,
?HandlerInterface $onUnknownToken = null,
?HandlerInterface $onEndOfInput = null,
string $unknown = Lexer::DEFAULT_UNKNOWN_TOKEN_NAME,
string $eoi = Lexer::DEFAULT_EOI_TOKEN_NAME,
/**
* @readonly
*/
private string $eoi = Lexer::DEFAULT_EOI_TOKEN_NAME,
?SourceFactoryInterface $sources = null
) {
$this->tokens = $tokens;
$this->skip = $skip;

$this->driver = $driver ?? new Markers(new MarkersCompiler(), $unknown);

$this->eoi = $eoi;
$this->unknown = $unknown;

$this->onHiddenToken = $onHiddenToken ?? new NullHandler();
Expand All @@ -142,21 +118,6 @@ public function __construct(
$this->sources = $sources ?? new SourceFactory();
}

/**
* @deprecated since phplrt 3.6 and will be removed in 4.0. Please use
* "$onUnknownToken" argument of the {@see __construct()}
* or {@see Lexer::withUnknownTokenHandler()} method instead.
*/
public function disableUnrecognizedTokenException(): void
{
trigger_deprecation('phplrt/lexer', '3.6', <<<'MSG'
Using "%s::disableUnrecognizedTokenException()" is deprecated.
Please use %1$s::withUnknownTokenHandler() instead.
MSG, static::class);

$this->onUnknownToken = new PassthroughHandler();
}

/**
* @psalm-immutable This method returns a new {@see LexerInterface} instance
* and does not change the current state of the lexer.
Expand Down Expand Up @@ -208,36 +169,6 @@ public function withEndOfInputHandler(HandlerInterface $handler): self
return $self;
}

/**
* @deprecated since phplrt 3.6 and will be removed in 4.0.
*
* @api
*/
public function getDriver(): DriverInterface
{
trigger_deprecation('phplrt/lexer', '3.6', <<<'MSG'
Using "%s::getDriver()" is deprecated.
MSG, static::class);

return $this->driver;
}

/**
* @deprecated since phplrt 3.6 and will be removed in 4.0.
*
* @api
*/
public function setDriver(DriverInterface $driver): self
{
trigger_deprecation('phplrt/lexer', '3.6', <<<'MSG'
Using "%s::setDriver(DriverInterface $driver)" is deprecated.
MSG, static::class);

$this->driver = $driver;

return $this;
}

public function skip(string ...$tokens): self
{
$this->skip = \array_merge($this->skip, $tokens);
Expand Down
17 changes: 2 additions & 15 deletions src/Multistate.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,6 @@ class Multistate implements PositionalLexerInterface
*/
private array $states = [];

/**
* @var array-key|null
*/
private string|int|null $state;

/**
* @var array<non-empty-string|int<0, max>, array<non-empty-string, non-empty-string|int<0, max>>>
*/
private array $transitions = [];

private SourceFactoryInterface $sources;

private HandlerInterface $onEndOfInput;
Expand All @@ -51,18 +41,15 @@ class Multistate implements PositionalLexerInterface
*/
public function __construct(
array $states,
array $transitions = [],
string|int|null $state = null,
private array $transitions = [],
private string|int|null $state = null,
?HandlerInterface $onEndOfInput = null,
?SourceFactoryInterface $sources = null
) {
foreach ($states as $name => $data) {
$this->setState($name, $data);
}

$this->transitions = $transitions;
$this->state = $state;

$this->onEndOfInput = $onEndOfInput ?? new PassthroughWhenTokenHandler(
Lexer::DEFAULT_EOI_TOKEN_NAME,
);
Expand Down
2 changes: 1 addition & 1 deletion src/Token/BaseToken.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

use Phplrt\Contracts\Lexer\TokenInterface;

abstract class BaseToken implements TokenInterface, \JsonSerializable
abstract class BaseToken implements TokenInterface, \JsonSerializable, \Stringable
{
/**
* @var int<0, max>|null
Expand Down
15 changes: 6 additions & 9 deletions src/Token/Composite.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,17 @@

class Composite extends Token implements CompositeTokenInterface
{
/**
* @var array<int, TokenInterface>
*/
private array $children = [];

/**
* @param array-key $name
* @param int<0, max> $offset
* @param array<int, TokenInterface> $children
*/
public function __construct(int|string $name, string $value, int $offset, array $children)
{
$this->children = $children;

public function __construct(
int|string $name,
string $value,
int $offset,
private array $children,
) {
parent::__construct($name, $value, $offset);
}

Expand Down
21 changes: 4 additions & 17 deletions src/Token/EndOfInput.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,29 +18,16 @@ final class EndOfInput extends BaseToken
*
* @var non-empty-string
*/
public const DEFAULT_TOKEN_NAME = TokenInterface::END_OF_INPUT;

/**
* @var int<0, max>
*/
private int $offset;

/**
* @var array-key
*/
private $name;
public const DEFAULT_TOKEN_NAME = 'T_EOI';

/**
* @param int<0, max> $offset
* @param array-key $name
*/
public function __construct(
int $offset = 0,
$name = self::DEFAULT_TOKEN_NAME
) {
$this->offset = $offset;
$this->name = $name;
}
private readonly int $offset = 0,
private readonly string $name = self::DEFAULT_TOKEN_NAME,
) {}

public function getName(): string
{
Expand Down
15 changes: 6 additions & 9 deletions src/Token/Renderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,12 @@ final class Renderer

public function render(TokenInterface $token): string
{
switch (true) {
case $token instanceof EndOfInput:
return 'end of input';
case $token instanceof UnknownToken:
case $token->getName() === $token->getValue():
return $this->value($token);
}

return \sprintf('%s (%s)', $this->value($token), $this->name($token));
return match (true) {
$token instanceof EndOfInput => 'end of input',
$token instanceof UnknownToken,
$token->getName() === $token->getValue() => $this->value($token),
default => \sprintf('%s (%s)', $this->value($token), $this->name($token)),
};
}

public function value(TokenInterface $token): string
Expand Down
16 changes: 5 additions & 11 deletions src/Token/Token.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,26 +16,20 @@ class Token extends BaseToken
*/
private string|int $name;

private string $value;

/**
* @var int<0, max>
*/
private int $offset;

/**
* @param array-key $name
* @param int<0, max> $offset
*/
public function __construct(string|int $name, string $value, int $offset = 0)
{
public function __construct(
string|int $name,
private readonly string $value,
private readonly int $offset = 0,
) {
if ($name === '') {
$name = self::$anonymousId++;
}

$this->name = $name;
$this->value = $value;
$this->offset = $offset;
}

public static function empty(): UnknownToken
Expand Down
Loading

0 comments on commit 3bb6f85

Please sign in to comment.