Skip to content

Commit 9cc3412

Browse files
authored
Merge pull request #71 from Lukazar/bug-68-length-support
[Bug-68] added support for length on array
2 parents 95215ed + 8d7f667 commit 9cc3412

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

src/Filters/IndexFilter.php

+6
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,12 @@ public function filter($collection): array
4141
return AccessHelper::arrayValues($collection);
4242
}
4343

44+
if ($this->token->value === 'length') {
45+
return [
46+
count($collection),
47+
];
48+
}
49+
4450
return [];
4551
}
4652
}

tests/QueryTest.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -808,7 +808,7 @@ public function queryDataProvider(): array
808808
'dot_notation_with_key_named_length_on_array',
809809
'$.length',
810810
'[4,5,6]',
811-
'[]'
811+
'[3]'
812812
],
813813
[ // data set #114
814814
'dot_notation_with_key_named_null',
@@ -1454,7 +1454,7 @@ public function queryDataProvider(): array
14541454
'script_expression',
14551455
'$[(@.length-1)]',
14561456
'["first","second","third","forth","fifth"]',
1457-
''
1457+
'fifth'
14581458
],
14591459
[ // data set #214
14601460
'union',

0 commit comments

Comments
 (0)