Skip to content
Permalink
master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
<?php
declare(strict_types=1);
final class username
{
private $username;
private function __construct(string $username)
{
$this->ensureIsValidUsername($username);
$this->username = $username;
}
public static function fromString(string $username): self
{
return new self($username);
}
public function __toString(): string
{
return $this->username;
}
private function ensureIsValidUsername(string $username): void
{
if (!filter_var($username, FILTER_VALIDATE_USERNAME)) {
throw new InvalidArgumentException(
sprintf(
'"%s" is not a valid username',
$username
)
);
}
}
}