Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 11 additions & 8 deletions src/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand All @@ -122,7 +128,6 @@ public function addResult(string $resultClass, string $resultRendererClass): voi
*/
public function setLogo(string $logo): void
{
Assertion::string($logo);
$this->logo = $logo;
}

Expand All @@ -134,7 +139,6 @@ public function setLogo(string $logo): void
*/
public function setFgColour(string $colour): void
{
Assertion::string($colour);
$this->fgColour = $colour;
}

Expand All @@ -146,7 +150,6 @@ public function setFgColour(string $colour): void
*/
public function setBgColour(string $colour): void
{
Assertion::string($colour);
$this->bgColour = $colour;
}

Expand Down
8 changes: 6 additions & 2 deletions src/CodeInsertion.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down
1 change: 0 additions & 1 deletion src/Event/CliExecuteEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace PhpSchool\PhpWorkshop\Event;

use Assert\Assertion;
use PhpSchool\PhpWorkshop\Utils\ArrayObject;

/**
Expand Down
2 changes: 1 addition & 1 deletion test/CodeInsertionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down