Skip to content

Commit

Permalink
Optimise BuildIds and BrowserIds
Browse files Browse the repository at this point in the history
  • Loading branch information
NielsLeenheer committed Dec 7, 2015
1 parent f8d2490 commit 79c0625
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 21 deletions.
2 changes: 1 addition & 1 deletion src/Analyser/Header/Useragent/Os.php
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,7 @@ private function determineAndroidVersionBasedOnBuild($ua)
{
if ((isset($this->data->os->name) && $this->data->os->name == 'Android') || isset($this->data->os->name) && $this->data->os->name == 'Android TV') {
if (preg_match('/Build\/([^\);]+)/u', $ua, $match)) {
$version = Data\BuildIds::identify('android', $match[1]);
$version = Data\BuildIds::identify($match[1]);

if ($version) {
if (!isset($this->data->os->version) || $this->data->os->version == null || $this->data->os->version->value == null || $version->toFloat() < $this->data->os->version->toFloat()) {
Expand Down
2 changes: 0 additions & 2 deletions src/Data/BrowserIds.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,5 @@ public static function identify($model)
if (isset(BrowserIds::$ANDROID_BROWSERS[$model])) {
return BrowserIds::$ANDROID_BROWSERS[$model];
}

return false;
}
}
24 changes: 6 additions & 18 deletions src/Data/BuildIds.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,28 +8,16 @@ class BuildIds
{
public static $ANDROID_BUILDS = [];

public static function identify($type, $id)
public static function identify($id)
{
require_once __DIR__ . '/../../data/build-' . $type . '.php';
require_once __DIR__ . '/../../data/build-android.php';

switch ($type) {
case 'android':
return self::identifyList(BuildIds::$ANDROID_BUILDS, $id);
}

return false;
}

public static function identifyList($list, $id)
{
if (isset($list[$id])) {
if (is_array($list[$id])) {
return new Version($list[$id]);
if (isset(BuildIds::$ANDROID_BUILDS[$id])) {
if (is_array(BuildIds::$ANDROID_BUILDS[$id])) {
return new Version(BuildIds::$ANDROID_BUILDS[$id]);
} else {
return new Version([ 'value' => $list[$id] ]);
return new Version([ 'value' => BuildIds::$ANDROID_BUILDS[$id] ]);
}
}

return false;
}
}

0 comments on commit 79c0625

Please sign in to comment.