Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 13 additions & 10 deletions .github/workflows/phpqa.yml
Original file line number Diff line number Diff line change
@@ -1,21 +1,24 @@
name: Static code analysis
name: "Static code analysis"

on: [pull_request]

jobs:
static-code-analysis:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- name: PHPStan
uses: docker://jakzal/phpqa:php8.4
- uses: actions/checkout@v6

- name: "PHPStan"
uses: docker://jakzal/phpqa:php8.5
with:
args: phpstan analyze src/ -l 1
- name: PHP-CS-Fixer
uses: docker://jakzal/phpqa:php8.4

- name: "PHP-CS-Fixer"
uses: docker://jakzal/phpqa:php8.5
with:
args: php-cs-fixer --dry-run --allow-risky=yes --no-interaction --ansi fix
- name: Deptrac
uses: docker://jakzal/phpqa:php8.4
args: php-cs-fixer fix --dry-run --allow-risky=yes --no-interaction --ansi

- name: "Deptrac"
uses: docker://jakzal/phpqa:php8.5
with:
args: deptrac --no-interaction --ansi --formatter-graphviz-display=0
args: deptrac --config-file=depfile.yaml --no-interaction --ansi
30 changes: 30 additions & 0 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

$finder = PhpCsFixer\Finder::create()
->in(__DIR__ . '/src')
->in(__DIR__ . '/tests')
->name('*.php')
;

return (new PhpCsFixer\Config())
->setRiskyAllowed(true)
->setRules([
'@PSR12' => true,
'array_syntax' => ['syntax' => 'short'],
'cast_spaces' => ['space' => 'single'],
'no_extra_blank_lines' => true,
'no_trailing_whitespace' => true,
'no_trailing_whitespace_in_comment' => true,
'no_whitespace_in_blank_line' => true,
'ordered_imports' => ['sort_algorithm' => 'alpha'],
'single_quote' => true,
'trailing_comma_in_multiline' => ['elements' => ['arrays']],
'trim_array_spaces' => true,
'no_unused_imports' => true,
'blank_line_after_opening_tag' => true,
'blank_line_before_statement' => [
'statements' => ['return'],
],
])
->setFinder($finder)
;
45 changes: 0 additions & 45 deletions .scrutinizer.yml

This file was deleted.

12 changes: 0 additions & 12 deletions .travis.yml

This file was deleted.

