Skip to content

Commit

Permalink
added a tokenizer for outward and inward splitting of postcode
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrew Mcdonald committed May 10, 2017
1 parent 5ce1dac commit be255b9
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions src/Utils/Tokenizer.php
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");
}

}

0 comments on commit be255b9

Please sign in to comment.