Skip to content

Commit 972b73a

Browse files
committed
RequireConstructorPropertyPromotionSniff: Fixed false positives
1 parent fa20e13 commit 972b73a

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

SlevomatCodingStandard/Sniffs/Classes/RequireConstructorPropertyPromotionSniff.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,14 @@
2626
use const T_CALLABLE;
2727
use const T_CLOSE_CURLY_BRACKET;
2828
use const T_COMMA;
29+
use const T_DEC;
2930
use const T_ELLIPSIS;
3031
use const T_ELSE;
3132
use const T_ELSEIF;
3233
use const T_EQUAL;
3334
use const T_FUNCTION;
3435
use const T_IF;
36+
use const T_INC;
3537
use const T_OBJECT_OPERATOR;
3638
use const T_OPEN_CURLY_BRACKET;
3739
use const T_OPEN_PARENTHESIS;
@@ -377,6 +379,15 @@ private function isParameterModifiedBeforeAssigment(
377379
if (in_array($tokens[$nextPointer]['code'], Tokens::$assignmentTokens, true)) {
378380
return true;
379381
}
382+
383+
if ($tokens[$nextPointer]['code'] === T_INC) {
384+
return true;
385+
}
386+
387+
$previousPointer = TokenHelper::findNextEffective($phpcsFile, $i - 1);
388+
if ($tokens[$previousPointer]['code'] === T_DEC) {
389+
return true;
390+
}
380391
}
381392

382393
return false;

tests/Sniffs/Classes/data/requireConstructorPropertyPromotionNoErrors.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,10 @@ class Nothing
7575
#[SomeAttribute]
7676
private $k;
7777

78-
public function __construct($a, $c, $d, $e, $f, $g, $h, string $i, string $j, $k)
78+
private int $l;
79+
private int $m;
80+
81+
public function __construct($a, $c, $d, $e, $f, $g, $h, string $i, string $j, $k, int $l, int $m)
7982
{
8083
$phpVersion = phpversion();
8184

@@ -102,6 +105,12 @@ public function __construct($a, $c, $d, $e, $f, $g, $h, string $i, string $j, $k
102105
$this->j = $j;
103106

104107
$this->k = $k;
108+
109+
$l++;
110+
$this->l = $l;
111+
112+
--$m;
113+
$this->m = $m;
105114
}
106115

107116
}

0 commit comments

Comments
 (0)