Geocoder\Provider\TomTom::executeQuery PHP Method

executeQuery() private method

private executeQuery ( string $query )
$query string
    private function executeQuery($query)
    {
        if (null !== $this->getLocale()) {
            // Supported 2- character values are de, en, es, fr, it, nl, pl, pt, and sv.
            // Equivalent 3-character values are GER, ENG, SPA, FRE, ITA, DUT, POL, POR, and SWE.
            $query = sprintf('%s&language=%s', $query, substr($this->getLocale(), 0, 2));
        }
        $request = $this->getMessageFactory()->createRequest('GET', $query);
        $content = (string) $this->getHttpClient()->sendRequest($request)->getBody();
        if (false !== stripos($content, "Developer Inactive")) {
            throw new InvalidCredentials('Map API Key provided is not valid.');
        }
        try {
            $xml = new \SimpleXmlElement($content);
        } catch (\Exception $e) {
            throw new NoResult(sprintf('Could not execute query "%s".', $query));
        }
        $attributes = $xml->attributes();
        if (isset($attributes['count']) && 0 === (int) $attributes['count']) {
            throw new NoResult(sprintf('Could not execute query "%s".', $query));
        }
        if (isset($attributes['errorCode'])) {
            if ('403' === (string) $attributes['errorCode']) {
                throw new InvalidCredentials('Map API Key provided is not valid.');
            }
            throw new NoResult(sprintf('Could not execute query "%s".', $query));
        }
        $data = isset($xml->geoResult) ? $xml->geoResult : $xml->reverseGeoResult;
        if (0 === count($data)) {
            return $this->returnResults([$this->getResultArray($data)]);
        }
        $results = [];
        foreach ($data as $item) {
            $results[] = $this->getResultArray($item);
        }
        return $this->returnResults($results);
    }