44
55use PHPStan \ShouldNotHappenException ;
66use PHPStan \TrinaryLogic ;
7- use function array_map ;
87use function array_merge ;
98use function array_unique ;
109use function array_values ;
@@ -155,9 +154,16 @@ public static function extremeIdentity(self ...$operands): self
155154 throw new ShouldNotHappenException ();
156155 }
157156
158- $ result = TrinaryLogic::extremeIdentity (...array_map (static fn (self $ result ) => $ result ->result , $ operands ));
157+ $ results = [];
158+ $ reasons = [];
159+ foreach ($ operands as $ operand ) {
160+ $ results [] = $ operand ->result ;
161+ foreach ($ operand ->reasons as $ reason ) {
162+ $ reasons [] = $ reason ;
163+ }
164+ }
159165
160- return new self ($ result , self :: mergeReasons ( $ operands ));
166+ return new self (TrinaryLogic:: extremeIdentity (... $ results ), array_values ( array_unique ( $ reasons ) ));
161167 }
162168
163169 /** @see TrinaryLogic::maxMin() */
@@ -167,9 +173,16 @@ public static function maxMin(self ...$operands): self
167173 throw new ShouldNotHappenException ();
168174 }
169175
170- $ result = TrinaryLogic::maxMin (...array_map (static fn (self $ result ) => $ result ->result , $ operands ));
176+ $ results = [];
177+ $ reasons = [];
178+ foreach ($ operands as $ operand ) {
179+ $ results [] = $ operand ->result ;
180+ foreach ($ operand ->reasons as $ reason ) {
181+ $ reasons [] = $ reason ;
182+ }
183+ }
171184
172- return new self ($ result , self :: mergeReasons ( $ operands ));
185+ return new self (TrinaryLogic:: maxMin (... $ results ), array_values ( array_unique ( $ reasons ) ));
173186 }
174187
175188 public function negate (): self
@@ -182,21 +195,4 @@ public function describe(): string
182195 return $ this ->result ->describe ();
183196 }
184197
185- /**
186- * @param array<self> $operands
187- *
188- * @return list<string>
189- */
190- private static function mergeReasons (array $ operands ): array
191- {
192- $ reasons = [];
193- foreach ($ operands as $ operand ) {
194- foreach ($ operand ->reasons as $ reason ) {
195- $ reasons [] = $ reason ;
196- }
197- }
198-
199- return array_values (array_unique ($ reasons ));
200- }
201-
202198}
0 commit comments