Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 0 additions & 12 deletions build/psalm-baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3338,18 +3338,6 @@
<code><![CDATA[version_compare($first, $second, $operator)]]></code>
</NullableReturnStatement>
</file>
<file src="lib/private/App/InfoParser.php">
<InvalidArrayOffset>
<code><![CDATA[$array[$element][]]]></code>
<code><![CDATA[$array[$element][]]]></code>
</InvalidArrayOffset>
<InvalidReturnStatement>
<code><![CDATA[(string)$xml]]></code>
</InvalidReturnStatement>
<InvalidReturnType>
<code><![CDATA[array]]></code>
</InvalidReturnType>
</file>
<file src="lib/private/AppConfig.php">
<NullableReturnStatement>
<code><![CDATA[$this->fastCache[$app][$key] ?? $default]]></code>
Expand Down
2 changes: 1 addition & 1 deletion lib/private/App/AppManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -771,7 +771,7 @@ public function getAppInfoByPath(string $path, ?string $lang = null): ?array {
$data = $parser->parse($path);

if (is_array($data)) {
$data = \OC_App::parseAppInfo($data, $lang);
$data = $parser->applyL10N($data, $lang);
}

return $data;
Expand Down
108 changes: 24 additions & 84 deletions lib/private/App/DependencyAnalyzer.php
Original file line number Diff line number Diff line change
@@ -1,34 +1,28 @@
<?php

declare(strict_types=1);

/**
* SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors
* 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 array */
private $appInfo;

/**
* @param Platform $platform
* @param \OCP\IL10N $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 {
Expand Down Expand Up @@ -64,12 +58,10 @@ public function isMarkedCompatible(array $app): bool {
* 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
*/
private function normalizeVersions($first, $second) {
private function normalizeVersions(string $first, string $second): array {
$first = explode('.', $first);
$second = explode('.', $second);

Expand All @@ -84,47 +76,31 @@ private function normalizeVersions($first, $second) {
/**
* 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'];
Expand All @@ -147,7 +123,7 @@ private function analyzePhpVersion(array $dependencies) {
return $missing;
}

private function analyzeArchitecture(array $dependencies) {
private function analyzeArchitecture(array $dependencies): array {
$missing = [];
if (!isset($dependencies['architecture'])) {
return $missing;
Expand All @@ -170,11 +146,7 @@ private function analyzeArchitecture(array $dependencies) {
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;
Expand All @@ -187,6 +159,9 @@ private function analyzeDatabases(array $dependencies) {
if (!is_array($supportedDatabases)) {
$supportedDatabases = [$supportedDatabases];
}
if (isset($supportedDatabases['@value'])) {
$supportedDatabases = [$supportedDatabases];
}
$supportedDatabases = array_map(function ($db) {
return $this->getValue($db);
}, $supportedDatabases);
Expand All @@ -197,11 +172,7 @@ private function analyzeDatabases(array $dependencies) {
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;
Expand All @@ -227,11 +198,7 @@ private function analyzeCommands(array $dependencies) {
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;
Expand Down Expand Up @@ -272,11 +239,7 @@ private function analyzeLibraries(array $dependencies) {
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;
Expand All @@ -300,12 +263,7 @@ private function analyzeOS(array $dependencies) {
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'])) {
Expand All @@ -321,12 +279,12 @@ private function analyzeOC(array $dependencies, array $appInfo, bool $ignoreMax)

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;
Expand All @@ -347,25 +305,7 @@ private function getMaxVersion(array $dependencies, array $appInfo): ?string {
}

/**
* 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 (str_starts_with($version, '9.1.')) {
$version = '10.0.' . substr($version, 4);
}
return $version;
}
}

/**
* @param $element
* @param mixed $element
* @return mixed
*/
private function getValue($element) {
Expand Down
Loading
Loading