Skip to content

Commit

Permalink
CS Fixed all file
Browse files Browse the repository at this point in the history
  • Loading branch information
stevebauman committed May 8, 2015
1 parent ab9d52d commit 025c606
Show file tree
Hide file tree
Showing 15 changed files with 233 additions and 183 deletions.
3 changes: 2 additions & 1 deletion src/Stevebauman/Location/Drivers/DriverInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ interface DriverInterface
* using the current driver.
*
* @param string $ip
*
* @return \Stevebauman\Location\Objects\Location
*/
public function get($ip);
}
}
60 changes: 39 additions & 21 deletions src/Stevebauman/Location/Drivers/FreeGeoIp.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,21 @@
use Stevebauman\Location\Location as LocationInstance;

/**
* The FreeGeoIp driver
* The FreeGeoIp driver.
*
* Class FreeGeoIp
* @package Stevebauman\Location\Drivers
*/
class FreeGeoIp implements DriverInterface
{

/**
* Holds the current Location class instance
* Holds the current Location class instance.
*
* @var LocationInstance
*/
private $instance;

/**
* Holds the configuration instance
* Holds the configuration instance.
*
* @var \Illuminate\Config\Repository
*/
Expand All @@ -42,50 +40,70 @@ public function __construct(LocationInstance $instance)

$this->config = $this->instance->getConfig();

$this->url = $this->config->get('location' . $this->instance->getConfigSeparator() . 'drivers.FreeGeoIp.url');
$this->url = $this->config->get('location'.$this->instance->getConfigSeparator().'drivers.FreeGeoIp.url');
}

/**
* Retrieves the location from the driver FreeGeoIp and returns a location object
* Retrieves the location from the driver FreeGeoIp and returns a location object.
*
* @param string $ip
*
* @return Location
*/
public function get($ip)
{
$location = new Location;
$location = new Location();

try {
$contents = json_decode(file_get_contents($this->url . $ip), true);
$contents = json_decode(file_get_contents($this->url.$ip), true);

$location->ip = $ip;

if (array_key_exists('country_code', $contents)) $location->countryCode = $contents['country_code'];
if (array_key_exists('country_code', $contents)) {
$location->countryCode = $contents['country_code'];
}

if (array_key_exists('country_name', $contents)) $location->countryName = $contents['country_name'];
if (array_key_exists('country_name', $contents)) {
$location->countryName = $contents['country_name'];
}

if (array_key_exists('region_code', $contents)) $location->regionCode = $contents['region_code'];
if (array_key_exists('region_code', $contents)) {
$location->regionCode = $contents['region_code'];
}

if (array_key_exists('region_name', $contents)) $location->regionName = $contents['region_name'];
if (array_key_exists('region_name', $contents)) {
$location->regionName = $contents['region_name'];
}

if (array_key_exists('city', $contents)) $location->cityName = $contents['city'];
if (array_key_exists('city', $contents)) {
$location->cityName = $contents['city'];
}

if (array_key_exists('zip_code', $contents)) $location->zipCode = $contents['zip_code'];
if (array_key_exists('zip_code', $contents)) {
$location->zipCode = $contents['zip_code'];
}

if (array_key_exists('latitude', $contents)) $location->latitude = $contents['latitude'];
if (array_key_exists('latitude', $contents)) {
$location->latitude = $contents['latitude'];
}

if (array_key_exists('longitude', $contents)) $location->longitude = $contents['longitude'];
if (array_key_exists('longitude', $contents)) {
$location->longitude = $contents['longitude'];
}

if (array_key_exists('metro_code', $contents)) $location->metroCode = $contents['metro_code'];
if (array_key_exists('metro_code', $contents)) {
$location->metroCode = $contents['metro_code'];
}

if (array_key_exists('area_code', $contents)) $location->areaCode = $contents['area_code'];
if (array_key_exists('area_code', $contents)) {
$location->areaCode = $contents['area_code'];
}

$location->driver = get_class($this);

} catch (\Exception $e) {
$location->error = true;
}

return $location;
}
}
}
55 changes: 36 additions & 19 deletions src/Stevebauman/Location/Drivers/GeoPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,21 @@
use Stevebauman\Location\Location as LocationInstance;

/**
* The GeoPlugin driver
* The GeoPlugin driver.
*
* Class GeoPlugin
* @package Stevebauman\Location\Drivers
*/
class GeoPlugin implements DriverInterface
{
/**
* Holds the current Location class instance
* Holds the current Location class instance.
*
* @var LocationInstance
*/
private $instance;

/**
* Holds the configuration instance
* Holds the configuration instance.
*
* @var \Illuminate\Config\Repository
*/
Expand All @@ -41,48 +40,66 @@ public function __construct(LocationInstance $instance)

$this->config = $this->instance->getConfig();

$this->url = $this->config->get('location' . $this->instance->getConfigSeparator() . 'drivers.GeoPlugin.url');
$this->url = $this->config->get('location'.$this->instance->getConfigSeparator().'drivers.GeoPlugin.url');
}

