| 1: | <?php declare(strict_types = 1); |
| 2: | |
| 3: | namespace PHPStan\Rules; |
| 4: | |
| 5: | use function array_merge; |
| 6: | |
| 7: | |
| 8: | |
| 9: | |
| 10: | final class RuleLevelHelperAcceptsResult |
| 11: | { |
| 12: | |
| 13: | |
| 14: | |
| 15: | |
| 16: | public function __construct( |
| 17: | public readonly bool $result, |
| 18: | public readonly array $reasons, |
| 19: | ) |
| 20: | { |
| 21: | } |
| 22: | |
| 23: | public function and(self $other): self |
| 24: | { |
| 25: | return new self( |
| 26: | $this->result && $other->result, |
| 27: | array_merge($this->reasons, $other->reasons), |
| 28: | ); |
| 29: | } |
| 30: | |
| 31: | |
| 32: | |
| 33: | |
| 34: | public function decorateReasons(callable $cb): self |
| 35: | { |
| 36: | $reasons = []; |
| 37: | foreach ($this->reasons as $reason) { |
| 38: | $reasons[] = $cb($reason); |
| 39: | } |
| 40: | |
| 41: | return new self($this->result, $reasons); |
| 42: | } |
| 43: | |
| 44: | } |
| 45: | |