Skip to content

Commit

Permalink
Apply fixes from StyleCI
Browse files Browse the repository at this point in the history
  • Loading branch information
madeITBelgium authored and StyleCIBot committed Nov 30, 2018
1 parent 09987bd commit 7ff2d15
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 24 deletions.
45 changes: 23 additions & 22 deletions src/Geocode.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace MadeITBelgium\Geocode;

use Carbon\Carbon;
use Exception;
use GuzzleHttp\Client;
use GuzzleHttp\Exception\ClientException;
Expand All @@ -20,7 +19,7 @@
class Geocode
{
protected $version = '1.0.0';
private $type = "geocode.xyz";
private $type = 'geocode.xyz';
private $key = null;

private $client;
Expand All @@ -32,7 +31,7 @@ class Geocode
* @param $clientSecret;
* @param $client
*/
public function __construct($type = "geocode.xyz", $key = null, $client = null)
public function __construct($type = 'geocode.xyz', $key = null, $client = null)
{
$this->setType($type);

Expand Down Expand Up @@ -67,9 +66,10 @@ public function getClient()

public function setType($type)
{
if(in_array($type, ['geocode.xyz', 'google'])) {
if (in_array($type, ['geocode.xyz', 'google'])) {
$this->type = $type;
}

throw new \Exception('Wrong GEO Data type. Take one of: geocode.xyz, google');
}

Expand Down Expand Up @@ -110,7 +110,7 @@ public function getCall($endPoint)

public function lookup($address)
{
if($this->type === "geocode.xyz") {
if ($this->type === 'geocode.xyz') {
return $this->lookupGeocodeXYZ($address);
}

Expand All @@ -119,42 +119,43 @@ public function lookup($address)

private function lookupGeocodeXYZ($address)
{
$url = "https://geocode.xyz/" . urlencode($address) . "?json=1";
if($this->key !== null) {
$url .= "&key=" . $this->key;
$url = 'https://geocode.xyz/'.urlencode($address).'?json=1';
if ($this->key !== null) {
$url .= '&key='.$this->key;
}

$result = $this->getCall($url);
$respons = json_decode($result, true);
if(isset($respons["longt"])) {
if (isset($respons['longt'])) {
return [
$respons["latt"],
$respons["longt"]
$respons['latt'],
$respons['longt'],
];
}

return false;
}

private function lookupGoogle($address)
{
$url = "https://maps.googleapis.com/maps/api/geocode/json?sensor=false&address=";
$url = 'https://maps.googleapis.com/maps/api/geocode/json?sensor=false&address=';
$url .= urlencode($address);
if($this->key !== null) {
$url .= "&key=" . $this->key;
if ($this->key !== null) {
$url .= '&key='.$this->key;
}

$result = $this->getCall($url);
$respons = json_decode($result, true);
if(isset($respons["results"][0])) {
$results = $respons["results"][0];
if(isset($results["geometry"]["location"]["lat"])) {
if (isset($respons['results'][0])) {
$results = $respons['results'][0];
if (isset($results['geometry']['location']['lat'])) {
return [
$results["geometry"]["location"]["lat"],
$results["geometry"]["location"]["lng"]
$results['geometry']['location']['lat'],
$results['geometry']['location']['lng'],
];
}
}

return false;
}
}
}
4 changes: 2 additions & 2 deletions src/config/geocode.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php

return [
'type' => env('GOEDATA_TYPE', 'geocode.xyz'),
'key' => env('GEODATA_KEY', null),
'type' => env('GOEDATA_TYPE', 'geocode.xyz'),
'key' => env('GEODATA_KEY', null),
'client' => null,
];

0 comments on commit 7ff2d15

Please sign in to comment.