Skip to content

Commit

Permalink
Merge pull request #18 from mpociot/analysis-XVr5PK
Browse files Browse the repository at this point in the history
Applied fixes from StyleCI
  • Loading branch information
mpociot committed Apr 7, 2016
2 parents 4ec448a + 2e8a9e5 commit 3d5bef2
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 13 deletions.
20 changes: 11 additions & 9 deletions src/Mpociot/VatCalculator/VatCalculator.php
Expand Up @@ -127,10 +127,10 @@ public function __construct($config = null)
*/
private function getClientIP()
{
if (isset($_SERVER[ 'HTTP_X_FORWARDED_FOR' ]) && $_SERVER[ 'HTTP_X_FORWARDED_FOR' ]) {
$clientIpAddress = $_SERVER[ 'HTTP_X_FORWARDED_FOR' ];
} elseif (isset($_SERVER[ 'REMOTE_ADDR' ]) && $_SERVER[ 'REMOTE_ADDR' ]) {
$clientIpAddress = $_SERVER[ 'REMOTE_ADDR' ];
if (isset($_SERVER['HTTP_X_FORWARDED_FOR']) && $_SERVER['HTTP_X_FORWARDED_FOR']) {
$clientIpAddress = $_SERVER['HTTP_X_FORWARDED_FOR'];
} elseif (isset($_SERVER['REMOTE_ADDR']) && $_SERVER['REMOTE_ADDR']) {
$clientIpAddress = $_SERVER['REMOTE_ADDR'];
} else {
$clientIpAddress = '';
}
Expand All @@ -150,27 +150,29 @@ public function getIPBasedCountry()
$ip = $this->getClientIP();
$url = self::GEOCODE_SERVICE_URL.$ip;
$result = file_get_contents($url);
switch ($result[ 0 ]) {
switch ($result[0]) {
case '1':
$data = explode(';', $result);

return $data[ 1 ];
return $data[1];
break;
default:
return false;
}
}

/**
* Determines if you need to collect VAT for the given country code
* Determines if you need to collect VAT for the given country code.
*
* @param $countryCode
*
* @return bool
*/
public function shouldCollectVAT($countryCode)
{
$taxKey = 'vat_calculator.rules.'.strtoupper($countryCode);
return (isset($this->taxRules[ strtoupper($countryCode) ]) || (isset($this->config) && $this->config->has($taxKey)));

return isset($this->taxRules[strtoupper($countryCode)]) || (isset($this->config) && $this->config->has($taxKey));
}

/**
Expand Down Expand Up @@ -273,7 +275,7 @@ public function getTaxRateForCountry($countryCode, $company = false)
return $this->config->get($taxKey, 0);
}

return isset($this->taxRules[ strtoupper($countryCode) ]) ? $this->taxRules[ strtoupper($countryCode) ] : 0;
return isset($this->taxRules[strtoupper($countryCode)]) ? $this->taxRules[strtoupper($countryCode)] : 0;
}

/**
Expand Down
5 changes: 1 addition & 4 deletions tests/VatCalculatorTest.php
Expand Up @@ -400,7 +400,7 @@ public function testCanResolveInvalidIPToCountry()
public function testCanHandleIPServiceDowntime()
{
self::$file_get_contents_result = false;
$_SERVER[ 'REMOTE_ADDR' ] = '';
$_SERVER['REMOTE_ADDR'] = '';
$vatCalculator = new VatCalculator();
$country = $vatCalculator->getIPBasedCountry();
$this->assertFalse($country);
Expand Down Expand Up @@ -465,7 +465,6 @@ public function testCompanyOutsideBusinessCountryGetsValidVATRate()

public function testShouldCollectVAT()
{

$vatCalculator = new VatCalculator();
$this->assertTrue($vatCalculator->shouldCollectVAT('DE'));
$this->assertTrue($vatCalculator->shouldCollectVAT('NL'));
Expand All @@ -492,6 +491,4 @@ public function testShouldCollectVATFromConfig()
$vatCalculator = new VatCalculator($config);
$this->assertTrue($vatCalculator->shouldCollectVAT($countryCode));
}


}

0 comments on commit 3d5bef2

Please sign in to comment.