| 1 | <?php |
||
| 8 | class PostalAccount |
||
| 9 | { |
||
| 10 | const PATTERN = '/^[0-9]{2}-[1-9][0-9]{0,5}-[0-9]$/'; |
||
| 11 | |||
| 12 | /** |
||
| 13 | * @var int |
||
| 14 | */ |
||
| 15 | protected $prefix; |
||
| 16 | |||
| 17 | /** |
||
| 18 | * @var int |
||
| 19 | */ |
||
| 20 | protected $number; |
||
| 21 | |||
| 22 | /** |
||
| 23 | * @var int |
||
| 24 | */ |
||
| 25 | protected $checkDigit; |
||
| 26 | |||
| 27 | /** |
||
| 28 | * Constructor |
||
| 29 | * |
||
| 30 | * @param string $postalAccount |
||
| 31 | * |
||
| 32 | * @throws \InvalidArgumentException When the account number is not valid (check digit is not being tested). |
||
| 33 | */ |
||
| 34 | 8 | public function __construct($postalAccount) |
|
| 49 | |||
| 50 | /** |
||
| 51 | * Format the postal account number |
||
| 52 | * |
||
| 53 | * @return string The formatted account number |
||
| 54 | */ |
||
| 55 | 6 | public function format() |
|
| 59 | |||
| 60 | /** |
||
| 61 | * Checks whether a given prefix is valid |
||
| 62 | * |
||
| 63 | * @param int $prefix The prefix to be checked |
||
| 64 | * |
||
| 65 | * @return bool True if the prefix is valid |
||
| 66 | */ |
||
| 67 | 2 | private static function checkPrefix($prefix) |
|
| 78 | } |
||
| 79 |