Fix app version to be always string and neither array nor null

Signed-off-by: Morris Jobke <hey@morrisjobke.de>
This commit is contained in:
Morris Jobke 2018-02-17 15:25:24 +01:00
parent edee243b27
commit 9dc3b04802
No known key found for this signature in database
GPG Key ID: FE03C3A163FEDE68
5 changed files with 6 additions and 23 deletions

View File

@ -380,10 +380,10 @@ class AppManager implements IAppManager {
return $data;
}
public function getAppVersion(string $appId, bool $useCache = true) {
public function getAppVersion(string $appId, bool $useCache = true): string {
if(!$useCache || !isset($this->appVersions[$appId])) {
$appInfo = \OC::$server->getAppManager()->getAppInfo($appId);
$this->appVersions[$appId] = ($appInfo !== null) ? $appInfo['version'] : '0';
$this->appVersions[$appId] = ($appInfo !== null && isset($appInfo['version'])) ? $appInfo['version'] : '0';
}
return $this->appVersions[$appId];
}

View File

@ -112,7 +112,7 @@ class Installer {
);
}
$version = \OCP\Util::getVersion();
$version = implode('.', \OCP\Util::getVersion());
if (!\OC_App::isAppCompatible($version, $info)) {
throw new \Exception(
// TODO $l

View File

@ -856,7 +856,7 @@ class OC_App {
*
* @return boolean true if compatible, otherwise false
*/
public static function isAppCompatible($ocVersion, $appInfo) {
public static function isAppCompatible(string $ocVersion, array $appInfo): bool {
$requireMin = '';
$requireMax = '';
if (isset($appInfo['dependencies']['nextcloud']['@attributes']['min-version'])) {
@ -877,10 +877,6 @@ class OC_App {
$requireMax = $appInfo['requiremax'];
}
if (is_array($ocVersion)) {
$ocVersion = implode('.', $ocVersion);
}
if (!empty($requireMin)
&& version_compare(self::adjustVersionParts($ocVersion, $requireMin), $requireMin, '<')
) {

View File

@ -51,10 +51,10 @@ interface IAppManager {
*
* @param string $appId
* @param bool $useCache
* @return mixed
* @return string
* @since 14.0.0
*/
public function getAppVersion(string $appId, bool $useCache = true);
public function getAppVersion(string $appId, bool $useCache = true): string;
/**
* Check if an app is enabled for user

View File

@ -309,19 +309,6 @@ class AppTest extends \Test\TestCase {
$this->assertEquals($expectedResult, \OC_App::isAppCompatible($ocVersion, $appInfo));
}
/**
* Test that the isAppCompatible method also supports passing an array
* as $ocVersion
*/
public function testIsAppCompatibleWithArray() {
$ocVersion = array(6);
$appInfo = array(
'requiremin' => '6',
'requiremax' => '6',
);
$this->assertTrue(\OC_App::isAppCompatible($ocVersion, $appInfo));
}
/**
* Tests that the app order is correct
*/