Skip to content

Commit

Permalink
cs
Browse files Browse the repository at this point in the history
  • Loading branch information
staabm committed Jun 15, 2024
1 parent ed25873 commit 323ad98
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions src/Rules/Functions/PrintfArrayParametersRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

/**
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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();
Expand All @@ -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();
}

}

0 comments on commit 323ad98

Please sign in to comment.