/** * @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); }