Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 49 additions & 1 deletion src/Analyser/MutatingScope.php
Original file line number Diff line number Diff line change
Expand Up @@ -4647,7 +4647,55 @@ public function equals(self $otherScope): bool
if (!$this->compareVariableTypeHolders($this->expressionTypes, $otherScope->expressionTypes)) {
return false;
}
return $this->compareVariableTypeHolders($this->nativeExpressionTypes, $otherScope->nativeExpressionTypes);
if (!$this->compareVariableTypeHolders($this->nativeExpressionTypes, $otherScope->nativeExpressionTypes)) {
return false;
}

return $this->compareConditionalExpressions($this->conditionalExpressions, $otherScope->conditionalExpressions);
}

/**
* @param array<string, ConditionalExpressionHolder[]> $conditionalExpressions
* @param array<string, ConditionalExpressionHolder[]> $otherConditionalExpressions
*/
private function compareConditionalExpressions(array $conditionalExpressions, array $otherConditionalExpressions): bool
{
if (count($conditionalExpressions) !== count($otherConditionalExpressions)) {
return false;
}
foreach ($conditionalExpressions as $exprString => $holders) {
if (!isset($otherConditionalExpressions[$exprString])) {
return false;
}
$otherHolders = $otherConditionalExpressions[$exprString];
if (count($holders) !== count($otherHolders)) {
return false;
}
foreach ($holders as $key => $holder) {
if (!isset($otherHolders[$key])) {
return false;
}
$otherHolder = $otherHolders[$key];
if (!$holder->getTypeHolder()->equals($otherHolder->getTypeHolder())) {
return false;
}
$conditions = $holder->getConditionExpressionTypeHolders();
$otherConditions = $otherHolder->getConditionExpressionTypeHolders();
if (count($conditions) !== count($otherConditions)) {
return false;
}
foreach ($conditions as $conditionExprString => $conditionHolder) {
if (!isset($otherConditions[$conditionExprString])) {
return false;
}
if (!$conditionHolder->equals($otherConditions[$conditionExprString])) {
return false;
}
}
}
}

return true;
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php declare(strict_types = 1);

namespace LoopFixpointConditionalExpressions;

use function PHPStan\Testing\assertType;

final class Item
{

}

class Foo
{

/** @param list<Item> $items */
public function run(array $items): void
{
foreach ([1, 2] as $_) {
$toCurrent = 0;
if ($items !== []) {
$toCurrent = count($items);
}

while ($toCurrent > 0) {
assertType('list<LoopFixpointConditionalExpressions\Item>', $items);
$item = array_shift($items);
assertType('LoopFixpointConditionalExpressions\Item|null', $item);
$toCurrent--;
}
}
}

}
Loading