Skip to content

Commit 3881799

Browse files
committed
Refactor
1 parent 535692e commit 3881799

File tree

18 files changed

+85
-94
lines changed

18 files changed

+85
-94
lines changed

src/Compiler/StandardCompiler.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919

2020
final class StandardCompiler implements CompilerInterface
2121
{
22-
private const OPENING_PARENTHESIS = '(';
23-
private const CLOSING_PARENTHESIS = ')';
22+
private const string OPENING_PARENTHESIS = '(';
23+
private const string CLOSING_PARENTHESIS = ')';
2424

2525
private string $output = '';
2626
private int $openParenthesis = 0;

src/Expression/ExpressionFactory.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,13 @@
99

1010
use nicoSWD\Rule\Parser\Exception\ParserException;
1111
use nicoSWD\Rule\TokenStream\Token;
12+
use nicoSWD\Rule\TokenStream\Token\BaseToken;
1213
use nicoSWD\Rule\TokenStream\Token\Type\Operator;
1314

1415
final class ExpressionFactory implements ExpressionFactoryInterface
1516
{
1617
/** @throws ParserException */
17-
public function createFromOperator(Operator $operator): BaseExpression
18+
public function createFromOperator(BaseToken & Operator $operator): BaseExpression
1819
{
1920
return match ($operator::class) {
2021
Token\TokenEqual::class => new EqualExpression(),

src/Expression/ExpressionFactoryInterface.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@
77
*/
88
namespace nicoSWD\Rule\Expression;
99

10+
use nicoSWD\Rule\TokenStream\Token\BaseToken;
1011
use nicoSWD\Rule\TokenStream\Token\Type\Operator;
1112

1213
interface ExpressionFactoryInterface
1314
{
14-
public function createFromOperator(Operator $operator): BaseExpression;
15+
public function createFromOperator(BaseToken & Operator $operator): BaseExpression;
1516
}

src/Grammar/Definition.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@
99

1010
use nicoSWD\Rule\TokenStream\Token\Token;
1111

12-
final class Definition
12+
final readonly class Definition
1313
{
1414
public function __construct(
15-
public readonly Token $token,
16-
public readonly string $regex,
17-
public readonly int $priority,
15+
public Token $token,
16+
public string $regex,
17+
public int $priority,
1818
) {
1919
}
2020
}

src/Grammar/InternalFunction.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@
77
*/
88
namespace nicoSWD\Rule\Grammar;
99

10-
final class InternalFunction
10+
final readonly class InternalFunction
1111
{
1212
public function __construct(
13-
public readonly string $name,
14-
public readonly string $class,
13+
public string $name,
14+
public string $class,
1515
) {
1616
}
1717
}

src/Grammar/InternalMethod.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@
77
*/
88
namespace nicoSWD\Rule\Grammar;
99

10-
final class InternalMethod
10+
final readonly class InternalMethod
1111
{
1212
public function __construct(
13-
public readonly string $name,
14-
public readonly string $class,
13+
public string $name,
14+
public string $class,
1515
) {
1616
}
1717
}

src/Grammar/JavaScript/Methods/Substr.php

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,8 @@ final class Substr extends CallableFunction
1515
{
1616
public function call(?BaseToken ...$parameters): BaseToken
1717
{
18-
$params = [];
1918
$start = $this->parseParameter($parameters, numParam: 0);
20-
21-
if (!$start) {
22-
$params[] = 0;
23-
} else {
24-
$params[] = (int) $start->getValue();
25-
}
19+
$params = [(int) $start?->getValue()];
2620

2721
$offset = $this->parseParameter($parameters, numParam: 1);
2822

src/Grammar/JavaScript/Methods/Test.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public function call(?BaseToken ...$parameters): BaseToken
2727
if (!$string) {
2828
$bool = false;
2929
} else {
30-
// Remove "g" modifier as is does not exist in PHP
30+
// Remove "g" modifier as it does not exist in PHP
3131
// It's also irrelevant in .test() but allowed in JS here
3232
$pattern = preg_replace_callback(
3333
'~/[igm]{0,3}$~',

src/Highlighter/Highlighter.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,15 @@
77
*/
88
namespace nicoSWD\Rule\Highlighter;
99

10-
use ArrayIterator;
10+
use Iterator;
1111
use nicoSWD\Rule\Tokenizer\TokenizerInterface;
1212
use nicoSWD\Rule\TokenStream\Token\BaseToken;
1313
use nicoSWD\Rule\TokenStream\Token\TokenType;
1414
use SplObjectStorage;
1515

1616
final class Highlighter
1717
{
18-
private readonly SplObjectStorage $styles;
18+
private SplObjectStorage $styles;
1919

2020
public function __construct(
2121
private readonly TokenizerInterface $tokenizer,
@@ -33,7 +33,7 @@ public function highlightString(string $string): string
3333
return $this->highlightTokens($this->tokenizer->tokenize($string));
3434
}
3535

36-
public function highlightTokens(ArrayIterator $tokens): string
36+
public function highlightTokens(Iterator $tokens): string
3737
{
3838
$string = '';
3939

src/Parser/Parser.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,12 @@
1515
use nicoSWD\Rule\TokenStream\Token\TokenType;
1616
use nicoSWD\Rule\TokenStream\Token\Type\Operator;
1717

18-
final class Parser
18+
final readonly class Parser
1919
{
2020
public function __construct(
21-
private readonly TokenStream $tokenStream,
22-
private readonly EvaluatableExpressionFactory $expressionFactory,
23-
private readonly CompilerFactoryInterface $compilerFactory,
21+
private TokenStream $tokenStream,
22+
private EvaluatableExpressionFactory $expressionFactory,
23+
private CompilerFactoryInterface $compilerFactory,
2424
) {
2525
}
2626

0 commit comments

Comments
 (0)