diff --git a/src/Type/AcceptsResult.php b/src/Type/AcceptsResult.php index 3696e43717..1690d7b90c 100644 --- a/src/Type/AcceptsResult.php +++ b/src/Type/AcceptsResult.php @@ -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; @@ -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() */ @@ -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))); } } diff --git a/src/Type/IsSuperTypeOfResult.php b/src/Type/IsSuperTypeOfResult.php index 2ce7d21e2d..b0826f518c 100644 --- a/src/Type/IsSuperTypeOfResult.php +++ b/src/Type/IsSuperTypeOfResult.php @@ -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; @@ -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() */ @@ -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 @@ -182,21 +195,4 @@ public function describe(): string return $this->result->describe(); } - /** - * @param array $operands - * - * @return list - */ - 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)); - } - }