-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added a tokenizer for outward and inward splitting of postcode
- Loading branch information
Andrew Mcdonald
committed
May 10, 2017
1 parent
5ce1dac
commit be255b9
Showing
1 changed file
with
34 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?php | ||
namespace RapidWeb\Postcodes\Utils; | ||
|
||
use RapidWeb\Postcodes\Utils\Validator; | ||
use Exception; | ||
|
||
abstract class Tokenizer | ||
{ | ||
public static function outward($postcode) | ||
{ | ||
self::sanityCheck($postcode); | ||
|
||
$postcodeStart = trim(substr($postcode, 0, -3)); | ||
|
||
return $postcodeStart; | ||
} | ||
|
||
public static function inward($postcode) | ||
{ | ||
self::sanityCheck($postcode); | ||
|
||
$postcodeEnd = trim(substr($postcode, -3,3)); | ||
|
||
return $postcodeEnd; | ||
} | ||
|
||
private function sanityCheck($postcode) | ||
{ | ||
$validated = Validator::validatePostcode($postcode); | ||
|
||
throw new Exception("Post code provided is not valid"); | ||
} | ||
|
||
} |