11<?php
2+
23/**
34 * JSONPath implementation for PHP.
45 *
5- * @copyright Copyright (c) 2018 Flow Communications
6- * @license MIT <https://github.com/SoftCreatR/JSONPath/blob/main/LICENSE>
6+ * @license https://github.com/SoftCreatR/JSONPath/blob/main/LICENSE MIT License
77 */
8+
89declare (strict_types=1 );
910
1011namespace Flow \JSONPath \Filters ;
1112
1213use Flow \JSONPath \AccessHelper ;
1314use RuntimeException ;
15+
16+ use function explode ;
17+ use function in_array ;
18+ use function is_array ;
1419use function is_string ;
1520use function preg_match ;
1621use function preg_replace ;
22+ use function strpos ;
1723use function strtolower ;
24+ use function substr ;
1825
1926class QueryMatchFilter extends AbstractFilter
2027{
21- public const MATCH_QUERY_OPERATORS = '
28+ protected const MATCH_QUERY_OPERATORS = '
2229 @(\.(?<key>[^\s<>!=]+)|\[[" \']?(?<keySquare>.*?)[" \']?\])
2330 (\s*(?<operator>==|=~|=|<>|!==|!=|>=|<=|>|<|in|!in|nin)\s*(?<comparisonValue>.+))?
2431 ' ;
2532
2633 /**
2734 * @inheritDoc
28- * @return array
2935 */
3036 public function filter ($ collection ): array
3137 {
@@ -44,7 +50,7 @@ public function filter($collection): array
4450 $ operator = $ matches ['operator ' ] ?? null ;
4551 $ comparisonValue = $ matches ['comparisonValue ' ] ?? null ;
4652
47- if (is_string (( $ comparisonValue) )) {
53+ if (is_string ($ comparisonValue )) {
4854 if (strpos ($ comparisonValue , "[ " ) === 0 && substr ($ comparisonValue , -1 ) === "] " ) {
4955 $ comparisonValue = substr ($ comparisonValue , 1 , -1 );
5056 $ comparisonValue = preg_replace ('/^[ \'"]/ ' , '' , $ comparisonValue );
@@ -76,11 +82,13 @@ public function filter($collection): array
7682 }
7783
7884 /** @noinspection TypeUnsafeComparisonInspection */
85+ // phpcs:ignore -- This is a loose comparison by design.
7986 if (($ operator === '= ' || $ operator === '== ' ) && $ value1 == $ comparisonValue ) {
8087 $ return [] = $ value ;
8188 }
8289
8390 /** @noinspection TypeUnsafeComparisonInspection */
91+ // phpcs:ignore -- This is a loose comparison by design.
8492 if (($ operator === '!= ' || $ operator === '!== ' || $ operator === '<> ' ) && $ value1 != $ comparisonValue ) {
8593 $ return [] = $ value ;
8694 }
@@ -109,7 +117,11 @@ public function filter($collection): array
109117 $ return [] = $ value ;
110118 }
111119
112- if (($ operator === 'nin ' || $ operator === '!in ' ) && is_array ($ comparisonValue ) && !in_array ($ value1 , $ comparisonValue , true )) {
120+ if (
121+ ($ operator === 'nin ' || $ operator === '!in ' ) &&
122+ is_array ($ comparisonValue ) &&
123+ !in_array ($ value1 , $ comparisonValue , true )
124+ ) {
113125 $ return [] = $ value ;
114126 }
115127 }
0 commit comments