Skip to content

Commit

Permalink
use ConstantIntegerType|IntegerRangeType
Browse files Browse the repository at this point in the history
  • Loading branch information
staabm committed Jul 17, 2024
1 parent fa3a1d2 commit d7c8d95
Showing 1 changed file with 17 additions and 10 deletions.
27 changes: 17 additions & 10 deletions src/Rules/Functions/PrintfArrayParametersRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@ public function processNode(Node $node, Scope $scope): array
$placeHoldersCount = new ConstantIntegerType($minCount);
} else {
$placeHoldersCount = IntegerRangeType::fromInterval($minCount, $maxCount);

if (!$placeHoldersCount instanceof IntegerRangeType && !$placeHoldersCount instanceof ConstantIntegerType) {
return [];
}
}

$formatArgsCounts = [];
Expand All @@ -96,6 +100,10 @@ public function processNode(Node $node, Scope $scope): array
$formatArgsCount = new ConstantIntegerType(0);
} else {
$formatArgsCount = TypeCombinator::union(...$formatArgsCounts);

if (!$formatArgsCount instanceof IntegerRangeType && !$formatArgsCount instanceof ConstantIntegerType) {
return [];
}
}

if (!$this->placeholdersMatchesArgsCount($placeHoldersCount, $formatArgsCount)) {
Expand Down Expand Up @@ -133,18 +141,17 @@ public function processNode(Node $node, Scope $scope): array
return [];
}

private function placeholdersMatchesArgsCount(Type $placeHoldersCount, Type $formatArgsCount): bool
private function placeholdersMatchesArgsCount(ConstantIntegerType|IntegerRangeType $placeHoldersCount, ConstantIntegerType|IntegerRangeType $formatArgsCount): bool
{
if ($placeHoldersCount instanceof ConstantIntegerType && $formatArgsCount instanceof ConstantIntegerType) {
return $placeHoldersCount->getValue() === $formatArgsCount->getValue();
}
if ($placeHoldersCount instanceof ConstantIntegerType) {
if ($formatArgsCount instanceof ConstantIntegerType) {
return $placeHoldersCount->getValue() === $formatArgsCount->getValue();
}

// Zero placeholders + array
if ($placeHoldersCount instanceof ConstantIntegerType
&& $placeHoldersCount->getValue() === 0
&& $formatArgsCount instanceof IntegerRangeType
) {
return true;
// Zero placeholders + array
if ($placeHoldersCount->getValue() === 0) {
return true;
}
}

if ($placeHoldersCount instanceof IntegerRangeType
Expand Down

0 comments on commit d7c8d95

Please sign in to comment.