/** * @param \StdClass $coordinatesObject * @return Coordinates */ public function parse($coordinatesObject) { $coordinates = new Coordinates(); if ($this->jsonCoordinatesValidator->validate($coordinatesObject)) { $coordinates->setLatitude($coordinatesObject->lat); $coordinates->setLongitude($coordinatesObject->long); } return $coordinates; }
/** * @param \StdClass $locationObject * @throws IncorrectLocationFormatException * @return Location */ public function parse($locationObject) { $location = new Location(); if ($this->jsonLocationValidator->validate($locationObject)) { $location->setName($locationObject->name); $coordinates = $this->coordinatesParser->parse($locationObject->coordinates); $location->setCoordinates($coordinates); } return $location; }
/** * @param string $jsonString * @return SampleObject * @throws InvalidJsonResponseException * @throws MalformedJsonResponseException * @throws UnsuccessfulJsonResponseException */ public function parse($jsonString) { if ($jsonArray = json_decode($jsonString)) { if ($this->jsonResponseValidator->validate($jsonArray)) { $sampleObject = new SampleObject(); foreach ($jsonArray->data->locations as $jsonLocation) { $location = $this->locationParser->parse($jsonLocation); $sampleObject->addLocation($location); } return $sampleObject; } } throw new InvalidJsonResponseException(json_last_error(), $jsonString); }