Skip to content

Commit

Permalink
PHP 8.1 compatibility (#9)
Browse files Browse the repository at this point in the history
  • Loading branch information
MidnightDesign authored Oct 12, 2023
1 parent 7531eaa commit 2bfb596
Show file tree
Hide file tree
Showing 21 changed files with 47 additions and 40 deletions.
6 changes: 6 additions & 0 deletions .github/workflows/checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ jobs:
fail-fast: false
matrix:
php:
- "8.1"
- "8.2"
dependencies:
- ""
Expand Down Expand Up @@ -41,6 +42,7 @@ jobs:
fail-fast: false
matrix:
php:
- "8.1"
- "8.2"
dependencies:
- ""
Expand Down Expand Up @@ -71,6 +73,7 @@ jobs:
fail-fast: false
matrix:
php:
- "8.1"
- "8.2"
dependencies:
- ""
Expand Down Expand Up @@ -101,6 +104,7 @@ jobs:
fail-fast: false
matrix:
php:
- "8.1"
- "8.2"
dependencies:
- ""
Expand Down Expand Up @@ -133,6 +137,7 @@ jobs:
fail-fast: false
matrix:
php:
- "8.1"
- "8.2"
dependencies:
- ""
Expand Down Expand Up @@ -176,6 +181,7 @@ jobs:
fail-fast: false
matrix:
php:
- "8.1"
- "8.2"
dependencies:
- ""
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"license": "MIT",
"type": "library",
"require": {
"php": ">=8.2",
"php": ">=8.1",
"ext-ctype": "*"
},
"require-dev": {
Expand Down
2 changes: 1 addition & 1 deletion src/Assert.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
* @internal
* @psalm-internal Eventjet\Ausdruck
*/
final readonly class Assert
final class Assert
{
public static function string(mixed $value): string
{
Expand Down
10 changes: 5 additions & 5 deletions src/Call.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,18 @@
* @internal
* @psalm-internal Eventjet\Ausdruck
*/
final readonly class Call extends Expression
final class Call extends Expression
{
/**
* @param Expression<mixed> $target
* @param list<Expression<mixed>> $arguments
* @param Type<T> $type
*/
public function __construct(
public Expression $target,
public string $name,
public Type $type,
public array $arguments,
public readonly Expression $target,
public readonly string $name,
public readonly Type $type,
public readonly array $arguments,
) {
}

Expand Down
4 changes: 2 additions & 2 deletions src/Eq.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@
* @internal
* @psalm-internal Eventjet\Ausdruck
*/
final readonly class Eq extends Expression
final class Eq extends Expression
{
/**
* @param Expression<mixed> $left
* @param Expression<mixed> $right
*/
public function __construct(public Expression $left, public Expression $right)
public function __construct(public readonly Expression $left, public readonly Expression $right)
{
}

Expand Down
2 changes: 1 addition & 1 deletion src/Expr.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* @internal
* @psalm-internal Eventjet\Ausdruck
*/
final readonly class Expr
final class Expr
{
/**
* @psalm-suppress UnusedConstructor
Expand Down
2 changes: 1 addition & 1 deletion src/Expression.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* @template-covariant T
* @api
*/
abstract readonly class Expression implements Stringable
abstract class Expression implements Stringable
{
/**
* @param self<mixed> $other
Expand Down
4 changes: 2 additions & 2 deletions src/Get.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@
* @internal
* @psalm-internal Eventjet\Ausdruck
*/
final readonly class Get extends Expression
final class Get extends Expression
{
/**
* @param Type<T> $type
*/
public function __construct(public string $name, private Type $type)
public function __construct(public readonly string $name, private readonly Type $type)
{
}

Expand Down
4 changes: 2 additions & 2 deletions src/Gt.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@
* @internal
* @psalm-internal Eventjet\Ausdruck
*/
final readonly class Gt extends Expression
final class Gt extends Expression
{
/**
* @param Expression<T> $left
* @param Expression<T> $right
*/
public function __construct(private Expression $left, private Expression $right)
public function __construct(private readonly Expression $left, private readonly Expression $right)
{
}

Expand Down
4 changes: 2 additions & 2 deletions src/Lambda.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@
* @internal
* @psalm-internal Eventjet\Ausdruck
*/
final readonly class Lambda extends Expression
final class Lambda extends Expression
{
/**
* @param Expression<T> $body
* @param list<string> $parameters
*/
public function __construct(public Expression $body, public array $parameters = [])
public function __construct(public readonly Expression $body, public readonly array $parameters = [])
{
}

Expand Down
4 changes: 2 additions & 2 deletions src/Literal.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@
* @internal
* @psalm-internal Eventjet\Ausdruck
*/
final readonly class Literal extends Expression
final class Literal extends Expression
{
/**
* @param T $value
*/
public function __construct(private mixed $value)
public function __construct(private readonly mixed $value)
{
}

Expand Down
4 changes: 2 additions & 2 deletions src/Or_.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@
* @internal
* @psalm-internal Eventjet\Ausdruck
*/
final readonly class Or_ extends Expression
final class Or_ extends Expression
{
/**
* @param Expression<bool> $left
* @param Expression<bool> $right
*/
public function __construct(public Expression $left, public Expression $right)
public function __construct(public readonly Expression $left, public readonly Expression $right)
{
}

Expand Down
5 changes: 3 additions & 2 deletions src/Parser/ExpressionParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,20 @@
* @phpstan-type AnyToken Token | string | Literal<string | int | float>
* @api
*/
final readonly class ExpressionParser
final class ExpressionParser
{
/**
* @return Expression<mixed>
*/
public static function parse(string $expression, Types|null $types = null): Expression
{
$chars = $expression === '' ? [] : str_split($expression);
/**
* @infection-ignore-all Currently, there's no difference between str_split and its multibyte version. Multibyte
* string literals and identifiers are just put back together. If you encounter a case where it does matter,
* just change it to mb_str_split and add an appropriate test case.
*/
return self::parseExpression(new Peekable(Tokenizer::tokenize(str_split($expression))), $types ?? new Types());
return self::parseExpression(new Peekable(Tokenizer::tokenize($chars)), $types ?? new Types());
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/Parser/Literal.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@
* @internal
* @psalm-internal Eventjet\Ausdruck
*/
final readonly class Literal implements Stringable
final class Literal implements Stringable
{
/**
* @param T $value
*/
public function __construct(public string|int|float $value)
public function __construct(public readonly string|int|float $value)
{
}

Expand Down
4 changes: 2 additions & 2 deletions src/Parser/Peekable.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@
* @internal
* @psalm-internal Eventjet\Ausdruck
*/
final readonly class Peekable
final class Peekable
{
/** @var Generator<mixed, T> */
private iterable $items;
private readonly iterable $items;

/**
* @param iterable<mixed, T> $items
Expand Down
2 changes: 1 addition & 1 deletion src/Parser/Tokenizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* @internal
* @psalm-internal Eventjet\Ausdruck
*/
final readonly class Tokenizer
final class Tokenizer
{
public const NON_IDENTIFIER_CHARS = '.[]()"=|<>{}:, -';

Expand Down
4 changes: 2 additions & 2 deletions src/Parser/TypeNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@
* @internal
* @psalm-internal Eventjet\Ausdruck
*/
final readonly class TypeNode implements Stringable
final class TypeNode implements Stringable
{
/**
* @param list<self> $args
*/
public function __construct(public string $name, public array $args = [])
public function __construct(public readonly string $name, public readonly array $args = [])
{
}

Expand Down
4 changes: 2 additions & 2 deletions src/Parser/Types.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@
/**
* @api
*/
final readonly class Types
final class Types
{
/**
* @param array<string, Type<mixed>> $aliases
*/
public function __construct(private array $aliases = [])
public function __construct(private readonly array $aliases = [])
{
}

Expand Down
6 changes: 3 additions & 3 deletions src/Scope.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,16 @@
* }
* @api
*/
final readonly class Scope
final class Scope
{
/** @var array<string, callable> */
private array $funcs;
private readonly array $funcs;

/**
* @param array<string, mixed> $vars
* @param array<string, callable> $funcs
*/
public function __construct(private array $vars = [], array $funcs = [], private Scope|null $parent = null)
public function __construct(private readonly array $vars = [], array $funcs = [], private readonly Scope|null $parent = null)
{
$predefinedFuncs = $this->parent === null ? [
'contains' => self::contains(...),
Expand Down
4 changes: 2 additions & 2 deletions src/Subtract.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@
* @internal
* @psalm-internal Eventjet\Ausdruck
*/
final readonly class Subtract extends Expression
final class Subtract extends Expression
{
/**
* @param Expression<T> $minuend
* @param Expression<T> $subtrahend
*/
public function __construct(public Expression $minuend, public Expression $subtrahend)
public function __construct(public readonly Expression $minuend, public readonly Expression $subtrahend)
{
}

Expand Down
6 changes: 3 additions & 3 deletions src/Type.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,17 @@
* @template-covariant T
* @api
*/
final readonly class Type implements Stringable
final class Type implements Stringable
{
/** @var callable(mixed): T */
private mixed $assert;
private readonly mixed $assert;

/**
* @param callable(mixed): T $validate
* @param list<self<mixed>> $args
* @param self<T> | null $aliasFor
*/
private function __construct(public string $name, callable $validate, public array $args = [], public self|null $aliasFor = null)
private function __construct(public readonly string $name, callable $validate, public readonly array $args = [], public readonly self|null $aliasFor = null)
{
$this->assert = $validate;
}
Expand Down

0 comments on commit 2bfb596

Please sign in to comment.