23 lines
637 B
PHP
23 lines
637 B
PHP
<?php
|
|
|
|
namespace App\Domain\Location\Model;
|
|
|
|
use InvalidArgumentException;
|
|
|
|
class City
|
|
{
|
|
public function __construct(
|
|
public readonly string $name,
|
|
public readonly Country $country,
|
|
public readonly ?ZipCode $zipCode = null,
|
|
) {
|
|
if (strlen($name) >= 100) {
|
|
throw new InvalidArgumentException('City name cannot be longer than 100 characters');
|
|
}
|
|
}
|
|
|
|
public static function create(string $name, string $countryAlpha2, ?string $zipCode = null): self
|
|
{
|
|
return new self($name, new Country($countryAlpha2), $zipCode !== null ? new ZipCode($zipCode) : null);
|
|
}
|
|
} |