forked from rapidwebltd/php-postcodes
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
90 additions
and
92 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
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 |
---|---|---|
@@ -1,6 +1,7 @@ | ||
<?php | ||
|
||
namespace RapidWeb\Postcodes\Exceptions; | ||
|
||
class InvalidPostcodeException extends \Exception | ||
{ | ||
} | ||
} |
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 |
---|---|---|
@@ -1,8 +1,10 @@ | ||
<?php | ||
|
||
namespace RapidWeb\Postcodes\Interfaces; | ||
|
||
interface PostcodeServiceInterface | ||
{ | ||
public function __construct($apiKey); | ||
|
||
public function getAddressesByPostcode($postcode); | ||
} | ||
} |
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
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
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
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
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 |
---|---|---|
@@ -1,38 +1,34 @@ | ||
<?php | ||
namespace RapidWeb\Postcodes\Utils; | ||
|
||
use RapidWeb\Postcodes\Utils\Validator; | ||
use Exception; | ||
use RapidWeb\Postcodes\Exceptions\InvalidPostcodeException; | ||
|
||
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 static function sanityCheck($postcode) | ||
{ | ||
$validated = Validator::validatePostcode($postcode); | ||
if(!$validated) | ||
{ | ||
throw new InvalidPostcodeException("Post code provided is not valid"); | ||
} | ||
|
||
} | ||
|
||
} | ||
<?php | ||
|
||
namespace RapidWeb\Postcodes\Utils; | ||
|
||
use RapidWeb\Postcodes\Exceptions\InvalidPostcodeException; | ||
|
||
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 static function sanityCheck($postcode) | ||
{ | ||
$validated = Validator::validatePostcode($postcode); | ||
if (!$validated) { | ||
throw new InvalidPostcodeException('Post code provided is not valid'); | ||
} | ||
} | ||
} |
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
Oops, something went wrong.