Skip to content

Commit 357f0dd

Browse files
committed
Use constants for all error messages
1 parent 6aabfa8 commit 357f0dd

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

src/Filter/UuidFilter.php

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,16 @@ final class UuidFilter
2222
*/
2323
const FILTER_ERROR_FORMAT = "Value '%s' is not a valid UUID. Versions checked (%s)";
2424

25+
/**
26+
* @var string
27+
*/
28+
const NULL_NOT_ALLOWED_ERROR = "Value is null, but null values are not allowed.";
29+
30+
/**
31+
* @var string
32+
*/
33+
const UNSUPPORTED_VERSION_ERROR_FORMAT = 'Filter does not support UUID v%d';
34+
2535
/**
2636
* @var array
2737
* @internal
@@ -69,7 +79,7 @@ public static function filter(
6979
private static function valueIsNullAndValid(bool $allowNull, string $value = null): bool
7080
{
7181
if ($allowNull === false && $value === null) {
72-
throw new FilterException('Value failed filtering, $allowNull is set to false');
82+
throw new FilterException(self::NULL_NOT_ALLOWED_ERROR);
7383
}
7484

7585
return $allowNull === true && $value === null;
@@ -79,7 +89,7 @@ private static function validateVersions(array $versions)
7989
{
8090
foreach ($versions as $version) {
8191
if (!in_array($version, self::VALID_UUID_VERSIONS)) {
82-
throw new InvalidArgumentException("Filter does not support UUID v{$version}");
92+
throw new InvalidArgumentException(sprintf(self::UNSUPPORTED_VERSION_ERROR_FORMAT, $version));
8393
}
8494
}
8595
}

tests/Filter/UuidFilterTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ public function filterNullAllowedNullIsFalse()
8484
public function filterWithInvalidVersionSpecified()
8585
{
8686
$this->expectException(InvalidArgumentException::class);
87-
$this->expectExceptionMessage('Filter does not support UUID v0');
87+
$this->expectExceptionMessage(sprintf(UuidFilter::UNSUPPORTED_VERSION_ERROR_FORMAT, 0));
8888
UuidFilter::filter(self::UUID_V7, false, [0]);
8989
}
9090

0 commit comments

Comments
 (0)