diff --git a/src/Exception/DestinationException.php b/src/Exception/DestinationException.php new file mode 100755 index 0000000..5510823 --- /dev/null +++ b/src/Exception/DestinationException.php @@ -0,0 +1,7 @@ +getStatus()), 6); break; } } diff --git a/src/Response/Address.php b/src/Response/Address.php index 6be3004..33d2925 100755 --- a/src/Response/Address.php +++ b/src/Response/Address.php @@ -2,7 +2,6 @@ namespace Valerian\GoogleDistanceMatrix\Response; - class Address { /** @@ -12,6 +11,7 @@ class Address /** * Address constructor. + * * @param $address string */ public function __construct($address) @@ -26,4 +26,4 @@ public function __toString() { return $this->address; } -} \ No newline at end of file +} diff --git a/src/Response/Distance.php b/src/Response/Distance.php index c03d445..71c316a 100755 --- a/src/Response/Distance.php +++ b/src/Response/Distance.php @@ -2,16 +2,15 @@ namespace Valerian\GoogleDistanceMatrix\Response; - class Distance { - private $text; private $value; /** * Distance constructor. + * * @param $text * @param $value */ @@ -41,4 +40,4 @@ public function getValue() { return $this->value; } -} \ No newline at end of file +} diff --git a/src/Response/Duration.php b/src/Response/Duration.php index 9031ffc..b632024 100755 --- a/src/Response/Duration.php +++ b/src/Response/Duration.php @@ -1,16 +1,16 @@ value; } -} \ No newline at end of file +} diff --git a/src/Response/Element.php b/src/Response/Element.php index d79e01e..e001cbf 100755 --- a/src/Response/Element.php +++ b/src/Response/Element.php @@ -4,17 +4,16 @@ use Valerian\GoogleDistanceMatrix\Exception\Exception; - class Element { const STATUS_OK = 'OK'; - const STATUS_NOT_FOUND = 'NOT_FOUND' ; + const STATUS_NOT_FOUND = 'NOT_FOUND'; const STATUS_ZERO_RESULTS = 'ZERO_RESULTS'; const STATUS = [ self::STATUS_OK, self::STATUS_NOT_FOUND, - self::STATUS_ZERO_RESULTS + self::STATUS_ZERO_RESULTS, ]; private $status; @@ -25,17 +24,17 @@ class Element /** * Element constructor. + * * @param $status * @param Duration $duration * @param Distance $distance */ public function __construct($status, Duration $duration, Distance $distance) { - if(!in_array($status,self::STATUS)) { - throw new Exception('Unknown status code'); + if (!in_array($status, self::STATUS)) { + throw new Exception(sprintf('Unknown status code: %s', $status)); } - $this->status = $status; $this->duration = $duration; $this->distance = $distance; @@ -64,4 +63,4 @@ public function getDistance() { return $this->distance; } -} \ No newline at end of file +} diff --git a/src/Response/GoogleDistanceMatrixResponse.php b/src/Response/GoogleDistanceMatrixResponse.php index f80df92..bdf458e 100755 --- a/src/Response/GoogleDistanceMatrixResponse.php +++ b/src/Response/GoogleDistanceMatrixResponse.php @@ -4,7 +4,6 @@ class GoogleDistanceMatrixResponse { - const RESPONSE_STATUS_OK = 'OK'; const RESPONSE_STATUS_INVALID_REQUEST = 'INVALID_REQUEST'; const RESPONSE_STATUS_MAX_ELEMENTS_EXCEEDED = 'MAX_ELEMENTS_EXCEEDED'; @@ -18,7 +17,7 @@ class GoogleDistanceMatrixResponse self::RESPONSE_STATUS_MAX_ELEMENTS_EXCEEDED, self::RESPONSE_STATUS_OVER_QUERY_LIMIT, self::RESPONSE_STATUS_REQUEST_DENIED, - self::RESPONSE_STATUS_UNKNOWN_ERROR + self::RESPONSE_STATUS_UNKNOWN_ERROR, ]; private $status; @@ -31,7 +30,7 @@ class GoogleDistanceMatrixResponse private $rows; - public function __construct(\stdClass $responseObject) + public function __construct(\stdClass $responseObject) { $this->responseObject = $responseObject; $this->originAddresses = array(); @@ -95,29 +94,26 @@ public function getRows() return $this->rows; } - private function construct() { $this->status = $this->responseObject->status; - foreach ($this->responseObject->origin_addresses as $originAddress){ + foreach ($this->responseObject->origin_addresses as $originAddress) { $this->addOriginAddress(new Address($originAddress)); } - foreach ($this->responseObject->destination_addresses as $destinationAddress){ + foreach ($this->responseObject->destination_addresses as $destinationAddress) { $this->addDestinationAddress(new Address($destinationAddress)); } - foreach ($this->responseObject->rows as $row){ - + foreach ($this->responseObject->rows as $row) { $elements = array(); - foreach($row->elements as $element){ - $duration = new Duration($element->duration->text,$element->duration->value); - $distance = new Distance($element->distance->text,$element->distance->value); - $elements[] = new Element($element->status,$duration,$distance); + foreach ($row->elements as $element) { + $duration = new Duration($element->duration->text, $element->duration->value); + $distance = new Distance($element->distance->text, $element->distance->value); + $elements[] = new Element($element->status, $duration, $distance); } $this->addRow(new Row($elements)); } - } -} \ No newline at end of file +} diff --git a/src/Response/Row.php b/src/Response/Row.php index 01a717b..636d5d6 100755 --- a/src/Response/Row.php +++ b/src/Response/Row.php @@ -3,12 +3,11 @@ * Created by PhpStorm. * User: ciro * Date: 10/07/17 - * Time: 17:19 + * Time: 17:19. */ namespace Valerian\GoogleDistanceMatrix\Response; - class Row { /** @@ -28,5 +27,4 @@ public function getElements() { return $this->elements; } - -} \ No newline at end of file +}