From 70336e343ee4de1a381dd21ea314eca3d9c6946b Mon Sep 17 00:00:00 2001 From: lukmzig <30526586+lukmzig@users.noreply.github.com> Date: Mon, 25 Nov 2024 14:04:07 +0100 Subject: [PATCH] [Bug] Fix lexer token and workflows (#260) * fix: parser errors caused by lexer version update * fix: sonar --- .github/workflows/php-cs-fixer.yaml | 5 +++-- .github/workflows/sonar.yaml | 4 +++- src/QueryLanguage/Pql/Parser.php | 16 ++++++++-------- 3 files changed, 14 insertions(+), 11 deletions(-) diff --git a/.github/workflows/php-cs-fixer.yaml b/.github/workflows/php-cs-fixer.yaml index e1f17de3..8bc4a184 100644 --- a/.github/workflows/php-cs-fixer.yaml +++ b/.github/workflows/php-cs-fixer.yaml @@ -1,7 +1,7 @@ name: "PHP-CS-Fixer" on: - pull_request: + pull_request_target: branches: - "[0-9]+.[0-9]+" - "[0-9]+.x" @@ -24,7 +24,8 @@ jobs: steps: - uses: actions/checkout@v2 with: - ref: ${{ github.head_ref }} + ref: ${{ github.event.pull_request.head.ref }} + repository: ${{ github.event.pull_request.head.repo.full_name }} - name: PHP-CS-Fixer uses: docker://oskarstark/php-cs-fixer-ga:latest diff --git a/.github/workflows/sonar.yaml b/.github/workflows/sonar.yaml index 051423e8..590c4a8b 100644 --- a/.github/workflows/sonar.yaml +++ b/.github/workflows/sonar.yaml @@ -3,7 +3,7 @@ on: push: branches: - 1.x - pull_request: + pull_request_target: types: [opened, synchronize, reopened] jobs: sonarcloud: @@ -13,6 +13,8 @@ jobs: - uses: actions/checkout@v3 with: fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis + ref: ${{ github.event.pull_request.head.ref }} + repository: ${{ github.event.pull_request.head.repo.full_name }} - name: SonarCloud Scan uses: SonarSource/sonarcloud-github-action@master env: diff --git a/src/QueryLanguage/Pql/Parser.php b/src/QueryLanguage/Pql/Parser.php index 34456e1e..af09f1b4 100644 --- a/src/QueryLanguage/Pql/Parser.php +++ b/src/QueryLanguage/Pql/Parser.php @@ -112,7 +112,7 @@ private function expectRightParenthesis(): void if (!$token || !$token->isA(QueryTokenType::T_RPAREN)) { $this->throwParsingException( 'token type `' . QueryTokenType::T_RPAREN->value . '`', - '`' . ($token['type']->value ?? 'null') . '`' + '`' . ($token->type ?? 'null') . '`' ); } $this->advance(); @@ -175,7 +175,7 @@ private function parseComparison(array &$subQueries): array|ParseResultSubQuery $this->validateCurrentTokenNotEmpty(); if (!$this->currentToken() || !$this->currentToken()->isA(...self::FIELD_NAME_TOKENS)) { - $tokenValue = $this->currentToken()['value'] ?? 'null'; + $tokenValue = $this->currentToken()->value ?? 'null'; $message = null; if (in_arrayi($tokenValue, ['and', 'or', 'like', 'not like', 'null', 'empty'])) { $message = sprintf('Expected %s, found %s.', 'a field name', '`' . $tokenValue . '`') @@ -186,15 +186,15 @@ private function parseComparison(array &$subQueries): array|ParseResultSubQuery /** @var Token $fieldToken */ $fieldToken = $this->currentToken(); - $fieldType = $fieldToken['type']; - $field = $fieldToken['value']; + $fieldType = $fieldToken->type; + $field = $fieldToken->value; $this->advance(); // Move to operator $this->validateCurrentTokenNotEmpty(); $operatorToken = $this->currentToken(); if ($operatorToken === null || !$operatorToken->isA(...self::OPERATOR_TOKENS)) { - $this->throwParsingException('a comparison operator', '`' . ($operatorToken['value'] ?? 'null') . '`'); + $this->throwParsingException('a comparison operator', '`' . $operatorToken->value . '`'); } $this->advance(); // Move to value @@ -205,7 +205,7 @@ private function parseComparison(array &$subQueries): array|ParseResultSubQuery if (!$valueToken || !$valueToken->isA(...self::VALUE_TOKENS)) { $this->throwParsingException( 'a string, numeric value or a empty/null keyword', - '`' . ($valueToken['value'] ?? 'null') . '`' + '`' . $valueToken->value . '`' ); } @@ -214,7 +214,7 @@ private function parseComparison(array &$subQueries): array|ParseResultSubQuery ) { $this->throwParsingException( 'a valid value', - '`' . ($valueToken['value'] ?? 'null') . '`', + '`' . $valueToken->value . '`', 'Operator `' . $operatorToken->value . '` does not support null/empty values' ); } @@ -345,7 +345,7 @@ public function parse(): ParseResult $query = $this->parseCondition($subQueries); if ($token = $this->currentToken()) { - $this->throwParsingException('end of input', '`' . ($token['value'] ?? 'null') . '`'); + $this->throwParsingException('end of input', '`' . $token->value . '`'); } return new ParseResult($query, $subQueries);