66 * @license https://github.com/SoftCreatR/JSONPath/blob/main/LICENSE MIT License
77 */
88
9- declare (strict_types=1 );
10-
119namespace Flow \JSONPath ;
1210
1311use ArrayAccess ;
1412
15- use function abs ;
16- use function array_key_exists ;
17- use function array_keys ;
18- use function array_slice ;
19- use function array_values ;
20- use function get_object_vars ;
21- use function is_array ;
22- use function is_int ;
23- use function is_object ;
24- use function method_exists ;
25- use function property_exists ;
26-
2713class AccessHelper
2814{
2915 public static function collectionKeys (mixed $ collection ): array
3016 {
31- if (is_object ($ collection )) {
32- return array_keys (get_object_vars ($ collection ));
17+ if (\ is_object ($ collection )) {
18+ return \ array_keys (\ get_object_vars ($ collection ));
3319 }
3420
35- return array_keys ($ collection );
21+ return \ array_keys ($ collection );
3622 }
3723
3824 public static function isCollectionType (mixed $ collection ): bool
3925 {
40- return is_array ($ collection ) || is_object ($ collection );
26+ return \ is_array ($ collection ) || \ is_object ($ collection );
4127 }
4228
4329 public static function keyExists (mixed $ collection , $ key , bool $ magicIsAllowed = false ): bool
4430 {
45- if ($ magicIsAllowed && is_object ($ collection ) && method_exists ($ collection , '__get ' )) {
31+ if ($ magicIsAllowed && \ is_object ($ collection ) && \ method_exists ($ collection , '__get ' )) {
4632 return true ;
4733 }
4834
49- if (is_int ($ key ) && $ key < 0 ) {
50- $ key = abs ($ key );
35+ if (\ is_int ($ key ) && $ key < 0 ) {
36+ $ key = \ abs ($ key );
5137 }
5238
53- if (is_array ($ collection )) {
54- return array_key_exists ($ key , $ collection );
39+ if (\ is_array ($ collection )) {
40+ return \ array_key_exists ($ key , $ collection );
5541 }
5642
5743 if ($ collection instanceof ArrayAccess) {
5844 return $ collection ->offsetExists ($ key );
5945 }
6046
61- if (is_object ($ collection )) {
62- return property_exists ($ collection , (string )$ key );
47+ if (\ is_object ($ collection )) {
48+ return \ property_exists ($ collection , (string )$ key );
6349 }
6450
6551 return false ;
@@ -71,22 +57,22 @@ public static function keyExists(mixed $collection, $key, bool $magicIsAllowed =
7157 public static function getValue (mixed $ collection , $ key , bool $ magicIsAllowed = false )
7258 {
7359 if (
74- $ magicIsAllowed &&
75- is_object ($ collection ) &&
76- !$ collection instanceof ArrayAccess && method_exists ($ collection , '__get ' )
60+ $ magicIsAllowed
61+ && \ is_object ($ collection )
62+ && !$ collection instanceof ArrayAccess && \ method_exists ($ collection , '__get ' )
7763 ) {
7864 $ return = $ collection ->__get ($ key );
79- } elseif (is_object ($ collection ) && !$ collection instanceof ArrayAccess) {
80- $ return = $ collection ->$ key ;
65+ } elseif (\ is_object ($ collection ) && !$ collection instanceof ArrayAccess) {
66+ $ return = $ collection ->{ $ key} ;
8167 } elseif ($ collection instanceof ArrayAccess) {
8268 $ return = $ collection ->offsetGet ($ key );
83- } elseif (is_array ($ collection )) {
84- if (is_int ($ key ) && $ key < 0 ) {
85- $ return = array_slice ($ collection , $ key , 1 , false )[0 ];
69+ } elseif (\ is_array ($ collection )) {
70+ if (\ is_int ($ key ) && $ key < 0 ) {
71+ $ return = \ array_slice ($ collection , $ key , 1 )[0 ];
8672 } else {
8773 $ return = $ collection [$ key ];
8874 }
89- } elseif (is_int ($ key )) {
75+ } elseif (\ is_int ($ key )) {
9076 $ return = self ::getValueByIndex ($ collection , $ key );
9177 } else {
9278 $ return = $ collection [$ key ];
@@ -108,7 +94,7 @@ private static function getValueByIndex(mixed $collection, $key): mixed
10894 return $ val ;
10995 }
11096
111- ++ $ i ;
97+ $ i ++ ;
11298 }
11399
114100 if ($ key < 0 ) {
@@ -120,7 +106,7 @@ private static function getValueByIndex(mixed $collection, $key): mixed
120106 return $ val ;
121107 }
122108
123- ++ $ i ;
109+ $ i ++ ;
124110 }
125111 }
126112
@@ -129,8 +115,8 @@ private static function getValueByIndex(mixed $collection, $key): mixed
129115
130116 public static function setValue (mixed &$ collection , $ key , $ value )
131117 {
132- if (is_object ($ collection ) && !$ collection instanceof ArrayAccess) {
133- return $ collection ->$ key = $ value ;
118+ if (\ is_object ($ collection ) && !$ collection instanceof ArrayAccess) {
119+ return $ collection ->{ $ key} = $ value ;
134120 }
135121
136122 if ($ collection instanceof ArrayAccess) {
@@ -143,30 +129,30 @@ public static function setValue(mixed &$collection, $key, $value)
143129
144130 public static function unsetValue (mixed &$ collection , $ key ): void
145131 {
146- if (is_object ($ collection ) && !$ collection instanceof ArrayAccess) {
147- unset($ collection ->$ key );
132+ if (\ is_object ($ collection ) && !$ collection instanceof ArrayAccess) {
133+ unset($ collection ->{ $ key} );
148134 }
149135
150136 if ($ collection instanceof ArrayAccess) {
151137 $ collection ->offsetUnset ($ key );
152138 }
153139
154- if (is_array ($ collection )) {
140+ if (\ is_array ($ collection )) {
155141 unset($ collection [$ key ]);
156142 }
157143 }
158144
159145 /**
160146 * @throws JSONPathException
161147 */
162- public static function arrayValues (array |ArrayAccess $ collection ): array
148+ public static function arrayValues (array |ArrayAccess $ collection ): array | ArrayAccess
163149 {
164- if (is_array ($ collection )) {
165- return array_values ($ collection );
150+ if (\ is_array ($ collection )) {
151+ return \ array_values ($ collection );
166152 }
167153
168- if (is_object ($ collection )) {
169- return array_values ((array )$ collection );
154+ if (\ is_object ($ collection )) {
155+ return \ array_values ((array )$ collection );
170156 }
171157
172158 throw new JSONPathException ("Invalid variable type for arrayValues " );
0 commit comments