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