Passed
Push — master ( ba369c...dd1248 )
by Roeland
36:41 queued 23:10
created
lib/private/App/AppStore/Fetcher/AppFetcher.php 1 patch
Indentation   +136 added lines, -136 removed lines patch added patch discarded remove patch
@@ -40,141 +40,141 @@
 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);
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 89
 		
90
-		if (empty($response)) {
91
-			return [];
92
-		}
93
-
94
-		$allowPreReleases = $allowUnstable || $this->getChannel() === 'beta' || $this->getChannel() === 'daily';
95
-		$allowNightly = $allowUnstable || $this->getChannel() === 'daily';
96
-
97
-		foreach ($response['data'] as $dataKey => $app) {
98
-			$releases = [];
99
-
100
-			// Filter all compatible releases
101
-			foreach ($app['releases'] as $release) {
102
-				// Exclude all nightly and pre-releases if required
103
-				if (($allowNightly || $release['isNightly'] === false)
104
-					&& ($allowPreReleases || strpos($release['version'], '-') === false)) {
105
-					// Exclude all versions not compatible with the current version
106
-					try {
107
-						$versionParser = new VersionParser();
108
-						$serverVersion = $versionParser->getVersion($release['rawPlatformVersionSpec']);
109
-						$ncVersion = $this->getVersion();
110
-						$minServerVersion = $serverVersion->getMinimumVersion();
111
-						$maxServerVersion = $serverVersion->getMaximumVersion();
112
-						$minFulfilled = $this->compareVersion->isCompatible($ncVersion, $minServerVersion, '>=');
113
-						$maxFulfilled = $maxServerVersion !== '' &&
114
-							$this->compareVersion->isCompatible($ncVersion, $maxServerVersion, '<=');
115
-						$isPhpCompatible = true;
116
-						if (($release['rawPhpVersionSpec'] ?? '*') !== '*') {
117
-							$phpVersion = $versionParser->getVersion($release['rawPhpVersionSpec']);
118
-							$minPhpVersion = $phpVersion->getMinimumVersion();
119
-							$maxPhpVersion = $phpVersion->getMaximumVersion();
120
-							$minPhpFulfilled = $minPhpVersion === '' || $this->compareVersion->isCompatible(
121
-									PHP_VERSION,
122
-									$minPhpVersion,
123
-									'>='
124
-								);
125
-							$maxPhpFulfilled = $maxPhpVersion === '' || $this->compareVersion->isCompatible(
126
-									PHP_VERSION,
127
-									$maxPhpVersion,
128
-									'<='
129
-								);
130
-
131
-							$isPhpCompatible = $minPhpFulfilled && $maxPhpFulfilled;
132
-						}
133
-						if ($minFulfilled && ($this->ignoreMaxVersion || $maxFulfilled) && $isPhpCompatible) {
134
-							$releases[] = $release;
135
-						}
136
-					} catch (\InvalidArgumentException $e) {
137
-						$this->logger->logException($e, ['app' => 'appstoreFetcher', 'level' => ILogger::WARN]);
138
-					}
139
-				}
140
-			}
141
-
142
-			if (empty($releases)) {
143
-				// Remove apps that don't have a matching release
144
-				$response['data'][$dataKey] = [];
145
-				continue;
146
-			}
147
-
148
-			// Get the highest version
149
-			$versions = [];
150
-			foreach ($releases as $release) {
151
-				$versions[] = $release['version'];
152
-			}
153
-			usort($versions, 'version_compare');
154
-			$versions = array_reverse($versions);
155
-			if (isset($versions[0])) {
156
-				$highestVersion = $versions[0];
157
-				foreach ($releases as $release) {
158
-					if ((string)$release['version'] === (string)$highestVersion) {
159
-						$response['data'][$dataKey]['releases'] = [$release];
160
-						break;
161
-					}
162
-				}
163
-			}
164
-		}
165
-
166
-		$response['data'] = array_values(array_filter($response['data']));
167
-		return $response;
168
-	}
169
-
170
-	/**
171
-	 * @param string $version
172
-	 * @param string $fileName
173
-	 * @param bool $ignoreMaxVersion
174
-	 */
175
-	public function setVersion(string $version, string $fileName = 'apps.json', bool $ignoreMaxVersion = true) {
176
-		parent::setVersion($version);
177
-		$this->fileName = $fileName;
178
-		$this->ignoreMaxVersion = $ignoreMaxVersion;
179
-	}
90
+        if (empty($response)) {
91
+            return [];
92
+        }
93
+
94
+        $allowPreReleases = $allowUnstable || $this->getChannel() === 'beta' || $this->getChannel() === 'daily';
95
+        $allowNightly = $allowUnstable || $this->getChannel() === 'daily';
96
+
97
+        foreach ($response['data'] as $dataKey => $app) {
98
+            $releases = [];
99
+
100
+            // Filter all compatible releases
101
+            foreach ($app['releases'] as $release) {
102
+                // Exclude all nightly and pre-releases if required
103
+                if (($allowNightly || $release['isNightly'] === false)
104
+                    && ($allowPreReleases || strpos($release['version'], '-') === false)) {
105
+                    // Exclude all versions not compatible with the current version
106
+                    try {
107
+                        $versionParser = new VersionParser();
108
+                        $serverVersion = $versionParser->getVersion($release['rawPlatformVersionSpec']);
109
+                        $ncVersion = $this->getVersion();
110
+                        $minServerVersion = $serverVersion->getMinimumVersion();
111
+                        $maxServerVersion = $serverVersion->getMaximumVersion();
112
+                        $minFulfilled = $this->compareVersion->isCompatible($ncVersion, $minServerVersion, '>=');
113
+                        $maxFulfilled = $maxServerVersion !== '' &&
114
+                            $this->compareVersion->isCompatible($ncVersion, $maxServerVersion, '<=');
115
+                        $isPhpCompatible = true;
116
+                        if (($release['rawPhpVersionSpec'] ?? '*') !== '*') {
117
+                            $phpVersion = $versionParser->getVersion($release['rawPhpVersionSpec']);
118
+                            $minPhpVersion = $phpVersion->getMinimumVersion();
119
+                            $maxPhpVersion = $phpVersion->getMaximumVersion();
120
+                            $minPhpFulfilled = $minPhpVersion === '' || $this->compareVersion->isCompatible(
121
+                                    PHP_VERSION,
122
+                                    $minPhpVersion,
123
+                                    '>='
124
+                                );
125
+                            $maxPhpFulfilled = $maxPhpVersion === '' || $this->compareVersion->isCompatible(
126
+                                    PHP_VERSION,
127
+                                    $maxPhpVersion,
128
+                                    '<='
129
+                                );
130
+
131
+                            $isPhpCompatible = $minPhpFulfilled && $maxPhpFulfilled;
132
+                        }
133
+                        if ($minFulfilled && ($this->ignoreMaxVersion || $maxFulfilled) && $isPhpCompatible) {
134
+                            $releases[] = $release;
135
+                        }
136
+                    } catch (\InvalidArgumentException $e) {
137
+                        $this->logger->logException($e, ['app' => 'appstoreFetcher', 'level' => ILogger::WARN]);
138
+                    }
139
+                }
140
+            }
141
+
142
+            if (empty($releases)) {
143
+                // Remove apps that don't have a matching release
144
+                $response['data'][$dataKey] = [];
145
+                continue;
146
+            }
147
+
148
+            // Get the highest version
149
+            $versions = [];
150
+            foreach ($releases as $release) {
151
+                $versions[] = $release['version'];
152
+            }
153
+            usort($versions, 'version_compare');
154
+            $versions = array_reverse($versions);
155
+            if (isset($versions[0])) {
156
+                $highestVersion = $versions[0];
157
+                foreach ($releases as $release) {
158
+                    if ((string)$release['version'] === (string)$highestVersion) {
159
+                        $response['data'][$dataKey]['releases'] = [$release];
160
+                        break;
161
+                    }
162
+                }
163
+            }
164
+        }
165
+
166
+        $response['data'] = array_values(array_filter($response['data']));
167
+        return $response;
168
+    }
169
+
170
+    /**
171
+     * @param string $version
172
+     * @param string $fileName
173
+     * @param bool $ignoreMaxVersion
174
+     */
175
+    public function setVersion(string $version, string $fileName = 'apps.json', bool $ignoreMaxVersion = true) {
176
+        parent::setVersion($version);
177
+        $this->fileName = $fileName;
178
+        $this->ignoreMaxVersion = $ignoreMaxVersion;
179
+    }
180 180
 }
Please login to merge, or discard this patch.