/**
* Retrieves the location from the driver GeoPlugin and returns a location object
* Retrieves the location from the driver GeoPlugin and returns a location object.
*
* @param string $ip
*
* @return Location
*/
public function get($ip)
{
$location = new Location;
$location = new Location();

try {
$contents = unserialize(file_get_contents($this->url . $ip));
$contents = unserialize(file_get_contents($this->url.$ip));

$location->ip = $ip;

if (array_key_exists('geoplugin_countryCode', $contents)) $location->countryCode = $contents['geoplugin_countryCode'];
if (array_key_exists('geoplugin_countryCode', $contents)) {
$location->countryCode = $contents['geoplugin_countryCode'];
}

if (array_key_exists('geoplugin_countryName', $contents)) $location->countryName = $contents['geoplugin_countryName'];
if (array_key_exists('geoplugin_countryName', $contents)) {
$location->countryName = $contents['geoplugin_countryName'];
}

if (array_key_exists('geoplugin_regionName', $contents)) $location->regionName = $contents['geoplugin_regionName'];
if (array_key_exists('geoplugin_regionName', $contents)) {
$location->regionName = $contents['geoplugin_regionName'];
}

if (array_key_exists('geoplugin_city', $contents)) $location->regionName = $contents['geoplugin_city'];
if (array_key_exists('geoplugin_city', $contents)) {
$location->regionName = $contents['geoplugin_city'];
}

if (array_key_exists('geoplugin_longitude', $contents)) $location->longitude = $contents['geoplugin_longitude'];
if (array_key_exists('geoplugin_longitude', $contents)) {
$location->longitude = $contents['geoplugin_longitude'];
}

if (array_key_exists('geoplugin_latitude', $contents)) $location->latitude = $contents['geoplugin_latitude'];
if (array_key_exists('geoplugin_latitude', $contents)) {
$location->latitude = $contents['geoplugin_latitude'];
}

if (array_key_exists('geoplugin_areaCode', $contents)) $location->areaCode = $contents['geoplugin_areaCode'];
if (array_key_exists('geoplugin_areaCode', $contents)) {
$location->areaCode = $contents['geoplugin_areaCode'];
}

if (array_key_exists('geoplugin_regionCode', $contents)) $location->regionCode = $contents['geoplugin_regionCode'];
if (array_key_exists('geoplugin_regionCode', $contents)) {
$location->regionCode = $contents['geoplugin_regionCode'];
}

if (array_key_exists('geoplugin_regionName', $contents)) $location->regionName = $contents['geoplugin_regionName'];
if (array_key_exists('geoplugin_regionName', $contents)) {
$location->regionName = $contents['geoplugin_regionName'];
}

$location->driver = get_class($this);

} catch (\Exception $e) {
$location->error = true;
}

return $location;
}
}
}
46 changes: 28 additions & 18 deletions src/Stevebauman/Location/Drivers/IpInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,21 @@
use Stevebauman\Location\Location as LocationInstance;

/**
* The IpInfo driver
* The IpInfo driver.
*
* Class IpInfo
* @package Stevebauman\Location\Drivers
*/
class IpInfo implements DriverInterface
{
/**
* Holds the current Location class instance
* Holds the current Location class instance.
*
* @var LocationInstance
*/
private $instance;

/**
* Holds the configuration instance
* Holds the configuration instance.
*
* @var \Illuminate\Config\Repository
*/
Expand All @@ -41,41 +40,54 @@ public function __construct(LocationInstance $instance)

$this->config = $this->instance->getConfig();

$this->url = $this->config->get('location' . $this->instance->getConfigSeparator() . 'drivers.IpInfo.url');
$this->url = $this->config->get('location'.$this->instance->getConfigSeparator().'drivers.IpInfo.url');
}

/**
* Retrieves the location from the driver IpInfo and returns a location object
* Retrieves the location from the driver IpInfo and returns a location object.
*
* @param string $ip
*
* @return Location
*/
public function get($ip)
{
$location = new Location;
$location = new Location();

try {
$contents = json_decode(file_get_contents($this->url . $ip));
$contents = json_decode(file_get_contents($this->url.$ip));

$location->ip = $ip;

if (property_exists($contents, 'country')) $location->countryCode = $contents->country;
if (property_exists($contents, 'country')) {
$location->countryCode = $contents->country;
}

if (property_exists($contents, 'postal')) $location->postalCode = $contents->postal;
if (property_exists($contents, 'postal')) {
$location->postalCode = $contents->postal;
}

if (property_exists($contents, 'region')) $location->regionName = $contents->region;
if (property_exists($contents, 'region')) {
$location->regionName = $contents->region;
}

if (property_exists($contents, 'city')) $location->cityName = $contents->city;
if (property_exists($contents, 'city')) {
$location->cityName = $contents->city;
}

if (property_exists($contents, 'loc')) {
$coords = explode(',', $contents->loc);

if (array_key_exists(0, $coords)) $location->latitude = $coords[0];
if (array_key_exists(0, $coords)) {
$location->latitude = $coords[0];
}

if (array_key_exists(1, $coords)) $location->longitude = $coords[1];
if (array_key_exists(1, $coords)) {
$location->longitude = $coords[1];
}
}

$countries = $this->config->get('location' . $this->instance->getConfigSeparator() . 'country_codes');
$countries = $this->config->get('location'.$this->instance->getConfigSeparator().'country_codes');

/*
* See if we can convert the country code to the country name
Expand All @@ -85,12 +97,10 @@ public function get($ip)
}

$location->driver = get_class($this);

} catch (\Exception $e) {
$location->error = true;
}

return $location;
}

}
}
Loading

0 comments on commit 025c606

Please sign in to comment.