Skip to content

ParseResult

Gatepost\Postcode\ParseResult

The result of Postcode::parse(): a postcode, or the reason that the input is not one. Exactly one of value and error is set.

$result = Postcode::parse($input);
if ($result->isOk()) {
echo $result->value->canonical;
} else {
echo $result->error->code->value;
}
  • ?Postcode $value: The postcode, or null when the parse failed.
  • ?ParseError $error: Why the parse failed, or null when it succeeded.
public function isOk(): bool

Tells whether the parse found a postcode. Static analysers such as PHPStan then know which of value and error is set.

Unofficial. Not made or endorsed by NIPOST.