Skip to content

Commit fc17359

Browse files
authored
Merge pull request #171 from php-school/drop-beberlei-assert
Drop beberlei/assert
2 parents 1125bc6 + 89c9f2b commit fc17359

File tree

4 files changed

+18
-12
lines changed

4 files changed

+18
-12
lines changed

src/Application.php

+11-8
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
namespace PhpSchool\PhpWorkshop;
44

5-
use Assert\Assertion;
65
use DI\ContainerBuilder;
76
use PhpSchool\PhpWorkshop\Check\CheckRepository;
7+
use PhpSchool\PhpWorkshop\Exception\InvalidArgumentException;
88
use PhpSchool\PhpWorkshop\Exception\MissingArgumentException;
99
use PhpSchool\PhpWorkshop\Exercise\ExerciseInterface;
1010
use PhpSchool\PhpWorkshop\Factory\ResultRendererFactory;
@@ -70,8 +70,9 @@ final class Application
7070
*/
7171
public function __construct(string $workshopTitle, string $diConfigFile)
7272
{
73-
Assertion::string($workshopTitle);
74-
Assertion::file($diConfigFile);
73+
if (!\is_file($diConfigFile)) {
74+
throw new InvalidArgumentException(\sprintf('File "%s" was expected to exist.', $diConfigFile));
75+
}
7576

7677
$this->workshopTitle = $workshopTitle;
7778
$this->diConfigFile = $diConfigFile;
@@ -105,8 +106,13 @@ public function addExercise(string $exercise): void
105106
*/
106107
public function addResult(string $resultClass, string $resultRendererClass): void
107108
{
108-
Assertion::classExists($resultClass);
109-
Assertion::classExists($resultRendererClass);
109+
if (!\class_exists($resultClass)) {
110+
throw new InvalidArgumentException(\sprintf('Class "%s" does not exist', $resultClass));
111+
}
112+
113+
if (!\class_exists($resultRendererClass)) {
114+
throw new InvalidArgumentException(\sprintf('Class "%s" does not exist', $resultRendererClass));
115+
}
110116

111117
$this->results[] = [
112118
'resultClass' => $resultClass,
@@ -122,7 +128,6 @@ public function addResult(string $resultClass, string $resultRendererClass): voi
122128
*/
123129
public function setLogo(string $logo): void
124130
{
125-
Assertion::string($logo);
126131
$this->logo = $logo;
127132
}
128133

@@ -134,7 +139,6 @@ public function setLogo(string $logo): void
134139
*/
135140
public function setFgColour(string $colour): void
136141
{
137-
Assertion::string($colour);
138142
$this->fgColour = $colour;
139143
}
140144

@@ -146,7 +150,6 @@ public function setFgColour(string $colour): void
146150
*/
147151
public function setBgColour(string $colour): void
148152
{
149-
Assertion::string($colour);
150153
$this->bgColour = $colour;
151154
}
152155

src/CodeInsertion.php

+6-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
namespace PhpSchool\PhpWorkshop;
44

5-
use Assert\Assertion;
5+
use PhpSchool\PhpWorkshop\Exception\InvalidArgumentException;
66

77
/**
88
* This class is a simple DTO to represent a code insertion which should
@@ -49,7 +49,11 @@ class CodeInsertion
4949
*/
5050
public function __construct(string $type, string $code)
5151
{
52-
Assertion::inArray($type, $this->types);
52+
if (!in_array($type, $this->types, true)) {
53+
throw new InvalidArgumentException(
54+
sprintf('Value "%s" is not an element of the valid values: %s', $type, implode(', ', $this->types))
55+
);
56+
}
5357

5458
$this->type = $type;
5559
$this->code = $code;

src/Event/CliExecuteEvent.php

-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
namespace PhpSchool\PhpWorkshop\Event;
44

5-
use Assert\Assertion;
65
use PhpSchool\PhpWorkshop\Utils\ArrayObject;
76

87
/**

test/CodeInsertionTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
namespace PhpSchool\PhpWorkshopTest;
44

5-
use Assert\InvalidArgumentException;
65
use PhpSchool\PhpWorkshop\CodeInsertion;
6+
use PhpSchool\PhpWorkshop\Exception\InvalidArgumentException;
77
use PHPUnit\Framework\TestCase;
88

99
class CodeInsertionTest extends TestCase

0 commit comments

Comments
 (0)