Skip to content

Commit

Permalink
Fix rector deprecations
Browse files Browse the repository at this point in the history
  • Loading branch information
SerafimArts committed Sep 10, 2024
1 parent 5dbc0b0 commit 2718356
Show file tree
Hide file tree
Showing 28 changed files with 562 additions and 85 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
strategy:
fail-fast: false
matrix:
php: [ '7.4', '8.0', '8.1', '8.2', '8.3', '8.4' ]
php: [ '8.1', '8.2', '8.3', '8.4' ]
os: [ ubuntu-latest, macos-latest, windows-latest ]
stability: [ prefer-lowest, prefer-stable ]
steps:
Expand Down
28 changes: 16 additions & 12 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,13 @@
],
"require": {
"php": "^8.1",
"phplrt/source": "^4.0",
"phplrt/buffer": "^4.0",
"phplrt/exception": "^4.0",
"phplrt/parser-contracts": "^4.0",
"phplrt/lexer-contracts": "^4.0",
"phplrt/ast-contracts": "^4.0"
"phplrt/source": "^3.7",
"phplrt/buffer": "^3.7",
"phplrt/exception": "^3.7",
"phplrt/parser-contracts": "^3.7",
"phplrt/lexer-contracts": "^3.7",
"phplrt/ast-contracts": "^3.7",
"symfony/deprecation-contracts": "^2.5|^3.0"
},
"replace": {
"phplrt/grammar": "<=3.1",
Expand All @@ -31,11 +32,14 @@
"autoload": {
"psr-4": {
"Phplrt\\Parser\\": "src"
}
},
"files": [
"src/polyfill.php"
]
},
"require-dev": {
"phplrt/visitor": "^4.0",
"phplrt/lexer": "^4.0",
"phplrt/visitor": "^3.7",
"phplrt/lexer": "^3.7",
"phpunit/phpunit": "^10.5|^11.0",
"phpstan/extension-installer": "^1.4",
"phpstan/phpstan": "^1.11",
Expand All @@ -48,12 +52,12 @@
}
},
"provide": {
"phplrt/parser-contracts-implementation": "^4.0"
"phplrt/parser-contracts-implementation": "^3.7"
},
"extra": {
"branch-alias": {
"dev-master": "4.x-dev",
"dev-main": "4.x-dev"
"dev-master": "3.x-dev",
"dev-main": "3.x-dev"
}
},
"config": {
Expand Down
91 changes: 91 additions & 0 deletions resources/.deprecations.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
<?php

namespace Phplrt\Grammar {

/**
* @deprecated since phplrt 3.2 and will be removed in 4.0, use {@see \Phplrt\Parser\Grammar\Terminal} instead.
*/
abstract class Terminal extends \Phplrt\Parser\Grammar\Terminal
{
}

/**
* @deprecated since phplrt 3.2 and will be removed in 4.0, use {@see \Phplrt\Parser\Grammar\Repetition} instead.
*/
class Repetition extends \Phplrt\Parser\Grammar\Repetition
{
}

/**
* @deprecated since phplrt 3.2 and will be removed in 4.0, use {@see \Phplrt\Parser\Grammar\Optional} instead.
*/
class Optional extends \Phplrt\Parser\Grammar\Optional
{
}

/**
* @deprecated since phplrt 3.2 and will be removed in 4.0, use {@see \Phplrt\Parser\Grammar\Production} instead.
*/
abstract class Production extends \Phplrt\Parser\Grammar\Production
{
}

/**
* @deprecated since phplrt 3.2 and will be removed in 4.0, use {@see \Phplrt\Parser\Grammar\Concatenation} instead.
*/
class Concatenation extends \Phplrt\Parser\Grammar\Concatenation
{
}

/**
* @deprecated since phplrt 3.2 and will be removed in 4.0, use {@see \Phplrt\Parser\Grammar\Builder} instead.
*/
class Builder extends \Phplrt\Parser\Grammar\Builder
{
}

/**
* @deprecated since phplrt 3.2 and will be removed in 4.0, use {@see \Phplrt\Parser\Grammar\Rule} instead.
*/
class Rule extends \Phplrt\Parser\Grammar\Rule
{
}

/**
* @deprecated since phplrt 3.2 and will be removed in 4.0, use {@see \Phplrt\Parser\Grammar\Lexeme} instead.
*/
class Lexeme extends \Phplrt\Parser\Grammar\Lexeme
{
}

/**
* @deprecated since phplrt 3.2 and will be removed in 4.0, use {@see \Phplrt\Parser\Grammar\Alternation} instead.
*/
class Alternation extends \Phplrt\Parser\Grammar\Alternation
{
}
}

namespace Phplrt\Contracts\Grammar {

/**
* @deprecated since phplrt 3.2 and will be removed in 4.0, use {@see \Phplrt\Parser\Grammar\ProductionInterface} instead.
*/
interface ProductionInterface extends \Phplrt\Parser\Grammar\ProductionInterface
{
}

/**
* @deprecated since phplrt 3.2 and will be removed in 4.0, use {@see \Phplrt\Parser\Grammar\RuleInterface} instead.
*/
interface RuleInterface extends \Phplrt\Parser\Grammar\RuleInterface
{
}

/**
* @deprecated since phplrt 3.2 and will be removed in 4.0, use {@see \Phplrt\Parser\Grammar\TerminalInterface} instead.
*/
interface TerminalInterface extends \Phplrt\Parser\Grammar\TerminalInterface
{
}
}
2 changes: 1 addition & 1 deletion src/BuilderInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ interface BuilderInterface
/**
* @param NodeInterface|TokenInterface|iterable<NodeInterface|TokenInterface> $result
*/
public function build(Context $context, mixed $result);
public function build(Context $context, $result);
}
63 changes: 42 additions & 21 deletions src/Context.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,13 @@
* The presence of public modifiers in fields is required only to speed up the
* parser, since direct access is several times faster than using methods of
* setting values or creating a new class at each step of the parser.
*
* @property-read ReadableInterface $source
* @property-read BufferInterface $buffer
*
* @final marked as final since phplrt 3.4 and will be final since 4.0
*/
final class Context
class Context implements ContextInterface
{
use ContextOptionsTrait;

Expand Down Expand Up @@ -54,30 +59,46 @@ final class Context
*/
public ?RuleInterface $rule = null;

/**
* Contains the identifier of the current state of the parser.
*
* Note: This is a stateful data and may cause a race condition error. In
* the future, it is necessary to delete this data with a replacement for
* the stateless structure.
*
* @var array-key
*/
public $state;

/**
* Contains information about the processed source.
*
* @readonly marked as readonly since phplrt 3.4 and will be readonly since 4.0
*
* @psalm-readonly-allow-private-mutation
*/
public ReadableInterface $source;

/**
* Contains a buffer of tokens that were collected from lexical analysis.
*
* @readonly marked as readonly since phplrt 3.4 and will be readonly since 4.0
*
* @psalm-readonly-allow-private-mutation
*/
public BufferInterface $buffer;

/**
* @param array-key $state
* @param array<non-empty-string, mixed> $options
*/
public function __construct(
/**
* Contains a buffer of tokens that were collected from lexical analysis.
*/
public readonly BufferInterface $buffer,
/**
* Contains information about the processed source.
*/
public readonly ReadableInterface $source,
/**
* Contains the identifier of the current state of the parser.
*
* Note: This is a stateful data and may cause a race condition error. In
* the future, it is necessary to delete this data with a replacement for
* the stateless structure.
*/
public string|int $state,
array $options
) {
public function __construct(BufferInterface $buffer, ReadableInterface $source, $state, array $options)
{
$this->state = $state;
$this->source = $source;
$this->buffer = $buffer;
$this->options = $options;

$this->lastOrdinalToken = $this->lastProcessedToken = $this->buffer->current();
}

Expand Down Expand Up @@ -106,7 +127,7 @@ public function getToken(): TokenInterface
return $this->lastProcessedToken;
}

public function getState(): int|string
public function getState()
{
return $this->state;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Context/ContextOptionsProviderInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public function getOptions(): array;
*
* @return TArgDefault|mixed
*/
public function getOption(string $name, mixed $default = null): mixed;
public function getOption(string $name, $default = null);

/**
* Determine if the given option value exists.
Expand Down
2 changes: 1 addition & 1 deletion src/Context/ContextOptionsTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public function getOptions(): array
return $this->options;
}

public function getOption(string $name, mixed $default = null): mixed
public function getOption(string $name, $default = null)
{
return $this->options[$name] ?? $default;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Context/TreeBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public function __construct(iterable $reducers)
$this->reducers = $reducers;
}

public function build(Context $context, mixed $result): mixed
public function build(Context $context, $result)
{
if (isset($this->reducers[$context->state])) {
return ($this->reducers[$context->state])($context, $result);
Expand Down
61 changes: 61 additions & 0 deletions src/ContextInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<?php

declare(strict_types=1);

namespace Phplrt\Parser;

use Phplrt\Buffer\BufferInterface;
use Phplrt\Contracts\Lexer\TokenInterface;
use Phplrt\Contracts\Source\ReadableInterface;
use Phplrt\Parser\Grammar\RuleInterface;

/**
* Interface provides full information about execution context.
*
* @deprecated since phplrt 3.4 and will be removed in 4.0, please use {@see Context} instead.
*/
interface ContextInterface extends ContextOptionsInterface
{
/**
* Returns the source being processed.
*/
public function getSource(): ReadableInterface;

/**
* Returns a lexer's buffer.
*/
public function getBuffer(): BufferInterface;

/**
* Returns the parser's current state identifier.
*
* Note: Please note that this value is mutable and may change over time.
*
* @return array-key
*/
public function getState();

/**
* Returns the parser's current state rule.
*
* Note: Please note that this value is mutable and may change over time.
*/
public function getRule(): ?RuleInterface;

/**
* Returns the parser's current AST node.
*
* If the parser does not contain any nodes of the abstract syntax tree,
* then the method will return NULL.
*
* Note: Please note that this value is mutable and may change over time.
*/
public function getNode(): ?object;

/**
* Returns the current parsing token.
*
* Note: Please note that this value is mutable and may change over time.
*/
public function getToken(): TokenInterface;
}
13 changes: 13 additions & 0 deletions src/ContextOptionsInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

declare(strict_types=1);

namespace Phplrt\Parser;

use Phplrt\Parser\Context\ContextOptionsProviderInterface;

/**
* @deprecated since phplrt 3.4 and will be removed in 4.0, please
* use {@see ContextOptionsProviderInterface} instead.
*/
interface ContextOptionsInterface extends ContextOptionsProviderInterface {}
4 changes: 3 additions & 1 deletion src/Environment/Factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@ final class Factory implements SelectorInterface
{
/**
* @var list<SelectorInterface>
*
* @readonly
*/
private readonly array $selectors;
private array $selectors;

/**
* Factory "prepared" state.
Expand Down
Loading

0 comments on commit 2718356

Please sign in to comment.