Skip to content

Commit

Permalink
Manual assertion of input in AggregateType (#586)
Browse files Browse the repository at this point in the history
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`.
  • Loading branch information
ben-challis authored Oct 12, 2023
1 parent 16a585f commit 645f2a0
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion .php-cs-fixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@
'phpdoc_return_self_reference' => true,
'phpdoc_scalar' => true,
'phpdoc_single_line_var_spacing' => true,
'phpdoc_to_comment' => true,
'phpdoc_to_comment' => false,
'phpdoc_types' => true,
'phpdoc_var_without_name' => true,
'increment_style' => ['style' => 'post'],
Expand Down
12 changes: 6 additions & 6 deletions src/AggregateType.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@

namespace Lendable\Aggregate;

use Assert\Assertion;
use Assert\AssertionFailedException;

/**
* A type classification of an aggregate.
*/
Expand All @@ -18,17 +15,20 @@ final class AggregateType
private readonly string $value;

/**
* @throws AssertionFailedException If $value is empty.
* @throws \InvalidArgumentException If $value is empty.
*/
private function __construct(string $value)
{
Assertion::notEmpty($value, 'Aggregate type cannot be empty.');
if (\trim($value) === '') {
throw new \InvalidArgumentException('Aggregate type cannot be empty.');
}

/** @var non-empty-string $value */
$this->value = $value;
}

/**
* @throws AssertionFailedException If $value is empty.
* @throws \InvalidArgumentException If $value is empty.
*/
public static function fromString(string $value): self
{
Expand Down

0 comments on commit 645f2a0

Please sign in to comment.