Lines 100.00% 12 / 12
Methods 100.00% 5 / 5
Classes 100.00% 1 / 1
Name Lines Methods CRAP
 __construct 100.00% 1 / 1 100.00% 1 / 1 1
 of 100.00% 5 / 5 100.00% 1 / 1 3
 none 100.00% 1 / 1 100.00% 1 / 1 1
 allows 100.00% 4 / 4 100.00% 1 / 1 3
 guards 100.00% 1 / 1 100.00% 1 / 1 1
15final readonly class ClassRules
16{
17    /** @param array<string, non-empty-list<SkillRule>> $slots */
18    private function __construct(
19        private array $slots = [],
20    ) {}
21
22    public static function of(ClassName $class): self
23    {
24        return match (strtolower($class->value)) {
25            'oracle' => new self([
26                SkillSlot::Second->name => [new HealthBelow(50), new ManaAbove(50)],
27            ]),
28            default => new self(),
29        };
30    }
31
32    public static function none(): self
33    {
34        return new self();
35    }
36
37    public function allows(Skill $skill, Vitals $vitals): bool
38    {
39        foreach ($this->slots[$skill->slot->name] ?? [] as $rule) {
40            if (!$rule->allows($vitals)) {
41                return false;
42            }
43        }
44
45        return true;
46    }
47
48    public function guards(Skill $skill): bool
49    {
50        return array_key_exists($skill->slot->name, $this->slots);
51    }
52}