dank00/phpostcode

This package is abandoned and no longer maintained. No replacement package was suggested.
There is no license information available for the latest version (1.0) of this package.

Represent uk postcodes in PHP

1.0 2017-10-11 22:14 UTC

This package is auto-updated.

Last update: 2020-01-25 18:45:31 UTC


README

Build Status Coverage Status Scrutinizer Code Quality

A Postcode value object based on this https://www.mrs.org.uk/pdf/postcodeformat.pdf

If you want a postcode library to acutally use, I recommend this instead - https://github.com/vasildakov/postcode

Installation and Usage

The package is available on packagist.org, so use composer:

composer require dank00/phpostcode

Most applications will store postcodes as strings so you will typically use the fromString method:

$string = $address->getPostcode(); // 'CW8 4BW'

$postcode = Postcode::fromString($string);

echo $postcode->toString(); // 'CW8 4BW'
echo $postcode->getOutwardCode()->toString(); // 'CW8'
echo $postcode->getInwardCode()->getUnit(); // `BW`

If you need more precision, then OutwardCode and InwardCode also have fromString methods, or use the constructors directly.

An InvalidCodeException is thrown from the constructors of OutwardCode and InwardCode in the case that the inputs do not match the fixed patterns (which are also defined in those classes).