Lines
100.00%
6 / 6
Functions and Methods
100.00%
3 / 3
Classes and Traits
100.00%
1 / 1
| Name | Lines | Functions and Methods | CRAP | Classes and Traits | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| JoinMapCommand | 100.00% | 6 / 6 | 100.00% | 3 / 3 | 4 | 100.00% | 1 / 1 | |||
| __construct | 100.00% | 1 / 1 | 100.00% | 1 / 1 | 1 | |||||
| inRoom | 100.00% | 1 / 1 | 100.00% | 1 / 1 | 2 | |||||
| toMessage | 100.00% | 4 / 4 | 100.00% | 1 / 1 | 1 | |||||
| 1 | <?php | |
| 2 | ||
| 3 | declare(strict_types=1); | |
| 4 | ||
| 5 | namespace Lorekeeper\Client\Command\Map; | |
| 6 | ||
| 7 | use Lorekeeper\Client\Command\Command; | |
| 8 | use Lorekeeper\Core\Player\PlayerName; | |
| 9 | use Lorekeeper\Core\World\Map\MapName; | |
| 10 | use Lorekeeper\Core\World\Map\MapRoom; | |
| 11 | use Override; | |
| 12 | use Psl\Option; | |
| 13 | ||
| 14 | final readonly class JoinMapCommand implements Command | |
| 15 | { | |
| 16 | /** @param Option\Option<MapRoom> $room */ | |
| 17 | public function __construct( | |
| 18 | private PlayerName $playerName, | |
| 19 | public MapName $mapName, | |
| 20 | private Option\Option $room, | |
| 21 | ) {} | |
| 22 | ||
| 23 | public function inRoom(MapRoom $room): self | |
| 24 | { | |
| 25 | return $this->room->isSome() ? $this : new self($this->playerName, $this->mapName, Option\some($room)); | |
| 26 | } | |
| 27 | ||
| 28 | #[Override] | |
| 29 | public function toMessage(): string | |
| 30 | { | |
| 31 | return $this->room->proceed( | |
| 32 | fn(MapRoom $room) => "%xt%zm%cmd%1%tfer%{$this->playerName}%{$this->mapName}-{$room}%", | |
| 33 | fn() => "%xt%zm%cmd%1%tfer%{$this->playerName}%{$this->mapName}%", | |
| 34 | ); | |
| 35 | } | |
| 36 | } |