88namespace PhpMyAdmin ;
99
1010use PhpMyAdmin \Utils \HttpRequest ;
11- use stdClass ;
1211
1312use function count ;
1413use function explode ;
1514use function intval ;
15+ use function is_array ;
1616use function is_numeric ;
17- use function is_object ;
1817use function is_string ;
1918use function json_decode ;
2019use function preg_match ;
@@ -34,9 +33,9 @@ class VersionInformation
3433 /**
3534 * Returns information with latest version from phpmyadmin.net
3635 *
37- * @return stdClass |null JSON decoded object with the data
36+ * @return Release[] |null JSON decoded object with the data
3837 */
39- public function getLatestVersion (): stdClass |null
38+ public function getLatestVersions (): array |null
4039 {
4140 if (! Config::getInstance ()->settings ['VersionCheck ' ]) {
4241 return null ;
@@ -59,18 +58,29 @@ public function getLatestVersion(): stdClass|null
5958
6059 $ response = $ response ?: '{} ' ;
6160 /* Parse response */
62- $ data = json_decode ($ response );
61+ $ data = json_decode ($ response, true );
6362
6463 /* Basic sanity checking */
65- if (! is_object ($ data ) || empty ( $ data -> version ) || empty ($ data-> releases ) || empty ($ data-> date )) {
64+ if (! is_array ($ data ) || ! isset ($ data[ ' releases ' ] ) || ! is_array ($ data[ ' releases ' ] )) {
6665 return null ;
6766 }
6867
6968 if ($ save ) {
7069 $ _SESSION ['cache ' ]['version_check ' ] = ['response ' => $ response , 'timestamp ' => time ()];
7170 }
7271
73- return $ data ;
72+ $ releases = [];
73+ /** @var string[] $release */
74+ foreach ($ data ['releases ' ] as $ release ) {
75+ $ releases [] = new Release (
76+ $ release ['version ' ],
77+ $ release ['date ' ],
78+ $ release ['php_versions ' ],
79+ $ release ['mysql_versions ' ],
80+ );
81+ }
82+
83+ return $ releases ;
7484 }
7585
7686 /**
@@ -137,17 +147,16 @@ public function versionToInt(string $version): int
137147 * Returns the version and date of the latest phpMyAdmin version compatible
138148 * with the available PHP and MySQL versions
139149 *
140- * @param mixed [] $releases array of information related to each version
150+ * @param Release [] $releases array of information related to each version
141151 *
142- * @return mixed[] |null containing the version and date of latest compatible version
152+ * @return Release |null containing the version and date of latest compatible version
143153 */
144- public function getLatestCompatibleVersion (array $ releases ): array |null
154+ public function getLatestCompatibleVersion (array $ releases ): Release |null
145155 {
146156 // Maintains the latest compatible version
147157 $ latestRelease = null ;
148158 foreach ($ releases as $ release ) {
149- // phpcs:ignore Squiz.NamingConventions.ValidVariableName.MemberNotCamelCaps
150- $ phpVersions = $ release ->php_versions ;
159+ $ phpVersions = $ release ->phpVersions ;
151160 $ phpConditions = explode (', ' , $ phpVersions );
152161 foreach ($ phpConditions as $ phpCondition ) {
153162 if (! $ this ->evaluateVersionCondition ('PHP ' , $ phpCondition )) {
@@ -159,8 +168,7 @@ public function getLatestCompatibleVersion(array $releases): array|null
159168 // We evaluate MySQL version constraint if there are only
160169 // one server configured.
161170 if (count (Config::getInstance ()->settings ['Servers ' ]) === 1 ) {
162- // phpcs:ignore Squiz.NamingConventions.ValidVariableName.MemberNotCamelCaps
163- $ mysqlVersions = $ release ->mysql_versions ;
171+ $ mysqlVersions = $ release ->mysqlVersions ;
164172 $ mysqlConditions = explode (', ' , $ mysqlVersions );
165173 foreach ($ mysqlConditions as $ mysqlCondition ) {
166174 if (! $ this ->evaluateVersionCondition ('MySQL ' , $ mysqlCondition )) {
@@ -170,11 +178,11 @@ public function getLatestCompatibleVersion(array $releases): array|null
170178 }
171179
172180 // To compare the current release with the previous latest release or no release is set
173- if ($ latestRelease !== null && ! version_compare ($ latestRelease[ ' version ' ] , $ release ->version , '< ' )) {
181+ if ($ latestRelease !== null && ! version_compare ($ latestRelease-> version , $ release ->version , '< ' )) {
174182 continue ;
175183 }
176184
177- $ latestRelease = [ ' version ' => $ release-> version , ' date ' => $ release -> date ] ;
185+ $ latestRelease = $ release ;
178186 }
179187
180188 // no compatible version
0 commit comments