Skip to content

Commit 1f25f50

Browse files
committed
[SQUASH-ME] Make sniff tests more realistic
Use the `(void)` cast correctly in the test code samples. `(void)` casts have to be used as a statement, not an expression.
1 parent 3395b4c commit 1f25f50

13 files changed

+25
-20
lines changed

src/Standards/Generic/Tests/Formatting/SpaceAfterCastUnitTest.1.inc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,6 @@ $var = (boolean)/* comment */ $var2;
9999
$var = ( int )$spacesInsideParenthesis;
100100
$var = ( int )$tabsInsideParenthesis;
101101

102-
$var = (void) callMe();
103-
$var = (void)callMe();
104-
$var = (void) callMe();
102+
(void) callMe();
103+
(void)callMe();
104+
(void) callMe();

src/Standards/Generic/Tests/Formatting/SpaceAfterCastUnitTest.1.inc.fixed

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,6 @@ $var = (boolean)/* comment */ $var2;
9696
$var = ( int ) $spacesInsideParenthesis;
9797
$var = ( int ) $tabsInsideParenthesis;
9898

99-
$var = (void) callMe();
100-
$var = (void) callMe();
101-
$var = (void) callMe();
99+
(void) callMe();
100+
(void) callMe();
101+
(void) callMe();

src/Standards/Generic/Tests/Formatting/SpaceBeforeCastUnitTest.inc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,6 @@ $var = array(
6464

6565
(bool) $a ? echo $b : echo $c;
6666

67-
$var = (void) callMe();
68-
$var =(void) callMe();
69-
$var = (void) callMe();
67+
(void) callMe();
68+
(void)(bool) callMe();
69+
(void) callMe(); // Indentation whitespace before should be and will be ignored.

src/Standards/Generic/Tests/Formatting/SpaceBeforeCastUnitTest.inc.fixed

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,6 @@ $var = array(
6464

6565
(bool) $a ? echo $b : echo $c;
6666

67-
$var = (void) callMe();
68-
$var = (void) callMe();
69-
$var = (void) callMe();
67+
(void) callMe();
68+
(void) (bool) callMe();
69+
(void) callMe(); // Indentation whitespace before should be and will be ignored.

src/Standards/Generic/Tests/Formatting/SpaceBeforeCastUnitTest.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@ public function getErrorList()
6262
55 => 1,
6363
56 => 1,
6464
68 => 1,
65-
69 => 1,
6665
];
6766
}
6867

src/Standards/Generic/Tests/PHP/LowerCaseTypeUnitTest.1.inc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,4 +143,4 @@ interface PHP84HookedProperty {
143143
public String $readable { get; }
144144
}
145145

146-
$php85 = (VOID) callMe();
146+
(VOID) php85();

src/Standards/Generic/Tests/PHP/LowerCaseTypeUnitTest.1.inc.fixed

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,4 +143,4 @@ interface PHP84HookedProperty {
143143
public string $readable { get; }
144144
}
145145

146-
$php85 = (void) callMe();
146+
(void) php85();

src/Standards/Squiz/Sniffs/Formatting/OperatorBracketSniff.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,11 @@ public function addMissingBracketsError(File $phpcsFile, int $stackPtr)
304304
}
305305

306306
$before = $phpcsFile->findNext(Tokens::EMPTY_TOKENS, ($before + 1), null, true);
307+
if ($tokens[$before]['code'] === T_VOID_CAST) {
308+
// Don't throw an error if a (void) cast is the first token in the expression
309+
// as adding parentheses would turn that into a parse error.
310+
return;
311+
}
307312

308313
// A few extra tokens are allowed to be on the right side of the expression.
309314
$allowed[T_EQUAL] = true;

src/Standards/Squiz/Tests/Formatting/OperatorBracketUnitTest.1.inc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,4 +206,5 @@ $nsRelative = namespace\doSomething($items + 10);
206206
$partiallyQualified = Partially\qualified($items + 10);
207207
$fullyQualified = \Fully\qualified($items + 10);
208208

209-
$php85voidcast = (void) CallMeOnce() + (void) CallMeTwice();
209+
// The below should be ignored as adding parentheses will turn this into a parse error.
210+
(void) CallMeOnce() + (bool) CallMeTwice();

src/Standards/Squiz/Tests/Formatting/OperatorBracketUnitTest.1.inc.fixed

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,4 +206,5 @@ $nsRelative = namespace\doSomething($items + 10);
206206
$partiallyQualified = Partially\qualified($items + 10);
207207
$fullyQualified = \Fully\qualified($items + 10);
208208

209-
$php85voidcast = ((void) CallMeOnce() + (void) CallMeTwice());
209+
// The below should be ignored as adding parentheses will turn this into a parse error.
210+
(void) CallMeOnce() + (bool) CallMeTwice();

0 commit comments

Comments
 (0)