1<?php ...
 2 
 3namespace Thunk\Verbs\Examples\Monopoly\Events\Gameplay;
 4 
 5use Thunk\Verbs\Attributes\Autodiscovery\AppliesToState;
 6use Thunk\Verbs\Event;
 7use Thunk\Verbs\Examples\Monopoly\Game\Phase;
 8use Thunk\Verbs\Examples\Monopoly\States\GameState;
 9use Thunk\Verbs\Examples\Monopoly\States\PlayerState; 
10 
11#[AppliesToState(GameState::class)]
12#[AppliesToState(PlayerState::class)]
13class EndedTurn extends Event
14{
15    use PlayerAction;
16 
17    public function __construct(
18        public int $game_id,
19        public int $player_id,
20    ) {}
21 
22    public function validateGame(GameState $game)
23    {
24        $this->assert($game->phase_complete, 'You have to finish what you’re doing before you can end your turn.');
25        $this->assert($game->phase->canTransitionTo(Phase::EndTurn), 'You must complete your turn before ending it.');
26    }
27 
28    public function applyToGame(GameState $game)
29    {
30        $game->moveToNextPlayer();
31        $game->phase = Phase::Move;
32        $game->phase_complete = false;
33    }
34}