Skip to content

Commit e252c02

Browse files
committed
add failing test
1 parent fde3604 commit e252c02

File tree

4 files changed

+14
-6
lines changed

4 files changed

+14
-6
lines changed

tests/Rules/UseSafeFunctionsRuleTest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,14 @@ public function testJSONEncodeNoCatchSafe(): void
4444
{
4545
$this->analyse([__DIR__ . '/data/safe_json_encode.php'], []);
4646
}
47+
48+
public function testFirstClassCallable(): void
49+
{
50+
$this->analyse([__DIR__ . '/data/first_class_callable.php'], [
51+
[
52+
"Function json_encode is unsafe to use. It can return FALSE instead of throwing an exception. Please add 'use function Safe\\json_encode;' at the beginning of the file to use the variant provided by the 'thecodingmachine/safe' library.",
53+
3,
54+
],
55+
]);
56+
}
4757
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<?php
2+
3+
$encode = json_encode(...);
4+
$encode([]);

tests/Rules/data/safe_json_decode.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,3 @@
1313
// Test named arguments instead of positional
1414
json_decode("{}", flags: JSON_THROW_ON_ERROR);
1515
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: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,3 @@
77

88
// Named arguments
99
json_encode([], flags: JSON_THROW_ON_ERROR);
10-
11-
// First class callable
12-
json_encode(...);

0 commit comments

Comments
 (0)