Skip to content

Commit

Permalink
Devices updated database (#226)
Browse files Browse the repository at this point in the history
* Devices updated database

- updated devices.json
- dynamic Android API level selection
  • Loading branch information
Ririconj authored Jul 28, 2021
1 parent 70e4d92 commit 41474a7
Show file tree
Hide file tree
Showing 5 changed files with 4,461 additions and 160 deletions.
2 changes: 1 addition & 1 deletion src/Registration/AccountInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ public function getDevice(): string

public function getAndroidSdkVersion(): string
{
return $this->androidSdkVersion;
return DeviceResource::getUpdatedSdkVersion($this->androidSdkVersion);
}

public function getFirstName(): string
Expand Down
29 changes: 21 additions & 8 deletions src/Registration/DeviceGenerator/DeviceResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,6 @@ class DeviceResource
* @var string
*/
private $model;
/**
* @var int
*/
private $sdkVersion;
/** @var array */
private static $devices = [];

Expand All @@ -33,9 +29,6 @@ public function __construct()

$this->brand = $randomDevice['brand'];
$this->model = $randomDevice['model'];

$sdks = $randomDevice['sdks'];
$this->sdkVersion = $sdks[array_rand($sdks)];
}

public function getDeviceString(): string
Expand All @@ -45,6 +38,26 @@ public function getDeviceString(): string

public function getSdkString(): string
{
return 'SDK '.$this->sdkVersion;
return 'SDK '.rand(self::getMinSdkVersion(), self::getMaxSdkVersion());
}

public static function getUpdatedSdkVersion($currentSdkString): string
{
$intVersion = strstr($currentSdkString, 'SDK') ?
(int) explode(' ', $currentSdkString)[1] : (int) $currentSdkString;
$newVersion = $intVersion < self::getMinSdkVersion() ?
self::getMinSdkVersion() + ($intVersion % (self::getMaxSdkVersion() - self::getMinSdkVersion() + 1)) : $intVersion;

return 'SDK '.$newVersion;
}

public static function getMinSdkVersion(): int
{
return 26;
}

public static function getMaxSdkVersion(): int
{
return 30;
}
}
Loading

0 comments on commit 41474a7

Please sign in to comment.