Skip to content
Merged
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
11 changes: 6 additions & 5 deletions src/Type/AcceptsResult.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use PHPStan\ShouldNotHappenException;
use PHPStan\TrinaryLogic;
use function array_map;
use function array_merge;
use function array_unique;
use function array_values;
Expand Down Expand Up @@ -122,15 +121,16 @@ public static function extremeIdentity(self ...$operands): self
throw new ShouldNotHappenException();
}

$result = TrinaryLogic::extremeIdentity(...array_map(static fn (self $result) => $result->result, $operands));
$results = [];
$reasons = [];
foreach ($operands as $operand) {
$results[] = $operand->result;
foreach ($operand->reasons as $reason) {
$reasons[] = $reason;
}
}

return new self($result, array_values(array_unique($reasons)));
return new self(TrinaryLogic::extremeIdentity(...$results), array_values(array_unique($reasons)));
}

/** @see TrinaryLogic::maxMin() */
Expand All @@ -140,15 +140,16 @@ public static function maxMin(self ...$operands): self
throw new ShouldNotHappenException();
}

$result = TrinaryLogic::maxMin(...array_map(static fn (self $result) => $result->result, $operands));
$results = [];
$reasons = [];
foreach ($operands as $operand) {
$results[] = $operand->result;
foreach ($operand->reasons as $reason) {
$reasons[] = $reason;
}
}

return new self($result, array_values(array_unique($reasons)));
return new self(TrinaryLogic::maxMin(...$results), array_values(array_unique($reasons)));
}

}
40 changes: 18 additions & 22 deletions src/Type/IsSuperTypeOfResult.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use PHPStan\ShouldNotHappenException;
use PHPStan\TrinaryLogic;
use function array_map;
use function array_merge;
use function array_unique;
use function array_values;
Expand Down Expand Up @@ -155,9 +154,16 @@ public static function extremeIdentity(self ...$operands): self
throw new ShouldNotHappenException();
}

$result = TrinaryLogic::extremeIdentity(...array_map(static fn (self $result) => $result->result, $operands));
$results = [];
$reasons = [];
foreach ($operands as $operand) {
$results[] = $operand->result;
foreach ($operand->reasons as $reason) {
$reasons[] = $reason;
}
}

return new self($result, self::mergeReasons($operands));
return new self(TrinaryLogic::extremeIdentity(...$results), array_values(array_unique($reasons)));
}

/** @see TrinaryLogic::maxMin() */
Expand All @@ -167,9 +173,16 @@ public static function maxMin(self ...$operands): self
throw new ShouldNotHappenException();
}

$result = TrinaryLogic::maxMin(...array_map(static fn (self $result) => $result->result, $operands));
$results = [];
$reasons = [];
foreach ($operands as $operand) {
$results[] = $operand->result;
foreach ($operand->reasons as $reason) {
$reasons[] = $reason;
}
}

return new self($result, self::mergeReasons($operands));
return new self(TrinaryLogic::maxMin(...$results), array_values(array_unique($reasons)));
}

public function negate(): self
Expand All @@ -182,21 +195,4 @@ public function describe(): string
return $this->result->describe();
}

/**
* @param array<self> $operands
*
* @return list<string>
*/
private static function mergeReasons(array $operands): array
{
$reasons = [];
foreach ($operands as $operand) {
foreach ($operand->reasons as $reason) {
$reasons[] = $reason;
}
}

return array_values(array_unique($reasons));
}

}
Loading