Skip to content

Commit

Permalink
Add test file for PSR12.Operators.OperatorSpacing
Browse files Browse the repository at this point in the history
The sniff has specific logic to avoid an out-of-bounds array offset access.
Before now, there were no tests which covered this logic. This commit adds such
a test. The sniff already handles this, so there are no changes required there.

This particular omission was detected by infection/infection.

```diff
src/Standards/PSR12/Sniffs/Operators/OperatorSpacingSniff.php:104    [M] FalseValue

@@ @@
             }
         } else {
             // Skip partial files.
-            $checkAfter = false;
+            $checkAfter = true;
         }
         if ($checkBefore === true && $tokens[$stackPtr - 1]['code'] !== T_WHITESPACE) {
             $error = 'Expected at least 1 space before "%s"; 0 found';
```
  • Loading branch information
fredden committed Jul 14, 2024
1 parent 8581f0c commit 3c9fc66
Showing 1 changed file with 6 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?php
// Code to cover logic in the sniff which specifically targets an operator at
// the end of a file.

// There is (intentionally) no trailing newline at the end of this file
$var = true ?

0 comments on commit 3c9fc66

Please sign in to comment.