for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
declare(strict_types = 1);
namespace Puzzle\ValueObjects;
use Puzzle\Pieces\ConvertibleToString;
class SelfValidatedUuid implements ConvertibleToString, \JsonSerializable
{
private
$uuid;
$uuid
The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using
class A { var $property; }
the property is implicitly global.
To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.
public function __construct(?string $uuid = null)
if($uuid === null)
$uuid = (string) \Ramsey\Uuid\Uuid::uuid4();
}
else
$this->validateUuid($uuid);
$this->uuid = $uuid;
public function value(): string
return $this->uuid;
public function equals(SelfValidatedUuid $uuid): bool
return $this->uuid === $uuid->value();
public function __toString(): string
private function validateUuid(string $string): void
$validator = \Symfony\Component\Validator\Validation::createValidator();
$errors = $validator->validate(
$string,
new \Symfony\Component\Validator\Constraints\Uuid()
);
if (count($errors) > 0)
throw new Exceptions\InvalidUuid($string);
public function jsonSerialize()
return $this->value();
The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using
the property is implicitly global.
To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.