diff --git a/Example.php b/Example.php index 8337837..8591a0d 100644 --- a/Example.php +++ b/Example.php @@ -1,9 +1,10 @@ getAddressesByPostcode('ST16 3DP'); -var_dump($addresses); +var_dump($addresses); $postcodeAnywhere = new PostcodeAnywhere('API_KEY'); $addresses = $postcodeAnywhere->getAddressesByPostcode('ST16 3DP'); -var_dump($addresses); +var_dump($addresses); diff --git a/src/Exceptions/InvalidPostcodeException.php b/src/Exceptions/InvalidPostcodeException.php index f44d006..00cfb4b 100644 --- a/src/Exceptions/InvalidPostcodeException.php +++ b/src/Exceptions/InvalidPostcodeException.php @@ -1,6 +1,7 @@ 'IDEALPOSTCODES api_key="'.$this->apiKey.'"']; $this->client = new Client(['base_uri' => 'https://api.ideal-postcodes.co.uk/v1/', 'timeout' => 3.0, 'headers' => $headers]); - } public function getAddressesByPostcode($postcode) @@ -34,10 +33,10 @@ public function getAddressesByPostcode($postcode) return $result; } - + private function parseResponse(Response $response) { - if ($response->getStatusCode()!=200) { + if ($response->getStatusCode() != 200) { throw new Exception('HTTP response code was not 200. Received HTTP reponse code: '.$response->getStatusCode().' ('.$response->getReasonPhrase().')'); } @@ -51,7 +50,7 @@ private function parseResponse(Response $response) throw new Exception('Response code not found or invalid.'); } - if ($object->code!=2000) { + if ($object->code != 2000) { throw new Exception('Response code was not 2000. Response message: '.((isset($object->message) ? $object->message : '(none)'))); } @@ -61,8 +60,8 @@ private function parseResponse(Response $response) $addresses = []; - foreach($object->result as $idealPostcodesAddress) { - $address = new Address; + foreach ($object->result as $idealPostcodesAddress) { + $address = new Address(); $address->companyName = $idealPostcodesAddress->organisation_name; $address->line1 = $idealPostcodesAddress->line_1; $address->line2 = $idealPostcodesAddress->line_2; @@ -75,6 +74,5 @@ private function parseResponse(Response $response) } return $addresses; - } -} \ No newline at end of file +} diff --git a/src/Objects/PostcodeAnywhere.php b/src/Objects/PostcodeAnywhere.php index a3a07e2..a90a969 100644 --- a/src/Objects/PostcodeAnywhere.php +++ b/src/Objects/PostcodeAnywhere.php @@ -1,9 +1,9 @@ findSOAPClient = new SoapClient('https://services.postcodeanywhere.co.uk/PostcodeAnywhere/Interactive/Find/v1.10/wsdlnew.ws'); $this->retrieveByIDSOAPClient = new \SoapClient('https://services.postcodeanywhere.co.uk/PostcodeAnywhere/Interactive/RetrieveById/v1.30/wsdlnew.ws'); - } public function getAddressesByPostcode($postcode) @@ -31,19 +30,19 @@ public function getAddressesByPostcode($postcode) $addresses = []; - foreach($findResponseAddresses as $findResponseAddress) { + foreach ($findResponseAddresses as $findResponseAddress) { $addresses[] = $this->getAddressById($findResponseAddress->Id); } return $addresses; } - public function getFindResponseAddressesByPostcode($postcode) + public function getFindResponseAddressesByPostcode($postcode) { $findResponse = $this->findSOAPClient->PostcodeAnywhere_Interactive_Find_v1_10( [ - 'Key' => $this->apiKey, - 'SearchTerm' => $postcode + 'Key' => $this->apiKey, + 'SearchTerm' => $postcode, ] ); @@ -56,14 +55,14 @@ public function getAddressById($id) { $retrieveByIDResponse = $this->retrieveByIDSOAPClient->PostcodeAnywhere_Interactive_RetrieveById_v1_30( [ - 'Key' => $this->apiKey, - 'Id' => $id + 'Key' => $this->apiKey, + 'Id' => $id, ] ); - + $retrieveAddress = $retrieveByIDResponse->PostcodeAnywhere_Interactive_RetrieveById_v1_30_Result->PostcodeAnywhere_Interactive_RetrieveById_v1_30_Results; - $address = new Address; + $address = new Address(); $address->companyName = $retrieveAddress->Company; $address->line1 = $retrieveAddress->Line1; $address->line2 = $retrieveAddress->Line2; @@ -75,5 +74,4 @@ public function getAddressById($id) return $address; } - -} \ No newline at end of file +} diff --git a/src/Utils/Generator.php b/src/Utils/Generator.php index f6c5aa7..d6fc939 100644 --- a/src/Utils/Generator.php +++ b/src/Utils/Generator.php @@ -1,7 +1,7 @@ postcode; $validated = Validator::validatePostcode($postcode); } return $postcode; } -} \ No newline at end of file +} diff --git a/src/Utils/Tokenizer.php b/src/Utils/Tokenizer.php index 8f9685e..a2e18b2 100755 --- a/src/Utils/Tokenizer.php +++ b/src/Utils/Tokenizer.php @@ -1,38 +1,34 @@ -assertTrue(Validator::validatePostcode($postcode)); } } @@ -21,7 +21,7 @@ public function testValidationFailure() { $postcodes = ['ST163DPA', 'XF2P90', 'Ollie', 'cake']; - foreach($postcodes as $postcode) { + foreach ($postcodes as $postcode) { $this->assertFalse(Validator::validatePostcode($postcode)); } } @@ -30,11 +30,11 @@ public function testGeneration() { $postcodes = []; - for ($i=0; $i < 100; $i++) { + for ($i = 0; $i < 100; $i++) { $postcodes[] = Generator::generatePostcode(); } - foreach($postcodes as $postcode) { + foreach ($postcodes as $postcode) { $this->assertTrue(Validator::validatePostcode($postcode)); } } @@ -44,37 +44,37 @@ public function testOutwardAndInwardCodes() $postcodeTestItems = [ [ 'postcode' => 'ST163DP', - 'outward' => 'ST16', - 'inward' => '3DP' + 'outward' => 'ST16', + 'inward' => '3DP', ], [ 'postcode' => 'TN30YA', - 'outward' => 'TN3', - 'inward' => '0YA' + 'outward' => 'TN3', + 'inward' => '0YA', ], [ 'postcode' => 'ST78PP', - 'outward' => 'ST7', - 'inward' => '8PP' + 'outward' => 'ST7', + 'inward' => '8PP', ], [ 'postcode' => 'CM233WE', - 'outward' => 'CM23', - 'inward' => '3WE' + 'outward' => 'CM23', + 'inward' => '3WE', ], [ 'postcode' => 'E16AW', - 'outward' => 'E1', - 'inward' => '6AW' + 'outward' => 'E1', + 'inward' => '6AW', ], [ 'postcode' => 'E106QX', - 'outward' => 'E10', - 'inward' => '6QX' - ] + 'outward' => 'E10', + 'inward' => '6QX', + ], ]; - foreach($postcodeTestItems as $postcodeTestItem) { + foreach ($postcodeTestItems as $postcodeTestItem) { $this->assertEquals($postcodeTestItem['outward'], Tokenizer::outward($postcodeTestItem['postcode'])); $this->assertEquals($postcodeTestItem['inward'], Tokenizer::inward($postcodeTestItem['postcode'])); }