for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
declare(strict_types=1);
namespace Stu\Module\Tick\Npc;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use JsonMapper\JsonMapperInterface;
use RuntimeException;
use Stu\Component\Event\Payload\PayloadWithIdAndTurn;
use Stu\Component\Event\Strategy\EventStrategyInterface;
use Stu\Module\Tick\Ship\ManagerComponent\NpcShipHandling;
use Stu\Orm\Entity\EventInterface;
use Stu\Orm\Entity\UserInterface;
use Stu\Orm\Repository\UserRepositoryInterface;
class NpcTick implements EventStrategyInterface
{
public function __construct(
private UserRepositoryInterface $userRepository,
private JsonMapperInterface $jsonMapper,
private NpcShipHandling $npcShipHandling
) {
}
public function getEntitiesToLock(EventInterface $event): Collection
return new ArrayCollection([$this->getUser($event)]);
public function processEvent(EventInterface $event): void
$this->npcShipHandling->processUser($this->getUser($event));
private function getUser(EventInterface $event): UserInterface
/** @var PayloadWithIdAndTurn */
$payload = $event->getPayloadAsObject($this->jsonMapper);
$user = $this->userRepository->find($payload->id);
if ($user === null) {
throw new RuntimeException(sprintf('userId %d does not exist', $payload->id));
return $user;