diff --git a/src/Application.php b/src/Application.php index 3d9bcdb6..11ef2b29 100644 --- a/src/Application.php +++ b/src/Application.php @@ -2,9 +2,9 @@ namespace PhpSchool\PhpWorkshop; -use Assert\Assertion; use DI\ContainerBuilder; use PhpSchool\PhpWorkshop\Check\CheckRepository; +use PhpSchool\PhpWorkshop\Exception\InvalidArgumentException; use PhpSchool\PhpWorkshop\Exception\MissingArgumentException; use PhpSchool\PhpWorkshop\Exercise\ExerciseInterface; use PhpSchool\PhpWorkshop\Factory\ResultRendererFactory; @@ -70,8 +70,9 @@ final class Application */ public function __construct(string $workshopTitle, string $diConfigFile) { - Assertion::string($workshopTitle); - Assertion::file($diConfigFile); + if (!\is_file($diConfigFile)) { + throw new InvalidArgumentException(\sprintf('File "%s" was expected to exist.', $diConfigFile)); + } $this->workshopTitle = $workshopTitle; $this->diConfigFile = $diConfigFile; @@ -105,8 +106,13 @@ public function addExercise(string $exercise): void */ public function addResult(string $resultClass, string $resultRendererClass): void { - Assertion::classExists($resultClass); - Assertion::classExists($resultRendererClass); + if (!\class_exists($resultClass)) { + throw new InvalidArgumentException(\sprintf('Class "%s" does not exist', $resultClass)); + } + + if (!\class_exists($resultRendererClass)) { + throw new InvalidArgumentException(\sprintf('Class "%s" does not exist', $resultRendererClass)); + } $this->results[] = [ 'resultClass' => $resultClass, @@ -122,7 +128,6 @@ public function addResult(string $resultClass, string $resultRendererClass): voi */ public function setLogo(string $logo): void { - Assertion::string($logo); $this->logo = $logo; } @@ -134,7 +139,6 @@ public function setLogo(string $logo): void */ public function setFgColour(string $colour): void { - Assertion::string($colour); $this->fgColour = $colour; } @@ -146,7 +150,6 @@ public function setFgColour(string $colour): void */ public function setBgColour(string $colour): void { - Assertion::string($colour); $this->bgColour = $colour; } diff --git a/src/CodeInsertion.php b/src/CodeInsertion.php index b1866a7e..d7cd8fa1 100644 --- a/src/CodeInsertion.php +++ b/src/CodeInsertion.php @@ -2,7 +2,7 @@ namespace PhpSchool\PhpWorkshop; -use Assert\Assertion; +use PhpSchool\PhpWorkshop\Exception\InvalidArgumentException; /** * This class is a simple DTO to represent a code insertion which should @@ -49,7 +49,11 @@ class CodeInsertion */ public function __construct(string $type, string $code) { - Assertion::inArray($type, $this->types); + if (!in_array($type, $this->types, true)) { + throw new InvalidArgumentException( + sprintf('Value "%s" is not an element of the valid values: %s', $type, implode(', ', $this->types)) + ); + } $this->type = $type; $this->code = $code; diff --git a/src/Event/CliExecuteEvent.php b/src/Event/CliExecuteEvent.php index 43d520b7..ea2e5361 100644 --- a/src/Event/CliExecuteEvent.php +++ b/src/Event/CliExecuteEvent.php @@ -2,7 +2,6 @@ namespace PhpSchool\PhpWorkshop\Event; -use Assert\Assertion; use PhpSchool\PhpWorkshop\Utils\ArrayObject; /** diff --git a/test/CodeInsertionTest.php b/test/CodeInsertionTest.php index b385ca71..2baf2c88 100644 --- a/test/CodeInsertionTest.php +++ b/test/CodeInsertionTest.php @@ -2,8 +2,8 @@ namespace PhpSchool\PhpWorkshopTest; -use Assert\InvalidArgumentException; use PhpSchool\PhpWorkshop\CodeInsertion; +use PhpSchool\PhpWorkshop\Exception\InvalidArgumentException; use PHPUnit\Framework\TestCase; class CodeInsertionTest extends TestCase