4 changes: 3 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@
"require-dev": {
"phpunit/phpunit": "^13.1",
"mockery/mockery": "^1.6",
"squizlabs/php_codesniffer": "^4.0"
"squizlabs/php_codesniffer": "^4.0",
"friendsofphp/php-cs-fixer": "^3.95",
"qossmic/deptrac-shim": "^1.0"
},
"scripts": {
"test": "vendor/bin/phpunit"
Expand Down
66 changes: 66 additions & 0 deletions depfile.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
parameters:
paths:
- ./src
exclude_files:
- .*test.*
layers:
- name: AST
collectors:
- type: directory
value: src/AST/.*
- name: Grammar
collectors:
- type: directory
value: src/Grammar/.*
- name: Highlighter
collectors:
- type: directory
value: src/Highlighter/.*
- name: Lexer
collectors:
- type: directory
value: src/Lexer/.*
- name: Parser
collectors:
- type: directory
value: src/Parser/.*
- name: TokenStream
collectors:
- type: directory
value: src/TokenStream/.*
- name: Root
collectors:
- type: classNameRegex
value: '/.*Rule(Engine|EngineBuilder)?$/'
ruleset:
Root:
- Lexer
- Parser
- TokenStream
- Grammar
- AST
- Highlighter
Parser:
- Lexer
- AST
- TokenStream
AST:
- Grammar
- TokenStream
- Parser
TokenStream:
- Grammar
- Parser
Grammar:
- Lexer
- TokenStream
- Parser
Lexer:
- Grammar
- TokenStream
- Parser
Highlighter:
- Lexer
- Parser
- TokenStream
- Grammar
5 changes: 1 addition & 4 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
parameters:
checkGenericClassInNonGenericObjectType: false
checkMissingIterableValueType: false

excludes_analyse:
excludePaths:
- vendor/
6 changes: 3 additions & 3 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/12.3/phpunit.xsd"
bootstrap="src/autoload.php"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/13.1/phpunit.xsd"
bootstrap="vendor/autoload.php"
cacheDirectory=".phpunit.cache">
<testsuites>
<testsuite name="Unit tests">
Expand All @@ -10,7 +10,7 @@
</testsuites>
<source>
<include>
<directory suffix=".php">src</directory>
<directory>src</directory>
</include>
</source>
</phpunit>
4 changes: 2 additions & 2 deletions src/Grammar/JavaScript/Methods/Join.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@

namespace nicoSWD\Rule\Grammar\JavaScript\Methods;

use nicoSWD\Rule\Grammar\CallableFunction;
use nicoSWD\Rule\Parser\Exception\ParserException;
use nicoSWD\Rule\TokenStream\Token\GenericToken;
use nicoSWD\Rule\TokenStream\Token\TokenKind;
use nicoSWD\Rule\Parser\Exception\ParserException;
use nicoSWD\Rule\Grammar\CallableFunction;

final class Join extends CallableFunction
{
Expand Down
5 changes: 2 additions & 3 deletions src/Grammar/JavaScript/Methods/Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@

namespace nicoSWD\Rule\Grammar\JavaScript\Methods;

use nicoSWD\Rule\Grammar\CallableFunction;
use nicoSWD\Rule\Parser\Exception\ParserException;
use nicoSWD\Rule\TokenStream\Token\BaseToken;
use nicoSWD\Rule\TokenStream\Token\TokenBool;
use nicoSWD\Rule\TokenStream\Token\TokenKind;
use nicoSWD\Rule\Parser\Exception\ParserException;
use nicoSWD\Rule\Grammar\CallableFunction;

final class Test extends CallableFunction
{
Expand All @@ -36,7 +36,6 @@ public function call(mixed ...$parameters): TokenBool
$subject = current($subject);
}


$bool = (bool) preg_match($pattern, (string) $subject);

return TokenBool::fromBool($bool);
Expand Down
1 change: 1 addition & 0 deletions src/Lexer/DefaultLexer.php
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,7 @@ private function readIdentifier(LexerContext $ctx): BaseToken

if ($ctx->startsWith('in')) {
$ctx->pos += 2; // skip 'in'

return $this->tokenFactory->createFromToken(TokenKind::NOT_IN, [TokenKind::NOT_IN->value => 'not in'], $offset);
}

Expand Down
5 changes: 4 additions & 1 deletion src/Parser/Parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@
use nicoSWD\Rule\AST\SubtractionNode;
use nicoSWD\Rule\AST\UnaryMinusNode;
use nicoSWD\Rule\AST\VariableNode;
use nicoSWD\Rule\Lexer\Lexer;
use nicoSWD\Rule\TokenStream\Token\BaseToken;
use nicoSWD\Rule\TokenStream\Token\TokenKind;
use nicoSWD\Rule\TokenStream\TokenIterator;
use nicoSWD\Rule\Lexer\Lexer;

/**
* Recursive descent parser that builds an AST from the token stream.
Expand Down Expand Up @@ -237,12 +237,14 @@ private function parsePrimary(TokenIterator $tokens): Node
// Array literal (may have method calls chained)
if ($token->isOfKind(TokenKind::OPENING_ARRAY)) {
$node = $this->parseArrayLiteral($tokens);

return $this->parseMethodChain($node, $tokens);
}

// Function call
if ($token->isOfKind(TokenKind::FUNCTION)) {
$node = $this->parseFunctionCall($tokens);

return $this->parseMethodChain($node, $tokens);
}

Expand Down Expand Up @@ -368,6 +370,7 @@ private function parseCommaSeparatedList(TokenIterator $tokens, callable $isTerm
// Closing token ends the list
if ($isTerminator($token)) {
$tokens->next(); // consume the closing token

return $items;
}

Expand Down
2 changes: 1 addition & 1 deletion src/RuleEngineBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
use nicoSWD\Rule\AST\AstEvaluator;
use nicoSWD\Rule\Grammar\Grammar;
use nicoSWD\Rule\Grammar\JavaScript\JavaScript;
use nicoSWD\Rule\Parser\Parser;
use nicoSWD\Rule\Lexer\DefaultLexer;
use nicoSWD\Rule\Lexer\Lexer;
use nicoSWD\Rule\Parser\Parser;
use nicoSWD\Rule\TokenStream\FunctionRegistry;
use nicoSWD\Rule\TokenStream\MethodRegistry;
use nicoSWD\Rule\TokenStream\ObjectMethodCallerFactory;
Expand Down
1 change: 0 additions & 1 deletion src/TokenStream/MethodRegistry.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ public function get(string $methodName, BaseToken $token, mixed $rawValue = null
return new $this->methods[$methodName]($rawValue);
}


private function registerMethods(): void
{
foreach ($this->grammar->getInternalMethods() as $internalCallable) {
Expand Down
22 changes: 2 additions & 20 deletions src/TokenStream/TokenCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,31 +10,13 @@

namespace nicoSWD\Rule\TokenStream;

use ArrayObject;
use nicoSWD\Rule\TokenStream\Token\BaseToken;

final class TokenCollection extends \ArrayObject
final class TokenCollection extends ArrayObject
{
public function current(): BaseToken
{
/** @var BaseToken $token */
$token = $this->offsetGet($this->key());

return $token;
}

public function add(BaseToken $token): void
{
$this->append($token);
}

public function toArray(): array
{
$items = [];

foreach ($this as $item) {
$items[] = $item->getValue();
}

return $items;
}
}
13 changes: 0 additions & 13 deletions src/autoload.php

This file was deleted.

Loading