Skip to content

Commit 41474a7

Browse files
authored
Devices updated database (#226)
* Devices updated database - updated devices.json - dynamic Android API level selection
1 parent 70e4d92 commit 41474a7

File tree

5 files changed

+4461
-160
lines changed

5 files changed

+4461
-160
lines changed

src/Registration/AccountInfo.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ public function getDevice(): string
124124

125125
public function getAndroidSdkVersion(): string
126126
{
127-
return $this->androidSdkVersion;
127+
return DeviceResource::getUpdatedSdkVersion($this->androidSdkVersion);
128128
}
129129

130130
public function getFirstName(): string

src/Registration/DeviceGenerator/DeviceResource.php

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,6 @@ class DeviceResource
1616
* @var string
1717
*/
1818
private $model;
19-
/**
20-
* @var int
21-
*/
22-
private $sdkVersion;
2319
/** @var array */
2420
private static $devices = [];
2521

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

3430
$this->brand = $randomDevice['brand'];
3531
$this->model = $randomDevice['model'];
36-
37-
$sdks = $randomDevice['sdks'];
38-
$this->sdkVersion = $sdks[array_rand($sdks)];
3932
}
4033

4134
public function getDeviceString(): string
@@ -45,6 +38,26 @@ public function getDeviceString(): string
4538

4639
public function getSdkString(): string
4740
{
48-
return 'SDK '.$this->sdkVersion;
41+
return 'SDK '.rand(self::getMinSdkVersion(), self::getMaxSdkVersion());
42+
}
43+
44+
public static function getUpdatedSdkVersion($currentSdkString): string
45+
{
46+
$intVersion = strstr($currentSdkString, 'SDK') ?
47+
(int) explode(' ', $currentSdkString)[1] : (int) $currentSdkString;
48+
$newVersion = $intVersion < self::getMinSdkVersion() ?
49+
self::getMinSdkVersion() + ($intVersion % (self::getMaxSdkVersion() - self::getMinSdkVersion() + 1)) : $intVersion;
50+
51+
return 'SDK '.$newVersion;
52+
}
53+
54+
public static function getMinSdkVersion(): int
55+
{
56+
return 26;
57+
}
58+
59+
public static function getMaxSdkVersion(): int
60+
{
61+
return 30;
4962
}
5063
}

0 commit comments

Comments
 (0)