Skip to content

Commit 645f2a0

Browse files
authored
Manual assertion of input in AggregateType (#586)
Shifting towards ensuring that we can rely on `\InvalidArgumentException` rather than the `AssertionFailedException` interface, which can be overriden globally to throw an exception that doesn't extend `\InvalidArgumentException`.
1 parent 16a585f commit 645f2a0

2 files changed

Lines changed: 7 additions & 7 deletions

File tree

.php-cs-fixer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@
8686
'phpdoc_return_self_reference' => true,
8787
'phpdoc_scalar' => true,
8888
'phpdoc_single_line_var_spacing' => true,
89-
'phpdoc_to_comment' => true,
89+
'phpdoc_to_comment' => false,
9090
'phpdoc_types' => true,
9191
'phpdoc_var_without_name' => true,
9292
'increment_style' => ['style' => 'post'],

src/AggregateType.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,6 @@
44

55
namespace Lendable\Aggregate;
66

7-
use Assert\Assertion;
8-
use Assert\AssertionFailedException;
9-
107
/**
118
* A type classification of an aggregate.
129
*/
@@ -18,17 +15,20 @@ final class AggregateType
1815
private readonly string $value;
1916

2017
/**
21-
* @throws AssertionFailedException If $value is empty.
18+
* @throws \InvalidArgumentException If $value is empty.
2219
*/
2320
private function __construct(string $value)
2421
{
25-
Assertion::notEmpty($value, 'Aggregate type cannot be empty.');
22+
if (\trim($value) === '') {
23+
throw new \InvalidArgumentException('Aggregate type cannot be empty.');
24+
}
2625

26+
/** @var non-empty-string $value */
2727
$this->value = $value;
2828
}
2929

3030
/**
31-
* @throws AssertionFailedException If $value is empty.
31+
* @throws \InvalidArgumentException If $value is empty.
3232
*/
3333
public static function fromString(string $value): self
3434
{

0 commit comments

Comments
 (0)