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 10578d7 commit 8359f13
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 27 deletions.
31 changes: 14 additions & 17 deletions src/Executor.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,17 +114,14 @@ class Executor implements ExecutorInterface
private const ERROR_NESTED_ARRAY =
'Nested arrays are not a valid traversable AST structure';

/**
* @var array|VisitorInterface[]
*/
private array $visitors = [];

private bool $stop = false;

public function __construct(array $visitors = [])
{
$this->visitors = $visitors;
}
public function __construct(
/**
* @var array|VisitorInterface[]
*/
private array $visitors = []
) {}

/**
* @param iterable<array-key, object> $nodes
Expand Down Expand Up @@ -227,12 +224,12 @@ protected function traverseArray(array $nodes): array

case \is_array($return):
$error = self::ERROR_ENTER_RETURN_ARRAY;
$error = \sprintf($error, \get_class($visitor), \gettype($visitor));
$error = \sprintf($error, $visitor::class, \gettype($visitor));

throw new BadMethodException($error, static::ERROR_CODE_ARRAY_ENTERING);
default:
$error = self::ERROR_ENTER_RETURN_TYPE;
$error = \sprintf($error, \get_class($visitor), \gettype($visitor));
$error = \sprintf($error, $visitor::class, \gettype($visitor));

throw new BadReturnTypeException($error, static::ERROR_CODE_ARRAY_ENTERING);
}
Expand Down Expand Up @@ -271,7 +268,7 @@ protected function traverseArray(array $nodes): array

default:
$error = self::ERROR_LEAVE_RETURN_TYPE;
$error = \sprintf($error, \get_class($visitor), \gettype($return));
$error = \sprintf($error, $visitor::class, \gettype($return));

throw new BadReturnTypeException($error, static::ERROR_CODE_ARRAY_LEAVING);
}
Expand Down Expand Up @@ -338,7 +335,7 @@ protected function traverseNode(NodeInterface $node): NodeInterface

default:
$error = self::ERROR_ENTER_RETURN_TYPE;
$error = \sprintf($error, \get_class($visitor), \gettype($return));
$error = \sprintf($error, $visitor::class, \gettype($return));

throw new BadReturnTypeException($error, static::ERROR_CODE_NODE_ENTERING);
}
Expand Down Expand Up @@ -373,12 +370,12 @@ protected function traverseNode(NodeInterface $node): NodeInterface

case \is_array($return):
$error = self::ERROR_MODIFY_BY_ARRAY;
$error = \sprintf($error, \get_class($visitor));
$error = \sprintf($error, $visitor::class);

throw new BadReturnTypeException($error, static::ERROR_CODE_NODE_LEAVING);
default:
$error = self::ERROR_LEAVE_RETURN_TYPE;
$error = \sprintf($error, \get_class($visitor), \gettype($return));
$error = \sprintf($error, $visitor::class, \gettype($return));

throw new BadReturnTypeException($error, static::ERROR_CODE_NODE_LEAVING);
}
Expand All @@ -400,12 +397,12 @@ private function updateNodeValue(NodeInterface $node, int|string $key, mixed $va
// @phpstan-ignore-next-line
$node->$key = $value;
} catch (\Error $e) {
if (\strpos($e->getMessage(), 'Cannot access') !== 0) {
if (!\str_starts_with($e->getMessage(), 'Cannot access')) {
throw $e;
}

$error = self::ERROR_READONLY_MODIFY;
$error = \sprintf($error, $key, \get_class($node));
$error = \sprintf($error, $key, $node::class);

throw new AttributeException($error);
}
Expand Down
14 changes: 4 additions & 10 deletions src/Traverser.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,18 +46,12 @@

class Traverser implements TraverserInterface
{
/**
* @var list<VisitorInterface>
*/
private array $visitors = [];

/**
* @param list<VisitorInterface> $visitors
*/
final public function __construct(array $visitors = [])
{
$this->visitors = $visitors;
}
final public function __construct(
private array $visitors = [],
) {}

public static function through(VisitorInterface ...$visitors): self
{
Expand All @@ -66,7 +60,7 @@ public static function through(VisitorInterface ...$visitors): self

public function with(VisitorInterface $visitor, bool $prepend = false): TraverserInterface
{
$fn = $prepend ? '\\array_unshift' : '\\array_push';
$fn = $prepend ? \array_unshift(...) : \array_push(...);
$fn($this->visitors, $visitor);

return $this;
Expand Down

0 comments on commit 8359f13

Please sign in to comment.