*/ final class Country { /** * @var string|null */ private $name; /** * @var string|null */ private $code; /** * @param string $name * @param string $code */ public function __construct(string $name = null, string $code = null) { if (null === $name && null === $code) { throw new InvalidArgument('A country must have either a name or a code'); } $this->name = $name; $this->code = $code; } /** * Returns the country name. * * @return string|null */ public function getName() { return $this->name; } /** * Returns the country ISO code. * * @return string|null */ public function getCode() { return $this->code; } /** * Returns a string with the country name. * * @return string */ public function __toString(): string { return $this->getName() ?: ''; } }