Lines
100.00%
8 / 8
Functions and Methods
100.00%
4 / 4
Classes and Traits
100.00%
1 / 1
| Name | Lines | Functions and Methods | CRAP | Classes and Traits | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| HeroSettings | 100.00% | 8 / 8 | 100.00% | 4 / 4 | 5 | 100.00% | 1 / 1 | |||
| __construct | 100.00% | 1 / 1 | 100.00% | 1 / 1 | 1 | |||||
| allows | 100.00% | 1 / 1 | 100.00% | 1 / 1 | 1 | |||||
| allow | 100.00% | 2 / 2 | 100.00% | 1 / 1 | 2 | |||||
| deny | 100.00% | 4 / 4 | 100.00% | 1 / 1 | 1 | |||||
| 1 | <?php | |
| 2 | ||
| 3 | declare(strict_types=1); | |
| 4 | ||
| 5 | namespace Lorekeeper\Core\Player\Hero; | |
| 6 | ||
| 7 | use Lorekeeper\Core\Game\Setting\GameSetting; | |
| 8 | ||
| 9 | final class HeroSettings | |
| 10 | { | |
| 11 | /** @param list<GameSetting> $allowed */ | |
| 12 | public function __construct( | |
| 13 | public private(set) array $allowed = [], | |
| 14 | ) {} | |
| 15 | ||
| 16 | public function allows(GameSetting $setting): bool | |
| 17 | { | |
| 18 | return in_array($setting, $this->allowed, strict: true); | |
| 19 | } | |
| 20 | ||
| 21 | public function allow(GameSetting $setting): void | |
| 22 | { | |
| 23 | if (!$this->allows($setting)) { | |
| 24 | $this->allowed[] = $setting; | |
| 25 | } | |
| 26 | } | |
| 27 | ||
| 28 | public function deny(GameSetting $setting): void | |
| 29 | { | |
| 30 | $this->allowed = array_values(array_filter( | |
| 31 | $this->allowed, | |
| 32 | static fn(GameSetting $allowed): bool => $allowed !== $setting, | |
| 33 | )); | |
| 34 | } | |
| 35 | } |