Skip to content

Commit 201af9d

Browse files
committed
Require strict function usage
1 parent bf16355 commit 201af9d

File tree

5 files changed

+64
-61
lines changed

5 files changed

+64
-61
lines changed

src/Unleashed/ruleset.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,8 @@
265265
<rule ref="SlevomatCodingStandard.Exceptions.ReferenceThrowableOnly"/>
266266
<!-- Require closures not referencing $this be static -->
267267
<rule ref="SlevomatCodingStandard.Functions.StaticClosure"/>
268+
<!-- Require calls to PHP functions that have a `$strict` parameter to always set that to `true` -->
269+
<rule ref="SlevomatCodingStandard.Functions.StrictCall"/>
268270
<!-- Forbid unused variables passed to closures via `use` -->
269271
<rule ref="SlevomatCodingStandard.Functions.UnusedInheritedVariablePassedToClosure"/>
270272
<!-- Require use statements to be alphabetically sorted -->

tests/expected_report.txt

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,40 +11,43 @@ tests/input/concatenation_spacing.php 49 0
1111
tests/input/constants-no-lsb.php 2 0
1212
tests/input/constants-var.php 4 0
1313
tests/input/ControlStructures.php 17 2
14-
tests/input/doc-comment-spacing.php 14 0
14+
tests/input/doc-comment-spacing.php 12 0
1515
tests/input/duplicate-assignment-variable.php 1 0
1616
tests/input/EarlyReturn.php 6 0
1717
tests/input/example-class.php 38 0
1818
tests/input/forbidden-comments.php 14 0
1919
tests/input/forbidden-functions.php 5 0
2020
tests/input/fully-qualified-and-fallbacks.php 1 0
21+
tests/input/fully-qualified-without-namespace.php 3 0
2122
tests/input/inline_type_hint_assertions.php 7 0
22-
tests/input/LowCaseTypes.php 4 0
23-
tests/input/namespaces-spacing.php 8 0
24-
tests/input/NamingCamelCase.php 9 0
23+
tests/input/LowCaseTypes.php 3 0
24+
tests/input/namespaces-spacing.php 12 0
25+
tests/input/NamingCamelCase.php 8 0
2526
tests/input/negation-operator.php 2 0
2627
tests/input/new_with_parentheses.php 18 0
27-
tests/input/not_spacing.php 6 0
28+
tests/input/not_spacing.php 8 0
2829
tests/input/null_coalesce_operator.php 3 0
2930
tests/input/optimized-functions.php 1 0
30-
tests/input/return_type_on_closures.php 29 0
31-
tests/input/return_type_on_methods.php 25 0
31+
tests/input/return_type_on_closures.php 17 0
32+
tests/input/return_type_on_methods.php 13 0
3233
tests/input/semicolon_spacing.php 3 0
3334
tests/input/single-line-array-spacing.php 5 0
34-
tests/input/spread-operator.php 18 0
35+
tests/input/spread-operator.php 10 0
3536
tests/input/static-closures.php 1 0
37+
tests/input/strict-functions.php 4 0
3638
tests/input/test-case.php 7 0
3739
tests/input/trailing_comma_on_array.php 1 0
38-
tests/input/traits-uses.php 14 0
39-
tests/input/type-hints.php 6 0
40-
tests/input/UnusedVariables.php 3 0
41-
tests/input/use-ordering.php 6 0
40+
tests/input/traits-uses.php 11 0
41+
tests/input/type-hints.php 5 0
42+
tests/input/UnusedVariables.php 2 0
43+
tests/input/use-function.php 2 0
44+
tests/input/use-ordering.php 9 0
4245
tests/input/useless-semicolon.php 2 0
43-
tests/input/UselessConditions.php 26 0
46+
tests/input/UselessConditions.php 23 0
4447
----------------------------------------------------------------------
45-
A TOTAL OF 388 ERRORS AND 2 WARNINGS WERE FOUND IN 38 FILES
48+
A TOTAL OF 362 ERRORS AND 2 WARNINGS WERE FOUND IN 41 FILES
4649
----------------------------------------------------------------------
47-
PHPCBF CAN FIX 331 OF THESE SNIFF VIOLATIONS AUTOMATICALLY
50+
PHPCBF CAN FIX 303 OF THESE SNIFF VIOLATIONS AUTOMATICALLY
4851
----------------------------------------------------------------------
4952

5053

tests/fixed/strict-functions.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
$foo = in_array('foo', ['foo', 'bar']);
6+
7+
$bar = in_array('foo', ['foo', 'bar'], false);

tests/input/strict-functions.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
$foo = \in_array('foo', ['foo', 'bar']);
6+
7+
$bar = \in_array('foo', ['foo', 'bar'], false);

tests/php-compatibility.patch

