From 323ad98c3cbcdffaf3f8b6055da9b93c7193fa43 Mon Sep 17 00:00:00 2001 From: Markus Staab Date: Wed, 5 Jun 2024 11:42:34 +0200 Subject: [PATCH] cs --- .../Functions/PrintfArrayParametersRule.php | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/src/Rules/Functions/PrintfArrayParametersRule.php b/src/Rules/Functions/PrintfArrayParametersRule.php index f566bedcc3..09a6bf00cc 100644 --- a/src/Rules/Functions/PrintfArrayParametersRule.php +++ b/src/Rules/Functions/PrintfArrayParametersRule.php @@ -2,7 +2,6 @@ namespace PHPStan\Rules\Functions; -use Hoa\Stream\Test\Unit\IStream\In; use PhpParser\Node; use PhpParser\Node\Expr\FuncCall; use PHPStan\Analyser\Scope; @@ -12,9 +11,12 @@ use PHPStan\ShouldNotHappenException; use PHPStan\Type\Constant\ConstantIntegerType; use PHPStan\Type\IntegerRangeType; +use PHPStan\Type\Type; use PHPStan\Type\TypeCombinator; use function count; use function in_array; +use function max; +use function min; use function sprintf; /** @@ -77,7 +79,6 @@ public function processNode(Node $node, Scope $scope): array $placeHoldersCount = IntegerRangeType::fromInterval($minCount, $maxCount); } - $formatArgsCounts = []; if (isset($args[1])) { $formatArgsType = $scope->getType($args[1]->value); @@ -137,7 +138,7 @@ public function processNode(Node $node, Scope $scope): array return []; } - private function placeholdersMatchesArgsCount(IntegerRangeType|ConstantIntegerType $placeHoldersCount, IntegerRangeType|ConstantIntegerType $formatArgsCount): bool + private function placeholdersMatchesArgsCount(Type $placeHoldersCount, Type $formatArgsCount): bool { if ($placeHoldersCount instanceof ConstantIntegerType && $formatArgsCount instanceof ConstantIntegerType) { return $placeHoldersCount->getValue() === $formatArgsCount->getValue(); @@ -153,29 +154,31 @@ private function placeholdersMatchesArgsCount(IntegerRangeType|ConstantIntegerTy if ($placeHoldersCount instanceof IntegerRangeType && $formatArgsCount instanceof IntegerRangeType - && IntegerRangeType::fromInterval(1, null)->isSuperTypeOf($placeHoldersCount)->yes() + && IntegerRangeType::fromInterval(1, null)->isSuperTypeOf($placeHoldersCount)->yes() ) { if ($formatArgsCount->getMin() !== null && $formatArgsCount->getMax() !== null) { // constant array return $placeHoldersCount->isSuperTypeOf($formatArgsCount)->yes(); } + // general array return IntegerRangeType::fromInterval(1, null)->isSuperTypeOf($formatArgsCount)->yes(); } return false; } - private function getIntegerRangeAsString(IntegerRangeType $range): string { + private function getIntegerRangeAsString(IntegerRangeType $range): string + { if ($range->getMin() !== null && $range->getMax() !== null) { return $range->getMin() . '-' . $range->getMax(); } elseif ($range->getMin() !== null) { return $range->getMin() . ' or more'; } elseif ($range->getMax() !== null) { return $range->getMax() . ' or less'; - } else { - throw new ShouldNotHappenException(); } + + throw new ShouldNotHappenException(); } }