From ff28b2eb1d7c608f6ce18d4f4a6215ca658392ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jon=20Gonz=C3=A1lez=20Garrido?= Date: Sun, 5 Nov 2023 18:20:48 +0100 Subject: [PATCH] Fix psaml error in level 3 --- psalm.xml | 2 +- src/Domain/GameGenerator/RandomGameGenerator.php | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/psalm.xml b/psalm.xml index 8be3a1d..424fc7d 100644 --- a/psalm.xml +++ b/psalm.xml @@ -1,6 +1,6 @@ randomRule(); $game = new Game(array_merge($rules, [$rule]), $crime); @@ -56,6 +57,10 @@ public function __invoke(): Game echo $exception->getMessage() . PHP_EOL; } } + + if ($game === null) { + throw new \LogicException('This should not happen'); + } echo 'Se ha conseguido crear un juego! ' . PHP_EOL; return $game; } @@ -83,8 +88,12 @@ private function randomRule(): Rule private function randomDogAcrossToDogRule(string $className): TwoDogPlaced { + if (!is_subclass_of($className, TwoDogPlaced::class)) { + throw new \InvalidArgumentException("$className must be a subclass of TwoDogPlaced"); + } $firstDogDefinition = $this->randomDogDefinition(); $secondDogDefinition = $this->randomDogDefinition(); + return new $className( 'El perro %s está enfrente del perro %s', $firstDogDefinition,