Lines changed: 30 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,21 @@
1+
diff --git a/src/Unleashed/Helpers/SniffLocalCache.php b/src/Unleashed/Helpers/SniffLocalCache.php
2+
index ad0792f..a8eaab3 100644
3+
--- a/src/Unleashed/Helpers/SniffLocalCache.php
4+
+++ b/src/Unleashed/Helpers/SniffLocalCache.php
5+
@@ -14,7 +14,7 @@ use PHP_CodeSniffer\Files\File;
6+
final class SniffLocalCache
7+
{
8+
/** @var array<int, array<string, mixed>> */
9+
- private static $cache = [];
10+
+ private static array $cache = [];
11+
12+
/**
13+
* @return mixed
114
diff --git a/src/Unleashed/Sniffs/Namespaces/FullyQualifiedGlobalFunctionsSniff.php b/src/Unleashed/Sniffs/Namespaces/FullyQualifiedGlobalFunctionsSniff.php
2-
index fe018ad..4810bd0 100644
15+
index 71be9a5..f9492c7 100644
316
--- a/src/Unleashed/Sniffs/Namespaces/FullyQualifiedGlobalFunctionsSniff.php
417
+++ b/src/Unleashed/Sniffs/Namespaces/FullyQualifiedGlobalFunctionsSniff.php
5-
@@ -11,11 +11,10 @@ use Unleashed\SniffHelper;
18+
@@ -11,11 +11,10 @@ use Unleashed\Helpers\UseStatements;
619

720
final class FullyQualifiedGlobalFunctionsSniff implements Sniff
821
{
@@ -17,64 +30,35 @@ index fe018ad..4810bd0 100644
1730
'array_key_exists' => true,
1831
'array_slice' => true,
1932
diff --git a/tests/expected_report.txt b/tests/expected_report.txt
20-
index 1ecfaaa..975b9ca 100644
33+
index 0ab45ec..fc414f1 100644
2134
--- a/tests/expected_report.txt
2235
+++ b/tests/expected_report.txt
23-
@@ -11,40 +11,42 @@ tests/input/concatenation_spacing.php 49 0
24-
tests/input/constants-no-lsb.php 2 0
25-
tests/input/constants-var.php 4 0
26-
tests/input/ControlStructures.php 17 2
27-
-tests/input/doc-comment-spacing.php 14 0
28-
+tests/input/doc-comment-spacing.php 12 0
36+
@@ -14,7 +14,7 @@ tests/input/ControlStructures.php 17 2
37+
tests/input/doc-comment-spacing.php 12 0
2938
tests/input/duplicate-assignment-variable.php 1 0
3039
tests/input/EarlyReturn.php 6 0
3140
-tests/input/example-class.php 38 0
3241
+tests/input/example-class.php 41 0
3342
tests/input/forbidden-comments.php 14 0
3443
tests/input/forbidden-functions.php 5 0
3544
tests/input/fully-qualified-and-fallbacks.php 1 0
36-
+tests/input/fully-qualified-without-namespace.php 3 0
37-
tests/input/inline_type_hint_assertions.php 7 0
38-
-tests/input/LowCaseTypes.php 4 0
39-
-tests/input/namespaces-spacing.php 8 0
40-
-tests/input/NamingCamelCase.php 9 0
41-
+tests/input/LowCaseTypes.php 3 0
42-
+tests/input/namespaces-spacing.php 12 0
43-
+tests/input/NamingCamelCase.php 8 0
44-
tests/input/negation-operator.php 2 0
45-
tests/input/new_with_parentheses.php 18 0
46-
-tests/input/not_spacing.php 6 0
47-
+tests/input/not_spacing.php 8 0
48-
tests/input/null_coalesce_operator.php 3 0
49-
tests/input/optimized-functions.php 1 0
50-
-tests/input/return_type_on_closures.php 29 0
51-
-tests/input/return_type_on_methods.php 25 0
52-
+tests/input/return_type_on_closures.php 17 0
53-
+tests/input/return_type_on_methods.php 13 0
54-
tests/input/semicolon_spacing.php 3 0
55-
tests/input/single-line-array-spacing.php 5 0
56-
-tests/input/spread-operator.php 18 0
57-
+tests/input/spread-operator.php 10 0
58-
tests/input/static-closures.php 1 0
45+
@@ -38,16 +38,16 @@ tests/input/strict-functions.php 4 0
5946
tests/input/test-case.php 7 0
6047
tests/input/trailing_comma_on_array.php 1 0
61-
-tests/input/traits-uses.php 14 0
62-
+tests/input/traits-uses.php 11 0
63-
tests/input/type-hints.php 6 0
64-
-tests/input/UnusedVariables.php 3 0
65-
-tests/input/use-ordering.php 6 0
66-
+tests/input/UnusedVariables.php 2 0
67-
+tests/input/use-function.php 2 0
68-
+tests/input/use-ordering.php 9 0
48+
tests/input/traits-uses.php 11 0
49+
-tests/input/type-hints.php 5 0
50+
+tests/input/type-hints.php 6 0
51+
tests/input/UnusedVariables.php 2 0
52+
tests/input/use-function.php 2 0
53+
tests/input/use-ordering.php 9 0
6954
tests/input/useless-semicolon.php 2 0
70-
-tests/input/UselessConditions.php 26 0
71-
+tests/input/UselessConditions.php 23 0
55+
tests/input/UselessConditions.php 23 0
7256
----------------------------------------------------------------------
73-
-A TOTAL OF 388 ERRORS AND 2 WARNINGS WERE FOUND IN 38 FILES
74-
+A TOTAL OF 362 ERRORS AND 2 WARNINGS WERE FOUND IN 40 FILES
57+
-A TOTAL OF 362 ERRORS AND 2 WARNINGS WERE FOUND IN 41 FILES
58+
+A TOTAL OF 366 ERRORS AND 2 WARNINGS WERE FOUND IN 41 FILES
7559
----------------------------------------------------------------------
76-
-PHPCBF CAN FIX 331 OF THESE SNIFF VIOLATIONS AUTOMATICALLY
77-
+PHPCBF CAN FIX 305 OF THESE SNIFF VIOLATIONS AUTOMATICALLY
60+
-PHPCBF CAN FIX 303 OF THESE SNIFF VIOLATIONS AUTOMATICALLY
61+
+PHPCBF CAN FIX 307 OF THESE SNIFF VIOLATIONS AUTOMATICALLY
7862
----------------------------------------------------------------------
7963

8064

0 commit comments

Comments
 (0)