Skip to content

Commit 05e888c

Browse files
committed
Don't force backslashes in global namespace (fixes #6)
1 parent 09592be commit 05e888c

File tree

4 files changed

+35
-15
lines changed

4 files changed

+35
-15
lines changed

src/Unleashed/Sniffs/Namespaces/FullyQualifiedGlobalFunctionsSniff.php

+5
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,11 @@ public function register()
8282
*/
8383
public function process(File $phpcsFile, $stackPtr)
8484
{
85+
// Abort if we're not in namespaced code
86+
if ($phpcsFile->findPrevious([T_NAMESPACE], $stackPtr - 1) === false) {
87+
return;
88+
}
89+
8590
if (
8691
$this->onlyOptimizedFunctions !== null
8792
&& \filter_var($this->onlyOptimizedFunctions, FILTER_VALIDATE_BOOLEAN) !== false
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
use function time as now;
6+
7+
strrev(strrev(
8+
(new DateTimeImmutable('@' . now(), new DateTimeZone('UTC')))
9+
->sub(new DateInterval('P1D'))
10+
->format(DATE_RFC3339)
11+
));
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
use function time as now;
6+
7+
\strrev(strrev(
8+
(new \DateTimeImmutable('@' . now(), new DateTimeZone('UTC')))
9+
->sub(new DateInterval('P1D'))
10+
->format(\DATE_RFC3339)
11+
));

tests/php-compatibility.patch

+8-15
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
diff --git a/src/Unleashed/Sniffs/Namespaces/FullyQualifiedGlobalFunctionsSniff.php b/src/Unleashed/Sniffs/Namespaces/FullyQualifiedGlobalFunctionsSniff.php
2-
index eee1c6f..742226e 100644
2+
index fe018ad..4810bd0 100644
33
--- a/src/Unleashed/Sniffs/Namespaces/FullyQualifiedGlobalFunctionsSniff.php
44
+++ b/src/Unleashed/Sniffs/Namespaces/FullyQualifiedGlobalFunctionsSniff.php
55
@@ -11,11 +11,10 @@ use Unleashed\SniffHelper;
@@ -17,16 +17,10 @@ index eee1c6f..742226e 100644
1717
'array_key_exists' => true,
1818
'array_slice' => true,
1919
diff --git a/tests/expected_report.txt b/tests/expected_report.txt
20-
index 1ecfaaa..06d22b0 100644
20+
index 1ecfaaa..975b9ca 100644
2121
--- a/tests/expected_report.txt
2222
+++ b/tests/expected_report.txt
23-
@@ -6,45 +6,46 @@ FILE ERRORS WARNINGS
24-
tests/input/array_indentation.php 10 0
25-
tests/input/assignment-operators.php 4 0
26-
tests/input/binary_operators.php 9 0
27-
-tests/input/class-references.php 10 0
28-
+tests/input/class-references.php 15 0
29-
tests/input/concatenation_spacing.php 49 0
23+
@@ -11,40 +11,42 @@ tests/input/concatenation_spacing.php 49 0
3024
tests/input/constants-no-lsb.php 2 0
3125
tests/input/constants-var.php 4 0
3226
tests/input/ControlStructures.php 17 2
@@ -39,11 +33,11 @@ index 1ecfaaa..06d22b0 100644
3933
tests/input/forbidden-comments.php 14 0
4034
tests/input/forbidden-functions.php 5 0
4135
tests/input/fully-qualified-and-fallbacks.php 1 0
42-
-tests/input/inline_type_hint_assertions.php 7 0
36+
+tests/input/fully-qualified-without-namespace.php 3 0
37+
tests/input/inline_type_hint_assertions.php 7 0
4338
-tests/input/LowCaseTypes.php 4 0
4439
-tests/input/namespaces-spacing.php 8 0
4540
-tests/input/NamingCamelCase.php 9 0
46-
+tests/input/inline_type_hint_assertions.php 8 0
4741
+tests/input/LowCaseTypes.php 3 0
4842
+tests/input/namespaces-spacing.php 12 0
4943
+tests/input/NamingCamelCase.php 8 0
@@ -52,10 +46,9 @@ index 1ecfaaa..06d22b0 100644
5246
-tests/input/not_spacing.php 6 0
5347
+tests/input/not_spacing.php 8 0
5448
tests/input/null_coalesce_operator.php 3 0
55-
-tests/input/optimized-functions.php 1 0
49+
tests/input/optimized-functions.php 1 0
5650
-tests/input/return_type_on_closures.php 29 0
5751
-tests/input/return_type_on_methods.php 25 0
58-
+tests/input/optimized-functions.php 2 0
5952
+tests/input/return_type_on_closures.php 17 0
6053
+tests/input/return_type_on_methods.php 13 0
6154
tests/input/semicolon_spacing.php 3 0
@@ -78,10 +71,10 @@ index 1ecfaaa..06d22b0 100644
7871
+tests/input/UselessConditions.php 23 0
7972
----------------------------------------------------------------------
8073
-A TOTAL OF 388 ERRORS AND 2 WARNINGS WERE FOUND IN 38 FILES
81-
+A TOTAL OF 366 ERRORS AND 2 WARNINGS WERE FOUND IN 39 FILES
74+
+A TOTAL OF 362 ERRORS AND 2 WARNINGS WERE FOUND IN 40 FILES
8275
----------------------------------------------------------------------
8376
-PHPCBF CAN FIX 331 OF THESE SNIFF VIOLATIONS AUTOMATICALLY
84-
+PHPCBF CAN FIX 309 OF THESE SNIFF VIOLATIONS AUTOMATICALLY
77+
+PHPCBF CAN FIX 305 OF THESE SNIFF VIOLATIONS AUTOMATICALLY
8578
----------------------------------------------------------------------
8679

8780

0 commit comments

Comments
 (0)