1: <?php declare(strict_types = 1);
2:
3: namespace PHPStan\Rules;
4:
5: use PHPStan\Turbo\ReferencedByTurboExtension;
6: use PHPStan\Type\Type;
7: use function array_merge;
8:
9: /**
10: * @api
11: */
12: #[ReferencedByTurboExtension(key: 'ruleLevelHelperAcceptsResult')]
13: final class RuleLevelHelperAcceptsResult
14: {
15:
16: /**
17: * @param list<string> $reasons
18: * @param Type|null $witnessType Set when the accepted type is a mixed accepted on its own, but its witness type, what some path is known to produce, is not. Rules report it as the given type.
19: */
20: public function __construct(
21: public readonly bool $result,
22: public readonly array $reasons,
23: public readonly ?Type $witnessType = null,
24: )
25: {
26: }
27:
28: public function and(self $other): self
29: {
30: return new self(
31: $this->result && $other->result,
32: array_merge($this->reasons, $other->reasons),
33: $this->witnessType ?? $other->witnessType,
34: );
35: }
36:
37: /**
38: * @param callable(string): string $cb
39: */
40: public function decorateReasons(callable $cb): self
41: {
42: $reasons = [];
43: foreach ($this->reasons as $reason) {
44: $reasons[] = $cb($reason);
45: }
46:
47: return new self($this->result, $reasons, $this->witnessType);
48: }
49:
50: }
51: