From 57b1e345cdbb837a034063aa2a1f4865781a7dd2 Mon Sep 17 00:00:00 2001 From: Ondrej Mirtes Date: Fri, 5 Jan 2024 13:43:09 +0100 Subject: [PATCH] Fix UnusedVariableSniff when there's cast before `++` --- .../Sniffs/Variables/UnusedVariableSniff.php | 3 ++- tests/Sniffs/Variables/data/unusedVariableErrors.php | 4 ++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/SlevomatCodingStandard/Sniffs/Variables/UnusedVariableSniff.php b/SlevomatCodingStandard/Sniffs/Variables/UnusedVariableSniff.php index 568d116f0..20a5daae5 100644 --- a/SlevomatCodingStandard/Sniffs/Variables/UnusedVariableSniff.php +++ b/SlevomatCodingStandard/Sniffs/Variables/UnusedVariableSniff.php @@ -656,7 +656,8 @@ private function isPartOfStatementAndWithIncrementOrDecrementOperator(File $phpc [T_STRING_CONCAT, T_ECHO, T_RETURN, T_EXIT, T_PRINT, T_COMMA, T_EMPTY, T_EVAL, T_YIELD], Tokens::$operators, Tokens::$assignmentTokens, - Tokens::$booleanOperators + Tokens::$booleanOperators, + Tokens::$castTokens ), true ); diff --git a/tests/Sniffs/Variables/data/unusedVariableErrors.php b/tests/Sniffs/Variables/data/unusedVariableErrors.php index 2f0c25768..41ce0e13c 100644 --- a/tests/Sniffs/Variables/data/unusedVariableErrors.php +++ b/tests/Sniffs/Variables/data/unusedVariableErrors.php @@ -128,3 +128,7 @@ function ($b) { --$a; return $b; }; + +function ($s): string { + return (string) ++$s; +};