Skip to content

Commit

Permalink
Refactored like suggested; removed BC break
Browse files Browse the repository at this point in the history
  • Loading branch information
tholu committed Aug 6, 2014
1 parent aa36b57 commit a2b27f5
Showing 1 changed file with 9 additions and 16 deletions.
25 changes: 9 additions & 16 deletions SEOstats/Services/Sistrix.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,7 @@ public static function getVisibilityIndex($url = false)
$html = parent::_getPage($dataUrl);
@preg_match_all('#<h3>(.*?)<\/h3>#si', $html, $matches);

if(isset($matches[1][0])) {
$vi = str_replace(',','.',$matches[1][0]);
return $vi;
} else {
return parent::noDataDefaultValue();
}
return isset($matches[1][0]) ? $matches[1][0] : parent::noDataDefaultValue();
}

/**
Expand All @@ -70,8 +65,6 @@ public static function getVisibilityIndexByApi($url = false, $db = false)
self::guardApiKey();
self::guardApiCredits();

$db = ($db == false) ? Config\DefaultSettings::SISTRIX_DB : $db;

$url = parent::getUrl($url);
$domain = static::getDomainFromUrl($url);
$database = static::getValidDatabase($db);
Expand All @@ -80,12 +73,11 @@ public static function getVisibilityIndexByApi($url = false, $db = false)

$json = parent::_getPage($dataUrl);

if(!empty($json)) {
$json_decoded = (Helper\Json::decode($json, true));
return $json_decoded['answer'][0]['sichtbarkeitsindex'][0]['value'];
} else {
if(empty($json)) {
return parent::noDataDefaultValue();
}
$json_decoded = (Helper\Json::decode($json, true));
return $json_decoded['answer'][0]['sichtbarkeitsindex'][0]['value'];
}

public static function getApiCredits() {
Expand All @@ -95,12 +87,11 @@ public static function getApiCredits() {

$json = parent::_getPage($dataUrl);

if(!empty($json)) {
$json_decoded = (Helper\Json::decode($json, true));
return $json_decoded['answer'][0]['credits'][0]['value'];
} else {
if(empty($json)) {
return parent::noDataDefaultValue();
}
$json_decoded = (Helper\Json::decode($json, true));
return $json_decoded['answer'][0]['credits'][0]['value'];
}

private static function checkApiCredits() {
Expand Down Expand Up @@ -136,6 +127,8 @@ protected static function getDomainFromUrl($url)

protected static function getValidDatabase($db)
{
$db = ($db == false) ? Config\DefaultSettings::SISTRIX_DB : $db;

$database = self::checkDatabase($db);
static::guardDatabaseIsValid($database);

Expand Down

0 comments on commit a2b27f5

Please sign in to comment.