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
7 changes: 6 additions & 1 deletion src/Guid.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace SmartEmailing\Types;

use Nette\Utils\Strings;
use SmartEmailing\Types\Comparable\ComparableInterface;
use SmartEmailing\Types\Comparable\StringComparableTrait;
use SmartEmailing\Types\ExtractableTraits\StringExtractableTrait;
Expand All @@ -15,12 +16,16 @@ final class Guid implements ToStringInterface, ComparableInterface
use ToStringTrait;
use StringComparableTrait;

private string $value;

private function __construct(
private string $value
string $value
) {
if (\preg_match('/^[a-f\d]{8}(-[a-f\d]{4}){4}[a-f\d]{8}$/i', $value) !== 1) {
throw new InvalidTypeException('Invalid guid value');
}

$this->value = Strings::lower($value);
}

public static function fromHex32(
Expand Down
8 changes: 7 additions & 1 deletion tests/GuidTest.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ declare(strict_types = 1);

namespace SmartEmailing\Types;

use Nette\Utils\Strings;
use Tester\Assert;
use Tester\TestCase;

Expand Down Expand Up @@ -32,11 +33,16 @@ final class GuidTest extends TestCase

$validValues = [
'd7c8539e-089e-11e8-b161-2edbc134be21',
'd7c8539e-089E-11E8-B161-2edbc134be21',
];

foreach ($validValues as $validValue) {
$guid = Guid::from($validValue);
Assert::equal($validValue, $guid->getValue());

Assert::equal(
Strings::lower($validValue),
$guid->getValue()
);
}
}

Expand Down
Loading