From c2e4e1ad62daf48262841b995f908193ba34eda2 Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Wed, 10 Sep 2025 19:09:15 +0700 Subject: [PATCH 1/2] Fix PHPStan notice on PHPStan 2.1.23 --- rules/CodingStyle/Rector/Stmt/NewlineAfterStatementRector.php | 2 ++ rules/Php70/EregToPcreTransformer.php | 4 ++-- rules/Php70/Rector/FuncCall/CallUserMethodRector.php | 4 ++++ rules/Php73/Rector/FuncCall/ArrayKeyFirstLastRector.php | 4 ++++ .../Rector/FuncCall/NullToStrictStringFuncCallArgRector.php | 2 +- 5 files changed, 13 insertions(+), 3 deletions(-) diff --git a/rules/CodingStyle/Rector/Stmt/NewlineAfterStatementRector.php b/rules/CodingStyle/Rector/Stmt/NewlineAfterStatementRector.php index b89d65724ef..857ca35b2cb 100644 --- a/rules/CodingStyle/Rector/Stmt/NewlineAfterStatementRector.php +++ b/rules/CodingStyle/Rector/Stmt/NewlineAfterStatementRector.php @@ -129,7 +129,9 @@ private function processAddNewLine( continue; } + /** @var Stmt $stmt */ $endLine = $stmt->getEndLine(); + /** @var Stmt $nextStmt */ $line = $nextStmt->getStartLine(); $rangeLine = $line - $endLine; diff --git a/rules/Php70/EregToPcreTransformer.php b/rules/Php70/EregToPcreTransformer.php index 88ba0af813e..097a7d885f6 100644 --- a/rules/Php70/EregToPcreTransformer.php +++ b/rules/Php70/EregToPcreTransformer.php @@ -215,7 +215,7 @@ private function processBracket(string $content, int $i, int $l, array &$r, int } else { $position = $i + 1; [$t, $ii] = $this->_ere2pcre($content, $position); - if ($ii >= $l || $content[$ii] !== ')') { + if ($ii >= $l || ! isset($content[$ii]) || $content[$ii] !== ')') { throw new InvalidEregException('"(" does not have a matching ")"'); } @@ -265,7 +265,7 @@ private function processSquareBracket(string $s, int $i, int $l, string $cls, bo } $start = false; - } while ($i < $l && $s[$i] !== ']'); + } while ($i < $l && isset($s[$i]) && $s[$i] !== ']'); return [$cls, $i]; } diff --git a/rules/Php70/Rector/FuncCall/CallUserMethodRector.php b/rules/Php70/Rector/FuncCall/CallUserMethodRector.php index 986a476dae1..3cd9809bb2c 100644 --- a/rules/Php70/Rector/FuncCall/CallUserMethodRector.php +++ b/rules/Php70/Rector/FuncCall/CallUserMethodRector.php @@ -67,6 +67,10 @@ public function refactor(Node $node): ?Node return null; } + if (! isset(self::OLD_TO_NEW_FUNCTIONS[$this->getName($node)])) { + return null; + } + $newName = self::OLD_TO_NEW_FUNCTIONS[$this->getName($node)]; $node->name = new Name($newName); diff --git a/rules/Php73/Rector/FuncCall/ArrayKeyFirstLastRector.php b/rules/Php73/Rector/FuncCall/ArrayKeyFirstLastRector.php index 2350eec1bbe..63a65592cf8 100644 --- a/rules/Php73/Rector/FuncCall/ArrayKeyFirstLastRector.php +++ b/rules/Php73/Rector/FuncCall/ArrayKeyFirstLastRector.php @@ -147,6 +147,10 @@ private function processArrayKeyFirstLast( continue; } + if (! isset(self::PREVIOUS_TO_NEW_FUNCTIONS[$this->getName($stmt->expr)])) { + continue; + } + $newName = self::PREVIOUS_TO_NEW_FUNCTIONS[$this->getName($stmt->expr)]; $keyFuncCall->name = new Name($newName); diff --git a/rules/Php81/Rector/FuncCall/NullToStrictStringFuncCallArgRector.php b/rules/Php81/Rector/FuncCall/NullToStrictStringFuncCallArgRector.php index 212d4a4292b..b4b177ee061 100644 --- a/rules/Php81/Rector/FuncCall/NullToStrictStringFuncCallArgRector.php +++ b/rules/Php81/Rector/FuncCall/NullToStrictStringFuncCallArgRector.php @@ -142,7 +142,7 @@ public function provideMinPhpVersion(): int private function resolveNamedPositions(FuncCall $funcCall, array $args): array { $functionName = $this->getName($funcCall); - $argNames = NameNullToStrictNullFunctionMap::FUNCTION_TO_PARAM_NAMES[$functionName]; + $argNames = NameNullToStrictNullFunctionMap::FUNCTION_TO_PARAM_NAMES[$functionName] ?? []; $positions = []; foreach ($args as $position => $arg) { From 38e0d44af5a3281e5eb4e556c6fca347a32eb56a Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Wed, 10 Sep 2025 19:12:18 +0700 Subject: [PATCH 2/2] skip complex logic --- phpstan.neon | 4 ++++ rules/Php70/EregToPcreTransformer.php | 4 ++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/phpstan.neon b/phpstan.neon index 429e9f6e8d5..854020bdd80 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -340,3 +340,7 @@ parameters: identifier: rector.upgradeDowngradeRegisteredInSet count: 1 path: rules/Php74/Rector/Double/RealToFloatTypeCastRector.php + + - + message: '#Offset float\|int\|string might not exist on string#' + path: rules/Php70/EregToPcreTransformer.php diff --git a/rules/Php70/EregToPcreTransformer.php b/rules/Php70/EregToPcreTransformer.php index 097a7d885f6..88ba0af813e 100644 --- a/rules/Php70/EregToPcreTransformer.php +++ b/rules/Php70/EregToPcreTransformer.php @@ -215,7 +215,7 @@ private function processBracket(string $content, int $i, int $l, array &$r, int } else { $position = $i + 1; [$t, $ii] = $this->_ere2pcre($content, $position); - if ($ii >= $l || ! isset($content[$ii]) || $content[$ii] !== ')') { + if ($ii >= $l || $content[$ii] !== ')') { throw new InvalidEregException('"(" does not have a matching ")"'); } @@ -265,7 +265,7 @@ private function processSquareBracket(string $s, int $i, int $l, string $cls, bo } $start = false; - } while ($i < $l && isset($s[$i]) && $s[$i] !== ']'); + } while ($i < $l && $s[$i] !== ']'); return [$cls, $i]; }