Passed
Push — master ( 55b2b5...582ce5 )
by Roeland
13:43
created
lib/private/App/AppStore/Fetcher/AppFetcher.php 1 patch
Indentation   +133 added lines, -133 removed lines patch added patch discarded remove patch
@@ -40,137 +40,137 @@
 block discarded – undo
40 40
 
41 41
 class AppFetcher extends Fetcher {
42 42
 
43
-	/** @var CompareVersion */
44
-	private $compareVersion;
45
-
46
-	/** @var bool */
47
-	private $ignoreMaxVersion;
48
-
49
-	/**
50
-	 * @param Factory $appDataFactory
51
-	 * @param IClientService $clientService
52
-	 * @param ITimeFactory $timeFactory
53
-	 * @param IConfig $config
54
-	 * @param CompareVersion $compareVersion
55
-	 * @param ILogger $logger
56
-	 */
57
-	public function __construct(Factory $appDataFactory,
58
-								IClientService $clientService,
59
-								ITimeFactory $timeFactory,
60
-								IConfig $config,
61
-								CompareVersion $compareVersion,
62
-								ILogger $logger) {
63
-		parent::__construct(
64
-			$appDataFactory,
65
-			$clientService,
66
-			$timeFactory,
67
-			$config,
68
-			$logger
69
-		);
70
-
71
-		$this->fileName = 'apps.json';
72
-		$this->endpointName = 'apps.json';
73
-		$this->compareVersion = $compareVersion;
74
-		$this->ignoreMaxVersion = true;
75
-	}
76
-
77
-	/**
78
-	 * Only returns the latest compatible app release in the releases array
79
-	 *
80
-	 * @param string $ETag
81
-	 * @param string $content
82
-	 * @param bool [$allowUnstable] Allow unstable releases
83
-	 *
84
-	 * @return array
85
-	 */
86
-	protected function fetch($ETag, $content, $allowUnstable = false) {
87
-		/** @var mixed[] $response */
88
-		$response = parent::fetch($ETag, $content);
89
-
90
-		$allowPreReleases = $allowUnstable || $this->getChannel() === 'beta' || $this->getChannel() === 'daily';
91
-		$allowNightly = $allowUnstable || $this->getChannel() === 'daily';
92
-
93
-		foreach ($response['data'] as $dataKey => $app) {
94
-			$releases = [];
95
-
96
-			// Filter all compatible releases
97
-			foreach ($app['releases'] as $release) {
98
-				// Exclude all nightly and pre-releases if required
99
-				if (($allowNightly || $release['isNightly'] === false)
100
-					&& ($allowPreReleases || strpos($release['version'], '-') === false)) {
101
-					// Exclude all versions not compatible with the current version
102
-					try {
103
-						$versionParser = new VersionParser();
104
-						$serverVersion = $versionParser->getVersion($release['rawPlatformVersionSpec']);
105
-						$ncVersion = $this->getVersion();
106
-						$minServerVersion = $serverVersion->getMinimumVersion();
107
-						$maxServerVersion = $serverVersion->getMaximumVersion();
108
-						$minFulfilled = $this->compareVersion->isCompatible($ncVersion, $minServerVersion, '>=');
109
-						$maxFulfilled = $maxServerVersion !== '' &&
110
-							$this->compareVersion->isCompatible($ncVersion, $maxServerVersion, '<=');
111
-						$isPhpCompatible = true;
112
-						if (($release['rawPhpVersionSpec'] ?? '*') !== '*') {
113
-							$phpVersion = $versionParser->getVersion($release['rawPhpVersionSpec']);
114
-							$minPhpVersion = $phpVersion->getMinimumVersion();
115
-							$maxPhpVersion = $phpVersion->getMaximumVersion();
116
-							$minPhpFulfilled = $minPhpVersion === '' || $this->compareVersion->isCompatible(
117
-									PHP_VERSION,
118
-									$minPhpVersion,
119
-									'>='
120
-								);
121
-							$maxPhpFulfilled = $maxPhpVersion === '' || $this->compareVersion->isCompatible(
122
-									PHP_VERSION,
123
-									$maxPhpVersion,
124
-									'<='
125
-								);
126
-
127
-							$isPhpCompatible = $minPhpFulfilled && $maxPhpFulfilled;
128
-						}
129
-						if ($minFulfilled && ($this->ignoreMaxVersion || $maxFulfilled) && $isPhpCompatible) {
130
-							$releases[] = $release;
131
-						}
132
-					} catch (\InvalidArgumentException $e) {
133
-						$this->logger->logException($e, ['app' => 'appstoreFetcher', 'level' => ILogger::WARN]);
134
-					}
135
-				}
136
-			}
137
-
138
-			if (empty($releases)) {
139
-				// Remove apps that don't have a matching release
140
-				$response['data'][$dataKey] = [];
141
-				continue;
142
-			}
143
-
144
-			// Get the highest version
145
-			$versions = [];
146
-			foreach ($releases as $release) {
147
-				$versions[] = $release['version'];
148
-			}
149
-			usort($versions, 'version_compare');
150
-			$versions = array_reverse($versions);
151
-			if (isset($versions[0])) {
152
-				$highestVersion = $versions[0];
153
-				foreach ($releases as $release) {
154
-					if ((string)$release['version'] === (string)$highestVersion) {
155
-						$response['data'][$dataKey]['releases'] = [$release];
156
-						break;
157
-					}
158
-				}
159
-			}
160
-		}
161
-
162
-		$response['data'] = array_values(array_filter($response['data']));
163
-		return $response;
164
-	}
165
-
166
-	/**
167
-	 * @param string $version
168
-	 * @param string $fileName
169
-	 * @param bool $ignoreMaxVersion
170
-	 */
171
-	public function setVersion(string $version, string $fileName = 'apps.json', bool $ignoreMaxVersion = true) {
172
-		parent::setVersion($version);
173
-		$this->fileName = $fileName;
174
-		$this->ignoreMaxVersion = $ignoreMaxVersion;
175
-	}
43
+    /** @var CompareVersion */
44
+    private $compareVersion;
45
+
46
+    /** @var bool */
47
+    private $ignoreMaxVersion;
48
+
49
+    /**
50
+     * @param Factory $appDataFactory
51
+     * @param IClientService $clientService
52
+     * @param ITimeFactory $timeFactory
53
+     * @param IConfig $config
54
+     * @param CompareVersion $compareVersion
55
+     * @param ILogger $logger
56
+     */
57
+    public function __construct(Factory $appDataFactory,
58
+                                IClientService $clientService,
59
+                                ITimeFactory $timeFactory,
60
+                                IConfig $config,
61
+                                CompareVersion $compareVersion,
62
+                                ILogger $logger) {
63
+        parent::__construct(
64
+            $appDataFactory,
65
+            $clientService,
66
+            $timeFactory,
67
+            $config,
68
+            $logger
69
+        );
70
+
71
+        $this->fileName = 'apps.json';
72
+        $this->endpointName = 'apps.json';
73
+        $this->compareVersion = $compareVersion;
74
+        $this->ignoreMaxVersion = true;
75
+    }
76
+
77
+    /**
78
+     * Only returns the latest compatible app release in the releases array
79
+     *
80
+     * @param string $ETag
81
+     * @param string $content
82
+     * @param bool [$allowUnstable] Allow unstable releases
83
+     *
84
+     * @return array
85
+     */
86
+    protected function fetch($ETag, $content, $allowUnstable = false) {
87
+        /** @var mixed[] $response */
88
+        $response = parent::fetch($ETag, $content);
89
+
90
+        $allowPreReleases = $allowUnstable || $this->getChannel() === 'beta' || $this->getChannel() === 'daily';
91
+        $allowNightly = $allowUnstable || $this->getChannel() === 'daily';
92
+
93
+        foreach ($response['data'] as $dataKey => $app) {
94
+            $releases = [];
95
+
96
+            // Filter all compatible releases
97
+            foreach ($app['releases'] as $release) {
98
+                // Exclude all nightly and pre-releases if required
99
+                if (($allowNightly || $release['isNightly'] === false)
100
+                    && ($allowPreReleases || strpos($release['version'], '-') === false)) {
101
+                    // Exclude all versions not compatible with the current version
102
+                    try {
103
+                        $versionParser = new VersionParser();
104
+                        $serverVersion = $versionParser->getVersion($release['rawPlatformVersionSpec']);
105
+                        $ncVersion = $this->getVersion();
106
+                        $minServerVersion = $serverVersion->getMinimumVersion();
107
+                        $maxServerVersion = $serverVersion->getMaximumVersion();
108
+                        $minFulfilled = $this->compareVersion->isCompatible($ncVersion, $minServerVersion, '>=');
109
+                        $maxFulfilled = $maxServerVersion !== '' &&
110
+                            $this->compareVersion->isCompatible($ncVersion, $maxServerVersion, '<=');
111
+                        $isPhpCompatible = true;
112
+                        if (($release['rawPhpVersionSpec'] ?? '*') !== '*') {
113
+                            $phpVersion = $versionParser->getVersion($release['rawPhpVersionSpec']);
114
+                            $minPhpVersion = $phpVersion->getMinimumVersion();
115
+                            $maxPhpVersion = $phpVersion->getMaximumVersion();
116
+                            $minPhpFulfilled = $minPhpVersion === '' || $this->compareVersion->isCompatible(
117
+                                    PHP_VERSION,
118
+                                    $minPhpVersion,
119
+                                    '>='
120
+                                );
121
+                            $maxPhpFulfilled = $maxPhpVersion === '' || $this->compareVersion->isCompatible(
122
+                                    PHP_VERSION,
123
+                                    $maxPhpVersion,
124
+                                    '<='
125
+                                );
126
+
127
+                            $isPhpCompatible = $minPhpFulfilled && $maxPhpFulfilled;
128
+                        }
129
+                        if ($minFulfilled && ($this->ignoreMaxVersion || $maxFulfilled) && $isPhpCompatible) {
130
+                            $releases[] = $release;
131
+                        }
132
+                    } catch (\InvalidArgumentException $e) {
133
+                        $this->logger->logException($e, ['app' => 'appstoreFetcher', 'level' => ILogger::WARN]);
134
+                    }
135
+                }
136
+            }
137
+
138
+            if (empty($releases)) {
139
+                // Remove apps that don't have a matching release
140
+                $response['data'][$dataKey] = [];
141
+                continue;
142
+            }
143
+
144
+            // Get the highest version
145
+            $versions = [];
146
+            foreach ($releases as $release) {
147
+                $versions[] = $release['version'];
148
+            }
149
+            usort($versions, 'version_compare');
150
+            $versions = array_reverse($versions);
151
+            if (isset($versions[0])) {
152
+                $highestVersion = $versions[0];
153
+                foreach ($releases as $release) {
154
+                    if ((string)$release['version'] === (string)$highestVersion) {
155
+                        $response['data'][$dataKey]['releases'] = [$release];
156
+                        break;
157
+                    }
158
+                }
159
+            }
160
+        }
161
+
162
+        $response['data'] = array_values(array_filter($response['data']));
163
+        return $response;
164
+    }
165
+
166
+    /**
167
+     * @param string $version
168
+     * @param string $fileName
169
+     * @param bool $ignoreMaxVersion
170
+     */
171
+    public function setVersion(string $version, string $fileName = 'apps.json', bool $ignoreMaxVersion = true) {
172
+        parent::setVersion($version);
173
+        $this->fileName = $fileName;
174
+        $this->ignoreMaxVersion = $ignoreMaxVersion;
175
+    }
176 176
 }
Please login to merge, or discard this patch.