Skip to content

Commit 6fd2d73

Browse files
standardize values for native_minecraft_version and supported_minecraft_versions; fixes #53
1 parent 4c3a34e commit 6fd2d73

File tree

1 file changed

+22
-8
lines changed

1 file changed

+22
-8
lines changed

src/object/Resource.php

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,19 +24,29 @@ public function __construct($resource) {
2424

2525
for ($idx = 0; $idx < count($resource['fields']); $idx++) {
2626
$field = $resource['fields'][$idx];
27+
$value = $field['actual_field_value'];
2728

2829
switch ($field['field_id']) {
2930
case 'native_mc_version':
30-
$this->native_minecraft_version = self::cleanupVersion($field['actual_field_value']);
31+
if (is_null($value) || empty($value)) {
32+
$this->native_minecraft_version = NULL;
33+
} else {
34+
$this->native_minecraft_version = self::cleanupVersion($value);
35+
}
3136
break;
3237
case 'mc_versions':
33-
$versions = array_map(
34-
function($version) {
35-
return self::cleanupVersion($version);
36-
},
37-
unserialize($field['actual_field_value'])
38-
);
39-
$this->supported_minecraft_versions = array_values($versions);
38+
if (is_null($value) || empty($value)) {
39+
$this->supported_minecraft_versions = array();
40+
} else {
41+
$versions = array_map(
42+
function($version) {
43+
return self::cleanupVersion($version);
44+
},
45+
unserialize($value)
46+
);
47+
48+
$this->supported_minecraft_versions = array_values($versions);
49+
}
4050
break;
4151
}
4252
}
@@ -67,6 +77,10 @@ function($version) {
6777
}
6878

6979
private static function cleanupVersion($value) {
80+
if (is_null($value) || (is_string($value) && empty($value))) {
81+
return NULL;
82+
}
83+
7084
if (strtolower($value) != 'legacy') {
7185
$value = str_replace('_', '.', $value);
7286
}

0 commit comments

Comments
 (0)