aboutsummaryrefslogtreecommitdiffstats
path: root/lib/private/App/DependencyAnalyzer.php
diff options
context:
space:
mode:
Diffstat (limited to 'lib/private/App/DependencyAnalyzer.php')
-rw-r--r--lib/private/App/DependencyAnalyzer.php151
1 files changed, 32 insertions, 119 deletions
diff --git a/lib/private/App/DependencyAnalyzer.php b/lib/private/App/DependencyAnalyzer.php
index 373e3c5e04d..bde8719c41d 100644
--- a/lib/private/App/DependencyAnalyzer.php
+++ b/lib/private/App/DependencyAnalyzer.php
@@ -1,61 +1,28 @@
<?php
+
+declare(strict_types=1);
+
/**
- * @copyright Copyright (c) 2016, ownCloud, Inc.
- * @copyright Copyright (c) 2016, Lukas Reschke <lukas@statuscode.ch>
- *
- * @author Bernhard Posselt <dev@bernhard-posselt.com>
- * @author Christoph Wurst <christoph@winzerhof-wurst.at>
- * @author Joas Schilling <coding@schilljs.com>
- * @author Julius Härtl <jus@bitgrid.net>
- * @author Lukas Reschke <lukas@statuscode.ch>
- * @author Morris Jobke <hey@morrisjobke.de>
- * @author Roeland Jago Douma <roeland@famdouma.nl>
- * @author Stefan Weil <sw@weilnetz.de>
- * @author Thomas Müller <thomas.mueller@tmit.eu>
- *
- * @license AGPL-3.0
- *
- * This code is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License, version 3,
- * as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License, version 3,
- * along with this program. If not, see <http://www.gnu.org/licenses/>
- *
+ * SPDX-FileCopyrightText: 2016-2025 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
+ * SPDX-License-Identifier: AGPL-3.0-only
*/
+
namespace OC\App;
use OCP\IL10N;
class DependencyAnalyzer {
-
- /** @var Platform */
- private $platform;
- /** @var \OCP\IL10N */
- private $l;
- /** @var array */
- private $appInfo;
-
- /**
- * @param Platform $platform
- * @param \OCP\IL10N $l
- */
- public function __construct(Platform $platform, IL10N $l) {
- $this->platform = $platform;
- $this->l = $l;
+ public function __construct(
+ private Platform $platform,
+ private IL10N $l,
+ ) {
}
/**
- * @param array $app
- * @returns array of missing dependencies
+ * @return array of missing dependencies
*/
- public function analyze(array $app, bool $ignoreMax = false) {
- $this->appInfo = $app;
+ public function analyze(array $app, bool $ignoreMax = false): array {
if (isset($app['dependencies'])) {
$dependencies = $app['dependencies'];
} else {
@@ -91,12 +58,10 @@ class DependencyAnalyzer {
* Truncates both versions to the lowest common version, e.g.
* 5.1.2.3 and 5.1 will be turned into 5.1 and 5.1,
* 5.2.6.5 and 5.1 will be turned into 5.2 and 5.1
- * @param string $first
- * @param string $second
* @return string[] first element is the first version, second element is the
- * second version
+ * second version
*/
- private function normalizeVersions($first, $second) {
+ private function normalizeVersions(string $first, string $second): array {
$first = explode('.', $first);
$second = explode('.', $second);
@@ -111,47 +76,31 @@ class DependencyAnalyzer {
/**
* Parameters will be normalized and then passed into version_compare
* in the same order they are specified in the method header
- * @param string $first
- * @param string $second
- * @param string $operator
* @return bool result similar to version_compare
*/
- private function compare($first, $second, $operator) {
- // we can't normalize versions if one of the given parameters is not a
- // version string but null. In case one parameter is null normalization
- // will therefore be skipped
- if ($first !== null && $second !== null) {
- [$first, $second] = $this->normalizeVersions($first, $second);
- }
+ private function compare(string $first, string $second, string $operator): bool {
+ [$first, $second] = $this->normalizeVersions($first, $second);
return version_compare($first, $second, $operator);
}
/**
* Checks if a version is bigger than another version
- * @param string $first
- * @param string $second
* @return bool true if the first version is bigger than the second
*/
- private function compareBigger($first, $second) {
+ private function compareBigger(string $first, string $second): bool {
return $this->compare($first, $second, '>');
}
/**
* Checks if a version is smaller than another version
- * @param string $first
- * @param string $second
* @return bool true if the first version is smaller than the second
*/
- private function compareSmaller($first, $second) {
+ private function compareSmaller(string $first, string $second): bool {
return $this->compare($first, $second, '<');
}
- /**
- * @param array $dependencies
- * @return array
- */
- private function analyzePhpVersion(array $dependencies) {
+ private function analyzePhpVersion(array $dependencies): array {
$missing = [];
if (isset($dependencies['php']['@attributes']['min-version'])) {
$minVersion = $dependencies['php']['@attributes']['min-version'];
@@ -174,7 +123,7 @@ class DependencyAnalyzer {
return $missing;
}
- private function analyzeArchitecture(array $dependencies) {
+ private function analyzeArchitecture(array $dependencies): array {
$missing = [];
if (!isset($dependencies['architecture'])) {
return $missing;
@@ -197,11 +146,7 @@ class DependencyAnalyzer {
return $missing;
}
- /**
- * @param array $dependencies
- * @return array
- */
- private function analyzeDatabases(array $dependencies) {
+ private function analyzeDatabases(array $dependencies): array {
$missing = [];
if (!isset($dependencies['database'])) {
return $missing;
@@ -214,6 +159,9 @@ class DependencyAnalyzer {
if (!is_array($supportedDatabases)) {
$supportedDatabases = [$supportedDatabases];
}
+ if (isset($supportedDatabases['@value'])) {
+ $supportedDatabases = [$supportedDatabases];
+ }
$supportedDatabases = array_map(function ($db) {
return $this->getValue($db);
}, $supportedDatabases);
@@ -224,11 +172,7 @@ class DependencyAnalyzer {
return $missing;
}
- /**
- * @param array $dependencies
- * @return array
- */
- private function analyzeCommands(array $dependencies) {
+ private function analyzeCommands(array $dependencies): array {
$missing = [];
if (!isset($dependencies['command'])) {
return $missing;
@@ -254,11 +198,7 @@ class DependencyAnalyzer {
return $missing;
}
- /**
- * @param array $dependencies
- * @return array
- */
- private function analyzeLibraries(array $dependencies) {
+ private function analyzeLibraries(array $dependencies): array {
$missing = [];
if (!isset($dependencies['lib'])) {
return $missing;
@@ -299,11 +239,7 @@ class DependencyAnalyzer {
return $missing;
}
- /**
- * @param array $dependencies
- * @return array
- */
- private function analyzeOS(array $dependencies) {
+ private function analyzeOS(array $dependencies): array {
$missing = [];
if (!isset($dependencies['os'])) {
return $missing;
@@ -327,12 +263,7 @@ class DependencyAnalyzer {
return $missing;
}
- /**
- * @param array $dependencies
- * @param array $appInfo
- * @return array
- */
- private function analyzeOC(array $dependencies, array $appInfo, bool $ignoreMax) {
+ private function analyzeOC(array $dependencies, array $appInfo, bool $ignoreMax): array {
$missing = [];
$minVersion = null;
if (isset($dependencies['nextcloud']['@attributes']['min-version'])) {
@@ -348,12 +279,12 @@ class DependencyAnalyzer {
if (!is_null($minVersion)) {
if ($this->compareSmaller($this->platform->getOcVersion(), $minVersion)) {
- $missing[] = $this->l->t('Server version %s or higher is required.', [$this->toVisibleVersion($minVersion)]);
+ $missing[] = $this->l->t('Server version %s or higher is required.', [$minVersion]);
}
}
if (!$ignoreMax && !is_null($maxVersion)) {
if ($this->compareBigger($this->platform->getOcVersion(), $maxVersion)) {
- $missing[] = $this->l->t('Server version %s or lower is required.', [$this->toVisibleVersion($maxVersion)]);
+ $missing[] = $this->l->t('Server version %s or lower is required.', [$maxVersion]);
}
}
return $missing;
@@ -374,25 +305,7 @@ class DependencyAnalyzer {
}
/**
- * Map the internal version number to the Nextcloud version
- *
- * @param string $version
- * @return string
- */
- protected function toVisibleVersion($version) {
- switch ($version) {
- case '9.1':
- return '10';
- default:
- if (strpos($version, '9.1.') === 0) {
- $version = '10.0.' . substr($version, 4);
- }
- return $version;
- }
- }
-
- /**
- * @param $element
+ * @param mixed $element
* @return mixed
*/
private function getValue($element) {