From 272173a65fd16b25010dbd54d04dd34c0c5a8500 Mon Sep 17 00:00:00 2001 From: Sascha Greuel Date: Sat, 1 Jun 2024 11:15:21 +0200 Subject: [PATCH] 0.9.1 --- .github/workflows/Test.yml | 2 +- CODE_OF_CONDUCT.md | 9 +++------ composer.json | 9 ++++++--- src/Filters/QueryMatchFilter.php | 8 +++++++- 4 files changed, 17 insertions(+), 11 deletions(-) diff --git a/.github/workflows/Test.yml b/.github/workflows/Test.yml index 7ed083c..76226cb 100644 --- a/.github/workflows/Test.yml +++ b/.github/workflows/Test.yml @@ -53,7 +53,7 @@ jobs: run: composer update --prefer-dist --no-interaction - name: Run phpcs - run: phpcs -- -v + run: composer cs - name: Execute tests run: composer test -- --coverage-clover=coverage.xml diff --git a/CODE_OF_CONDUCT.md b/CODE_OF_CONDUCT.md index 82c0c3e..85f1e6f 100644 --- a/CODE_OF_CONDUCT.md +++ b/CODE_OF_CONDUCT.md @@ -22,14 +22,11 @@ include: Examples of unacceptable behavior by participants include: -* The use of sexualized language or imagery and unwelcome sexual attention or - advances +* The use of sexualized language or imagery and unwelcome sexual attention or advances * Trolling, insulting/derogatory comments, and personal or political attacks * Public or private harassment -* Publishing others' private information, such as a physical or electronic - address, without explicit permission -* Other conduct which could reasonably be considered inappropriate in a - professional setting +* Publishing others' private information, such as a physical or electronic address, without explicit permission +* Other conduct which could reasonably be considered inappropriate in a professional setting ## Our Responsibilities diff --git a/composer.json b/composer.json index 0ac0f93..42af9cc 100644 --- a/composer.json +++ b/composer.json @@ -2,7 +2,7 @@ "name": "softcreatr/jsonpath", "description": "JSONPath implementation for parsing, searching and flattening arrays", "license": "MIT", - "version": "0.9.0", + "version": "0.9.1", "authors": [ { "name": "Stephen Frank", @@ -29,7 +29,8 @@ }, "require-dev": { "phpunit/phpunit": "10 - 12", - "roave/security-advisories": "dev-latest" + "friendsofphp/php-cs-fixer": "^3.58", + "squizlabs/php_codesniffer": "^3.10" }, "replace": { "flow/jsonpath": "*" @@ -50,6 +51,8 @@ "preferred-install": "dist" }, "scripts": { - "test": "phpunit" + "test": "phpunit", + "cs": "phpcs", + "cs-fix": "php-cs-fixer fix --config=.php-cs-fixer.dist.php" } } diff --git a/src/Filters/QueryMatchFilter.php b/src/Filters/QueryMatchFilter.php index 59caa72..fd0c17a 100644 --- a/src/Filters/QueryMatchFilter.php +++ b/src/Filters/QueryMatchFilter.php @@ -10,6 +10,7 @@ use Flow\JSONPath\AccessHelper; use Flow\JSONPath\JSONPath; +use Flow\JSONPath\JSONPathException; use RuntimeException; class QueryMatchFilter extends AbstractFilter @@ -19,6 +20,9 @@ class QueryMatchFilter extends AbstractFilter (\s*(?==|=~|=|<>|!==|!=|>=|<=|>|<|in|!in|nin)\s*(?.+))? '; + /** + * @throws JSONPathException + */ public function filter($collection): array { \preg_match('/^' . static::MATCH_QUERY_OPERATORS . '$/x', $this->token->value, $matches); @@ -61,13 +65,15 @@ public function filter($collection): array foreach ($collection as $value) { $value1 = null; + if (AccessHelper::keyExists($value, $key, $this->magicIsAllowed)) { $value1 = AccessHelper::getValue($value, $key, $this->magicIsAllowed); } elseif (\str_contains($key, '.')) { $value1 = (new JSONPath($value))->find($key)->getData()[0] ?? ''; } + if ($value1) { - if ($operator === null && $value1) { + if ($operator === null) { $return[] = $value; }