| Total Complexity | 6 |
| Total Lines | 87 |
| Duplicated Lines | 0 % |
| Coverage | 100% |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 9 | class PostcodeService |
||
| 10 | { |
||
| 11 | /** |
||
| 12 | * @var string |
||
| 13 | */ |
||
| 14 | protected $url; |
||
| 15 | |||
| 16 | /** |
||
| 17 | * @var Client |
||
| 18 | */ |
||
| 19 | protected $http; |
||
| 20 | |||
| 21 | /** |
||
| 22 | * Postcode Service constructor. |
||
| 23 | * |
||
| 24 | * @param Client $client |
||
| 25 | * |
||
| 26 | * @return void |
||
| 27 | */ |
||
| 28 | 27 | public function __construct(Client $client) |
|
| 29 | { |
||
| 30 | 27 | $this->url = config('services.postcodes.url'); |
|
| 31 | |||
| 32 | 27 | $this->http = $client; |
|
| 33 | 27 | } |
|
| 34 | |||
| 35 | /** |
||
| 36 | * Validate a postcode against the API |
||
| 37 | * |
||
| 38 | * @param string $postcode |
||
| 39 | * |
||
| 40 | * @return bool |
||
| 41 | */ |
||
| 42 | 9 | public function validate(string $postcode): bool |
|
| 45 | } |
||
| 46 | |||
| 47 | /** |
||
| 48 | * Get the address details from a postcode |
||
| 49 | * |
||
| 50 | * @param string $postcode |
||
| 51 | * |
||
| 52 | * @return object |
||
| 53 | */ |
||
| 54 | 3 | public function getPostcode(string $postcode): object |
|
| 57 | } |
||
| 58 | |||
| 59 | /** |
||
| 60 | * Get the address details from a random postcode |
||
| 61 | * |
||
| 62 | * @return object |
||
| 63 | */ |
||
| 64 | 3 | public function getRandomPostcode() |
|
| 67 | } |
||
| 68 | |||
| 69 | /** |
||
| 70 | * Lookup a terminated postcode. Returns the postcode, year and month of termination. |
||
| 71 | * |
||
| 72 | * @param string $postcode |
||
| 73 | * |
||
| 74 | * @return object |
||
| 75 | */ |
||
| 76 | 3 | public function getTerminatedPostcode($postcode) |
|
| 77 | { |
||
| 78 | 3 | return $this->getResponse("terminated_postcodes/$postcode"); |
|
| 79 | } |
||
| 80 | |||
| 81 | /** |
||
| 82 | * Get the response and return the result object |
||
| 83 | * |
||
| 84 | * @param string $uri |
||
| 85 | */ |
||
| 86 | 18 | protected function getResponse(string $uri = null) |
|
| 96 | } |
||
| 97 | } |
||
| 98 |