Skip to content

Commit fde3604

Browse files
committed
fix merge, add test case
1 parent a31b664 commit fde3604

File tree

3 files changed

+20
-5
lines changed

3 files changed

+20
-5
lines changed

src/Rules/UseSafeFunctionsRule.php

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -94,10 +94,16 @@ private function argValueIncludeJSONTHROWONERROR(?Arg $arg): bool
9494
return true;
9595
}
9696

97-
return in_array(true, array_map(function ($element) {
98-
return ($element & self::JSON_THROW_ON_ERROR) == self::JSON_THROW_ON_ERROR;
99-
}, array_filter($options, function ($element) {
100-
return is_int($element);
101-
})), true);
97+
$intOptions = array_filter($options, function (mixed $option): bool {
98+
return is_int($option);
99+
});
100+
101+
foreach ($intOptions as $option) {
102+
if (($option & self::JSON_THROW_ON_ERROR) === self::JSON_THROW_ON_ERROR) {
103+
return true;
104+
}
105+
}
106+
107+
return false;
102108
}
103109
}

tests/Rules/data/safe_json_decode.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,7 @@
1212

1313
// Test named arguments instead of positional
1414
json_decode("{}", flags: JSON_THROW_ON_ERROR);
15+
json_decode("{}", flags: JSON_THROW_ON_ERROR);
16+
17+
// Test first class callable
18+
json_decode(...);

tests/Rules/data/safe_json_encode.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
<?php
22

3+
// Various combinations of flags
34
json_encode([], JSON_THROW_ON_ERROR, 512);
45
json_encode([], JSON_FORCE_OBJECT | JSON_THROW_ON_ERROR, 512);
56
json_encode([], JSON_FORCE_OBJECT | JSON_INVALID_UTF8_IGNORE | JSON_THROW_ON_ERROR, 512);
67

8+
// Named arguments
79
json_encode([], flags: JSON_THROW_ON_ERROR);
10+
11+
// First class callable
12+
json_encode(...);

0 commit comments

Comments
 (0)