Completed
Push — master ( bac545...383699 )
by Morris
19:54
created
settings/Controller/CheckSetupController.php 1 patch
Indentation   +553 added lines, -553 removed lines patch added patch discarded remove patch
@@ -62,293 +62,293 @@  discard block
 block discarded – undo
62 62
  * @package OC\Settings\Controller
63 63
  */
64 64
 class CheckSetupController extends Controller {
65
-	/** @var IConfig */
66
-	private $config;
67
-	/** @var IClientService */
68
-	private $clientService;
69
-	/** @var \OC_Util */
70
-	private $util;
71
-	/** @var IURLGenerator */
72
-	private $urlGenerator;
73
-	/** @var IL10N */
74
-	private $l10n;
75
-	/** @var Checker */
76
-	private $checker;
77
-	/** @var ILogger */
78
-	private $logger;
79
-	/** @var EventDispatcherInterface */
80
-	private $dispatcher;
81
-	/** @var IDBConnection|Connection */
82
-	private $db;
83
-	/** @var ILockingProvider */
84
-	private $lockingProvider;
85
-	/** @var IDateTimeFormatter */
86
-	private $dateTimeFormatter;
87
-	/** @var MemoryInfo */
88
-	private $memoryInfo;
89
-
90
-	public function __construct($AppName,
91
-								IRequest $request,
92
-								IConfig $config,
93
-								IClientService $clientService,
94
-								IURLGenerator $urlGenerator,
95
-								\OC_Util $util,
96
-								IL10N $l10n,
97
-								Checker $checker,
98
-								ILogger $logger,
99
-								EventDispatcherInterface $dispatcher,
100
-								IDBConnection $db,
101
-								ILockingProvider $lockingProvider,
102
-								IDateTimeFormatter $dateTimeFormatter,
103
-								MemoryInfo $memoryInfo) {
104
-		parent::__construct($AppName, $request);
105
-		$this->config = $config;
106
-		$this->clientService = $clientService;
107
-		$this->util = $util;
108
-		$this->urlGenerator = $urlGenerator;
109
-		$this->l10n = $l10n;
110
-		$this->checker = $checker;
111
-		$this->logger = $logger;
112
-		$this->dispatcher = $dispatcher;
113
-		$this->db = $db;
114
-		$this->lockingProvider = $lockingProvider;
115
-		$this->dateTimeFormatter = $dateTimeFormatter;
116
-		$this->memoryInfo = $memoryInfo;
117
-	}
118
-
119
-	/**
120
-	 * Checks if the server can connect to the internet using HTTPS and HTTP
121
-	 * @return bool
122
-	 */
123
-	private function isInternetConnectionWorking() {
124
-		if ($this->config->getSystemValue('has_internet_connection', true) === false) {
125
-			return false;
126
-		}
127
-
128
-		$siteArray = ['www.nextcloud.com',
129
-						'www.startpage.com',
130
-						'www.eff.org',
131
-						'www.edri.org',
132
-			];
133
-
134
-		foreach($siteArray as $site) {
135
-			if ($this->isSiteReachable($site)) {
136
-				return true;
137
-			}
138
-		}
139
-		return false;
140
-	}
141
-
142
-	/**
143
-	* Checks if the Nextcloud server can connect to a specific URL using both HTTPS and HTTP
144
-	* @return bool
145
-	*/
146
-	private function isSiteReachable($sitename) {
147
-		$httpSiteName = 'http://' . $sitename . '/';
148
-		$httpsSiteName = 'https://' . $sitename . '/';
149
-
150
-		try {
151
-			$client = $this->clientService->newClient();
152
-			$client->get($httpSiteName);
153
-			$client->get($httpsSiteName);
154
-		} catch (\Exception $e) {
155
-			$this->logger->logException($e, ['app' => 'internet_connection_check']);
156
-			return false;
157
-		}
158
-		return true;
159
-	}
160
-
161
-	/**
162
-	 * Checks whether a local memcache is installed or not
163
-	 * @return bool
164
-	 */
165
-	private function isMemcacheConfigured() {
166
-		return $this->config->getSystemValue('memcache.local', null) !== null;
167
-	}
168
-
169
-	/**
170
-	 * Whether /dev/urandom is available to the PHP controller
171
-	 *
172
-	 * @return bool
173
-	 */
174
-	private function isUrandomAvailable() {
175
-		if(@file_exists('/dev/urandom')) {
176
-			$file = fopen('/dev/urandom', 'rb');
177
-			if($file) {
178
-				fclose($file);
179
-				return true;
180
-			}
181
-		}
182
-
183
-		return false;
184
-	}
185
-
186
-	/**
187
-	 * Public for the sake of unit-testing
188
-	 *
189
-	 * @return array
190
-	 */
191
-	protected function getCurlVersion() {
192
-		return curl_version();
193
-	}
194
-
195
-	/**
196
-	 * Check if the used  SSL lib is outdated. Older OpenSSL and NSS versions do
197
-	 * have multiple bugs which likely lead to problems in combination with
198
-	 * functionality required by ownCloud such as SNI.
199
-	 *
200
-	 * @link https://github.com/owncloud/core/issues/17446#issuecomment-122877546
201
-	 * @link https://bugzilla.redhat.com/show_bug.cgi?id=1241172
202
-	 * @return string
203
-	 */
204
-	private function isUsedTlsLibOutdated() {
205
-		// Don't run check when:
206
-		// 1. Server has `has_internet_connection` set to false
207
-		// 2. AppStore AND S2S is disabled
208
-		if(!$this->config->getSystemValue('has_internet_connection', true)) {
209
-			return '';
210
-		}
211
-		if(!$this->config->getSystemValue('appstoreenabled', true)
212
-			&& $this->config->getAppValue('files_sharing', 'outgoing_server2server_share_enabled', 'yes') === 'no'
213
-			&& $this->config->getAppValue('files_sharing', 'incoming_server2server_share_enabled', 'yes') === 'no') {
214
-			return '';
215
-		}
216
-
217
-		$versionString = $this->getCurlVersion();
218
-		if(isset($versionString['ssl_version'])) {
219
-			$versionString = $versionString['ssl_version'];
220
-		} else {
221
-			return '';
222
-		}
223
-
224
-		$features = (string)$this->l10n->t('installing and updating apps via the app store or Federated Cloud Sharing');
225
-		if(!$this->config->getSystemValue('appstoreenabled', true)) {
226
-			$features = (string)$this->l10n->t('Federated Cloud Sharing');
227
-		}
228
-
229
-		// Check if at least OpenSSL after 1.01d or 1.0.2b
230
-		if(strpos($versionString, 'OpenSSL/') === 0) {
231
-			$majorVersion = substr($versionString, 8, 5);
232
-			$patchRelease = substr($versionString, 13, 6);
233
-
234
-			if(($majorVersion === '1.0.1' && ord($patchRelease) < ord('d')) ||
235
-				($majorVersion === '1.0.2' && ord($patchRelease) < ord('b'))) {
236
-				return (string) $this->l10n->t('cURL is using an outdated %s version (%s). Please update your operating system or features such as %s will not work reliably.', ['OpenSSL', $versionString, $features]);
237
-			}
238
-		}
239
-
240
-		// Check if NSS and perform heuristic check
241
-		if(strpos($versionString, 'NSS/') === 0) {
242
-			try {
243
-				$firstClient = $this->clientService->newClient();
244
-				$firstClient->get('https://nextcloud.com/');
245
-
246
-				$secondClient = $this->clientService->newClient();
247
-				$secondClient->get('https://nextcloud.com/');
248
-			} catch (ClientException $e) {
249
-				if($e->getResponse()->getStatusCode() === 400) {
250
-					return (string) $this->l10n->t('cURL is using an outdated %s version (%s). Please update your operating system or features such as %s will not work reliably.', ['NSS', $versionString, $features]);
251
-				}
252
-			}
253
-		}
254
-
255
-		return '';
256
-	}
257
-
258
-	/**
259
-	 * Whether the version is outdated
260
-	 *
261
-	 * @return bool
262
-	 */
263
-	protected function isPhpOutdated() {
264
-		if (version_compare(PHP_VERSION, '7.0.0', '<')) {
265
-			return true;
266
-		}
267
-
268
-		return false;
269
-	}
270
-
271
-	/**
272
-	 * Whether the php version is still supported (at time of release)
273
-	 * according to: https://secure.php.net/supported-versions.php
274
-	 *
275
-	 * @return array
276
-	 */
277
-	private function isPhpSupported() {
278
-		return ['eol' => $this->isPhpOutdated(), 'version' => PHP_VERSION];
279
-	}
280
-
281
-	/**
282
-	 * Check if the reverse proxy configuration is working as expected
283
-	 *
284
-	 * @return bool
285
-	 */
286
-	private function forwardedForHeadersWorking() {
287
-		$trustedProxies = $this->config->getSystemValue('trusted_proxies', []);
288
-		$remoteAddress = $this->request->getRemoteAddress();
289
-
290
-		if (is_array($trustedProxies) && in_array($remoteAddress, $trustedProxies)) {
291
-			return false;
292
-		}
293
-
294
-		// either not enabled or working correctly
295
-		return true;
296
-	}
297
-
298
-	/**
299
-	 * Checks if the correct memcache module for PHP is installed. Only
300
-	 * fails if memcached is configured and the working module is not installed.
301
-	 *
302
-	 * @return bool
303
-	 */
304
-	private function isCorrectMemcachedPHPModuleInstalled() {
305
-		if ($this->config->getSystemValue('memcache.distributed', null) !== '\OC\Memcache\Memcached') {
306
-			return true;
307
-		}
308
-
309
-		// there are two different memcached modules for PHP
310
-		// we only support memcached and not memcache
311
-		// https://code.google.com/p/memcached/wiki/PHPClientComparison
312
-		return !(!extension_loaded('memcached') && extension_loaded('memcache'));
313
-	}
314
-
315
-	/**
316
-	 * Checks if set_time_limit is not disabled.
317
-	 *
318
-	 * @return bool
319
-	 */
320
-	private function isSettimelimitAvailable() {
321
-		if (function_exists('set_time_limit')
322
-			&& strpos(@ini_get('disable_functions'), 'set_time_limit') === false) {
323
-			return true;
324
-		}
325
-
326
-		return false;
327
-	}
328
-
329
-	/**
330
-	 * @return RedirectResponse
331
-	 */
332
-	public function rescanFailedIntegrityCheck() {
333
-		$this->checker->runInstanceVerification();
334
-		return new RedirectResponse(
335
-			$this->urlGenerator->linkToRoute('settings.AdminSettings.index')
336
-		);
337
-	}
338
-
339
-	/**
340
-	 * @NoCSRFRequired
341
-	 * @return DataResponse
342
-	 */
343
-	public function getFailedIntegrityCheckFiles() {
344
-		if(!$this->checker->isCodeCheckEnforced()) {
345
-			return new DataDisplayResponse('Integrity checker has been disabled. Integrity cannot be verified.');
346
-		}
347
-
348
-		$completeResults = $this->checker->getResults();
349
-
350
-		if(!empty($completeResults)) {
351
-			$formattedTextResponse = 'Technical information
65
+    /** @var IConfig */
66
+    private $config;
67
+    /** @var IClientService */
68
+    private $clientService;
69
+    /** @var \OC_Util */
70
+    private $util;
71
+    /** @var IURLGenerator */
72
+    private $urlGenerator;
73
+    /** @var IL10N */
74
+    private $l10n;
75
+    /** @var Checker */
76
+    private $checker;
77
+    /** @var ILogger */
78
+    private $logger;
79
+    /** @var EventDispatcherInterface */
80
+    private $dispatcher;
81
+    /** @var IDBConnection|Connection */
82
+    private $db;
83
+    /** @var ILockingProvider */
84
+    private $lockingProvider;
85
+    /** @var IDateTimeFormatter */
86
+    private $dateTimeFormatter;
87
+    /** @var MemoryInfo */
88
+    private $memoryInfo;
89
+
90
+    public function __construct($AppName,
91
+                                IRequest $request,
92
+                                IConfig $config,
93
+                                IClientService $clientService,
94
+                                IURLGenerator $urlGenerator,
95
+                                \OC_Util $util,
96
+                                IL10N $l10n,
97
+                                Checker $checker,
98
+                                ILogger $logger,
99
+                                EventDispatcherInterface $dispatcher,
100
+                                IDBConnection $db,
101
+                                ILockingProvider $lockingProvider,
102
+                                IDateTimeFormatter $dateTimeFormatter,
103
+                                MemoryInfo $memoryInfo) {
104
+        parent::__construct($AppName, $request);
105
+        $this->config = $config;
106
+        $this->clientService = $clientService;
107
+        $this->util = $util;
108
+        $this->urlGenerator = $urlGenerator;
109
+        $this->l10n = $l10n;
110
+        $this->checker = $checker;
111
+        $this->logger = $logger;
112
+        $this->dispatcher = $dispatcher;
113
+        $this->db = $db;
114
+        $this->lockingProvider = $lockingProvider;
115
+        $this->dateTimeFormatter = $dateTimeFormatter;
116
+        $this->memoryInfo = $memoryInfo;
117
+    }
118
+
119
+    /**
120
+     * Checks if the server can connect to the internet using HTTPS and HTTP
121
+     * @return bool
122
+     */
123
+    private function isInternetConnectionWorking() {
124
+        if ($this->config->getSystemValue('has_internet_connection', true) === false) {
125
+            return false;
126
+        }
127
+
128
+        $siteArray = ['www.nextcloud.com',
129
+                        'www.startpage.com',
130
+                        'www.eff.org',
131
+                        'www.edri.org',
132
+            ];
133
+
134
+        foreach($siteArray as $site) {
135
+            if ($this->isSiteReachable($site)) {
136
+                return true;
137
+            }
138
+        }
139
+        return false;
140
+    }
141
+
142
+    /**
143
+     * Checks if the Nextcloud server can connect to a specific URL using both HTTPS and HTTP
144
+     * @return bool
145
+     */
146
+    private function isSiteReachable($sitename) {
147
+        $httpSiteName = 'http://' . $sitename . '/';
148
+        $httpsSiteName = 'https://' . $sitename . '/';
149
+
150
+        try {
151
+            $client = $this->clientService->newClient();
152
+            $client->get($httpSiteName);
153
+            $client->get($httpsSiteName);
154
+        } catch (\Exception $e) {
155
+            $this->logger->logException($e, ['app' => 'internet_connection_check']);
156
+            return false;
157
+        }
158
+        return true;
159
+    }
160
+
161
+    /**
162
+     * Checks whether a local memcache is installed or not
163
+     * @return bool
164
+     */
165
+    private function isMemcacheConfigured() {
166
+        return $this->config->getSystemValue('memcache.local', null) !== null;
167
+    }
168
+
169
+    /**
170
+     * Whether /dev/urandom is available to the PHP controller
171
+     *
172
+     * @return bool
173
+     */
174
+    private function isUrandomAvailable() {
175
+        if(@file_exists('/dev/urandom')) {
176
+            $file = fopen('/dev/urandom', 'rb');
177
+            if($file) {
178
+                fclose($file);
179
+                return true;
180
+            }
181
+        }
182
+
183
+        return false;
184
+    }
185
+
186
+    /**
187
+     * Public for the sake of unit-testing
188
+     *
189
+     * @return array
190
+     */
191
+    protected function getCurlVersion() {
192
+        return curl_version();
193
+    }
194
+
195
+    /**
196
+     * Check if the used  SSL lib is outdated. Older OpenSSL and NSS versions do
197
+     * have multiple bugs which likely lead to problems in combination with
198
+     * functionality required by ownCloud such as SNI.
199
+     *
200
+     * @link https://github.com/owncloud/core/issues/17446#issuecomment-122877546
201
+     * @link https://bugzilla.redhat.com/show_bug.cgi?id=1241172
202
+     * @return string
203
+     */
204
+    private function isUsedTlsLibOutdated() {
205
+        // Don't run check when:
206
+        // 1. Server has `has_internet_connection` set to false
207
+        // 2. AppStore AND S2S is disabled
208
+        if(!$this->config->getSystemValue('has_internet_connection', true)) {
209
+            return '';
210
+        }
211
+        if(!$this->config->getSystemValue('appstoreenabled', true)
212
+            && $this->config->getAppValue('files_sharing', 'outgoing_server2server_share_enabled', 'yes') === 'no'
213
+            && $this->config->getAppValue('files_sharing', 'incoming_server2server_share_enabled', 'yes') === 'no') {
214
+            return '';
215
+        }
216
+
217
+        $versionString = $this->getCurlVersion();
218
+        if(isset($versionString['ssl_version'])) {
219
+            $versionString = $versionString['ssl_version'];
220
+        } else {
221
+            return '';
222
+        }
223
+
224
+        $features = (string)$this->l10n->t('installing and updating apps via the app store or Federated Cloud Sharing');
225
+        if(!$this->config->getSystemValue('appstoreenabled', true)) {
226
+            $features = (string)$this->l10n->t('Federated Cloud Sharing');
227
+        }
228
+
229
+        // Check if at least OpenSSL after 1.01d or 1.0.2b
230
+        if(strpos($versionString, 'OpenSSL/') === 0) {
231
+            $majorVersion = substr($versionString, 8, 5);
232
+            $patchRelease = substr($versionString, 13, 6);
233
+
234
+            if(($majorVersion === '1.0.1' && ord($patchRelease) < ord('d')) ||
235
+                ($majorVersion === '1.0.2' && ord($patchRelease) < ord('b'))) {
236
+                return (string) $this->l10n->t('cURL is using an outdated %s version (%s). Please update your operating system or features such as %s will not work reliably.', ['OpenSSL', $versionString, $features]);
237
+            }
238
+        }
239
+
240
+        // Check if NSS and perform heuristic check
241
+        if(strpos($versionString, 'NSS/') === 0) {
242
+            try {
243
+                $firstClient = $this->clientService->newClient();
244
+                $firstClient->get('https://nextcloud.com/');
245
+
246
+                $secondClient = $this->clientService->newClient();
247
+                $secondClient->get('https://nextcloud.com/');
248
+            } catch (ClientException $e) {
249
+                if($e->getResponse()->getStatusCode() === 400) {
250
+                    return (string) $this->l10n->t('cURL is using an outdated %s version (%s). Please update your operating system or features such as %s will not work reliably.', ['NSS', $versionString, $features]);
251
+                }
252
+            }
253
+        }
254
+
255
+        return '';
256
+    }
257
+
258
+    /**
259
+     * Whether the version is outdated
260
+     *
261
+     * @return bool
262
+     */
263
+    protected function isPhpOutdated() {
264
+        if (version_compare(PHP_VERSION, '7.0.0', '<')) {
265
+            return true;
266
+        }
267
+
268
+        return false;
269
+    }
270
+
271
+    /**
272
+     * Whether the php version is still supported (at time of release)
273
+     * according to: https://secure.php.net/supported-versions.php
274
+     *
275
+     * @return array
276
+     */
277
+    private function isPhpSupported() {
278
+        return ['eol' => $this->isPhpOutdated(), 'version' => PHP_VERSION];
279
+    }
280
+
281
+    /**
282
+     * Check if the reverse proxy configuration is working as expected
283
+     *
284
+     * @return bool
285
+     */
286
+    private function forwardedForHeadersWorking() {
287
+        $trustedProxies = $this->config->getSystemValue('trusted_proxies', []);
288
+        $remoteAddress = $this->request->getRemoteAddress();
289
+
290
+        if (is_array($trustedProxies) && in_array($remoteAddress, $trustedProxies)) {
291
+            return false;
292
+        }
293
+
294
+        // either not enabled or working correctly
295
+        return true;
296
+    }
297
+
298
+    /**
299
+     * Checks if the correct memcache module for PHP is installed. Only
300
+     * fails if memcached is configured and the working module is not installed.
301
+     *
302
+     * @return bool
303
+     */
304
+    private function isCorrectMemcachedPHPModuleInstalled() {
305
+        if ($this->config->getSystemValue('memcache.distributed', null) !== '\OC\Memcache\Memcached') {
306
+            return true;
307
+        }
308
+
309
+        // there are two different memcached modules for PHP
310
+        // we only support memcached and not memcache
311
+        // https://code.google.com/p/memcached/wiki/PHPClientComparison
312
+        return !(!extension_loaded('memcached') && extension_loaded('memcache'));
313
+    }
314
+
315
+    /**
316
+     * Checks if set_time_limit is not disabled.
317
+     *
318
+     * @return bool
319
+     */
320
+    private function isSettimelimitAvailable() {
321
+        if (function_exists('set_time_limit')
322
+            && strpos(@ini_get('disable_functions'), 'set_time_limit') === false) {
323
+            return true;
324
+        }
325
+
326
+        return false;
327
+    }
328
+
329
+    /**
330
+     * @return RedirectResponse
331
+     */
332
+    public function rescanFailedIntegrityCheck() {
333
+        $this->checker->runInstanceVerification();
334
+        return new RedirectResponse(
335
+            $this->urlGenerator->linkToRoute('settings.AdminSettings.index')
336
+        );
337
+    }
338
+
339
+    /**
340
+     * @NoCSRFRequired
341
+     * @return DataResponse
342
+     */
343
+    public function getFailedIntegrityCheckFiles() {
344
+        if(!$this->checker->isCodeCheckEnforced()) {
345
+            return new DataDisplayResponse('Integrity checker has been disabled. Integrity cannot be verified.');
346
+        }
347
+
348
+        $completeResults = $this->checker->getResults();
349
+
350
+        if(!empty($completeResults)) {
351
+            $formattedTextResponse = 'Technical information
352 352
 =====================
353 353
 The following list covers which files have failed the integrity check. Please read
354 354
 the previous linked documentation to learn more about the errors and how to fix
@@ -357,273 +357,273 @@  discard block
 block discarded – undo
357 357
 Results
358 358
 =======
359 359
 ';
360
-			foreach($completeResults as $context => $contextResult) {
361
-				$formattedTextResponse .= "- $context\n";
362
-
363
-				foreach($contextResult as $category => $result) {
364
-					$formattedTextResponse .= "\t- $category\n";
365
-					if($category !== 'EXCEPTION') {
366
-						foreach ($result as $key => $results) {
367
-							$formattedTextResponse .= "\t\t- $key\n";
368
-						}
369
-					} else {
370
-						foreach ($result as $key => $results) {
371
-							$formattedTextResponse .= "\t\t- $results\n";
372
-						}
373
-					}
374
-
375
-				}
376
-			}
377
-
378
-			$formattedTextResponse .= '
360
+            foreach($completeResults as $context => $contextResult) {
361
+                $formattedTextResponse .= "- $context\n";
362
+
363
+                foreach($contextResult as $category => $result) {
364
+                    $formattedTextResponse .= "\t- $category\n";
365
+                    if($category !== 'EXCEPTION') {
366
+                        foreach ($result as $key => $results) {
367
+                            $formattedTextResponse .= "\t\t- $key\n";
368
+                        }
369
+                    } else {
370
+                        foreach ($result as $key => $results) {
371
+                            $formattedTextResponse .= "\t\t- $results\n";
372
+                        }
373
+                    }
374
+
375
+                }
376
+            }
377
+
378
+            $formattedTextResponse .= '
379 379
 Raw output
380 380
 ==========
381 381
 ';
382
-			$formattedTextResponse .= print_r($completeResults, true);
383
-		} else {
384
-			$formattedTextResponse = 'No errors have been found.';
385
-		}
386
-
387
-
388
-		$response = new DataDisplayResponse(
389
-			$formattedTextResponse,
390
-			Http::STATUS_OK,
391
-			[
392
-				'Content-Type' => 'text/plain',
393
-			]
394
-		);
395
-
396
-		return $response;
397
-	}
398
-
399
-	/**
400
-	 * Checks whether a PHP opcache is properly set up
401
-	 * @return bool
402
-	 */
403
-	protected function isOpcacheProperlySetup() {
404
-		$iniWrapper = new IniGetWrapper();
405
-
406
-		if(!$iniWrapper->getBool('opcache.enable')) {
407
-			return false;
408
-		}
409
-
410
-		if(!$iniWrapper->getBool('opcache.save_comments')) {
411
-			return false;
412
-		}
413
-
414
-		if(!$iniWrapper->getBool('opcache.enable_cli')) {
415
-			return false;
416
-		}
417
-
418
-		if($iniWrapper->getNumeric('opcache.max_accelerated_files') < 10000) {
419
-			return false;
420
-		}
421
-
422
-		if($iniWrapper->getNumeric('opcache.memory_consumption') < 128) {
423
-			return false;
424
-		}
425
-
426
-		if($iniWrapper->getNumeric('opcache.interned_strings_buffer') < 8) {
427
-			return false;
428
-		}
429
-
430
-		return true;
431
-	}
432
-
433
-	/**
434
-	 * Check if the required FreeType functions are present
435
-	 * @return bool
436
-	 */
437
-	protected function hasFreeTypeSupport() {
438
-		return function_exists('imagettfbbox') && function_exists('imagettftext');
439
-	}
440
-
441
-	protected function hasMissingIndexes(): array {
442
-		$indexInfo = new MissingIndexInformation();
443
-		// Dispatch event so apps can also hint for pending index updates if needed
444
-		$event = new GenericEvent($indexInfo);
445
-		$this->dispatcher->dispatch(IDBConnection::CHECK_MISSING_INDEXES_EVENT, $event);
446
-
447
-		return $indexInfo->getListOfMissingIndexes();
448
-	}
449
-
450
-	/**
451
-	 * warn if outdated version of a memcache module is used
452
-	 */
453
-	protected function getOutdatedCaches(): array {
454
-		$caches = [
455
-			'apcu'	=> ['name' => 'APCu', 'version' => '4.0.6'],
456
-			'redis'	=> ['name' => 'Redis', 'version' => '2.2.5'],
457
-		];
458
-		$outdatedCaches = [];
459
-		foreach ($caches as $php_module => $data) {
460
-			$isOutdated = extension_loaded($php_module) && version_compare(phpversion($php_module), $data['version'], '<');
461
-			if ($isOutdated) {
462
-				$outdatedCaches[] = $data;
463
-			}
464
-		}
465
-
466
-		return $outdatedCaches;
467
-	}
468
-
469
-	protected function isSqliteUsed() {
470
-		return strpos($this->config->getSystemValue('dbtype'), 'sqlite') !== false;
471
-	}
472
-
473
-	protected function isReadOnlyConfig(): bool {
474
-		return \OC_Helper::isReadOnlyConfigEnabled();
475
-	}
476
-
477
-	protected function hasValidTransactionIsolationLevel(): bool {
478
-		try {
479
-			if ($this->db->getDatabasePlatform() instanceof SqlitePlatform) {
480
-				return true;
481
-			}
482
-
483
-			return $this->db->getTransactionIsolation() === Connection::TRANSACTION_READ_COMMITTED;
484
-		} catch (DBALException $e) {
485
-			// ignore
486
-		}
487
-
488
-		return true;
489
-	}
490
-
491
-	protected function hasFileinfoInstalled(): bool {
492
-		return \OC_Util::fileInfoLoaded();
493
-	}
494
-
495
-	protected function hasWorkingFileLocking(): bool {
496
-		return !($this->lockingProvider instanceof NoopLockingProvider);
497
-	}
498
-
499
-	protected function getSuggestedOverwriteCliURL(): string {
500
-		$suggestedOverwriteCliUrl = '';
501
-		if ($this->config->getSystemValue('overwrite.cli.url', '') === '') {
502
-			$suggestedOverwriteCliUrl = $this->request->getServerProtocol() . '://' . $this->request->getInsecureServerHost() . \OC::$WEBROOT;
503
-			if (!$this->config->getSystemValue('config_is_read_only', false)) {
504
-				// Set the overwrite URL when it was not set yet.
505
-				$this->config->setSystemValue('overwrite.cli.url', $suggestedOverwriteCliUrl);
506
-				$suggestedOverwriteCliUrl = '';
507
-			}
508
-		}
509
-		return $suggestedOverwriteCliUrl;
510
-	}
511
-
512
-	protected function getLastCronInfo(): array {
513
-		$lastCronRun = $this->config->getAppValue('core', 'lastcron', 0);
514
-		return [
515
-			'diffInSeconds' => time() - $lastCronRun,
516
-			'relativeTime' => $this->dateTimeFormatter->formatTimeSpan($lastCronRun),
517
-			'backgroundJobsUrl' => $this->urlGenerator->linkToRoute('settings.AdminSettings.index', ['section' => 'server']) . '#backgroundjobs',
518
-		];
519
-	}
520
-
521
-	protected function getCronErrors() {
522
-		$errors = json_decode($this->config->getAppValue('core', 'cronErrors', ''), true);
523
-
524
-		if (is_array($errors)) {
525
-			return $errors;
526
-		}
527
-
528
-		return [];
529
-	}
530
-
531
-	protected function isPhpMailerUsed(): bool {
532
-		return $this->config->getSystemValue('mail_smtpmode', 'php') === 'php';
533
-	}
534
-
535
-	protected function hasOpcacheLoaded(): bool {
536
-		return function_exists('opcache_get_status');
537
-	}
538
-
539
-	/**
540
-	 * Iterates through the configured app roots and
541
-	 * tests if the subdirectories are owned by the same user than the current user.
542
-	 *
543
-	 * @return array
544
-	 */
545
-	protected function getAppDirsWithDifferentOwner(): array {
546
-		$currentUser = posix_getpwuid(posix_getuid());
547
-		$appDirsWithDifferentOwner = [];
548
-
549
-		foreach (OC::$APPSROOTS as $appRoot) {
550
-			if ($appRoot['writable'] === true) {
551
-				$appDirsWithDifferentOwner = array_merge(
552
-					$appDirsWithDifferentOwner,
553
-					$this->getAppDirsWithDifferentOwnerForAppRoot($currentUser, $appRoot)
554
-				);
555
-			}
556
-		}
557
-
558
-		sort($appDirsWithDifferentOwner);
559
-		return $appDirsWithDifferentOwner;
560
-	}
561
-
562
-	/**
563
-	 * Tests if the directories for one apps directory are writable by the current user.
564
-	 *
565
-	 * @param array $currentUser The current user
566
-	 * @param array $appRoot The app root config
567
-	 * @return string[] The none writable directory paths inside the app root
568
-	 */
569
-	private function getAppDirsWithDifferentOwnerForAppRoot(array $currentUser, array $appRoot): array {
570
-		$appDirsWithDifferentOwner = [];
571
-		$appsPath = $appRoot['path'];
572
-		$appsDir = new DirectoryIterator($appRoot['path']);
573
-
574
-		foreach ($appsDir as $fileInfo) {
575
-			if ($fileInfo->isDir() && !$fileInfo->isDot()) {
576
-				$absAppPath = $appsPath . DIRECTORY_SEPARATOR . $fileInfo->getFilename();
577
-				$appDirUser = posix_getpwuid(fileowner($absAppPath));
578
-				if ($appDirUser !== $currentUser) {
579
-					$appDirsWithDifferentOwner[] = $absAppPath . DIRECTORY_SEPARATOR . $fileInfo->getFilename();
580
-				}
581
-			}
582
-		}
583
-
584
-		return $appDirsWithDifferentOwner;
585
-	}
586
-
587
-	/**
588
-	 * @return DataResponse
589
-	 */
590
-	public function check() {
591
-		return new DataResponse(
592
-			[
593
-				'isGetenvServerWorking' => !empty(getenv('PATH')),
594
-				'isReadOnlyConfig' => $this->isReadOnlyConfig(),
595
-				'hasValidTransactionIsolationLevel' => $this->hasValidTransactionIsolationLevel(),
596
-				'outdatedCaches' => $this->getOutdatedCaches(),
597
-				'hasFileinfoInstalled' => $this->hasFileinfoInstalled(),
598
-				'hasWorkingFileLocking' => $this->hasWorkingFileLocking(),
599
-				'suggestedOverwriteCliURL' => $this->getSuggestedOverwriteCliURL(),
600
-				'cronInfo' => $this->getLastCronInfo(),
601
-				'cronErrors' => $this->getCronErrors(),
602
-				'serverHasInternetConnection' => $this->isInternetConnectionWorking(),
603
-				'isMemcacheConfigured' => $this->isMemcacheConfigured(),
604
-				'memcacheDocs' => $this->urlGenerator->linkToDocs('admin-performance'),
605
-				'isUrandomAvailable' => $this->isUrandomAvailable(),
606
-				'securityDocs' => $this->urlGenerator->linkToDocs('admin-security'),
607
-				'isUsedTlsLibOutdated' => $this->isUsedTlsLibOutdated(),
608
-				'phpSupported' => $this->isPhpSupported(),
609
-				'forwardedForHeadersWorking' => $this->forwardedForHeadersWorking(),
610
-				'reverseProxyDocs' => $this->urlGenerator->linkToDocs('admin-reverse-proxy'),
611
-				'isCorrectMemcachedPHPModuleInstalled' => $this->isCorrectMemcachedPHPModuleInstalled(),
612
-				'hasPassedCodeIntegrityCheck' => $this->checker->hasPassedCheck(),
613
-				'codeIntegrityCheckerDocumentation' => $this->urlGenerator->linkToDocs('admin-code-integrity'),
614
-				'isOpcacheProperlySetup' => $this->isOpcacheProperlySetup(),
615
-				'hasOpcacheLoaded' => $this->hasOpcacheLoaded(),
616
-				'phpOpcacheDocumentation' => $this->urlGenerator->linkToDocs('admin-php-opcache'),
617
-				'isSettimelimitAvailable' => $this->isSettimelimitAvailable(),
618
-				'hasFreeTypeSupport' => $this->hasFreeTypeSupport(),
619
-				'missingIndexes' => $this->hasMissingIndexes(),
620
-				'isSqliteUsed' => $this->isSqliteUsed(),
621
-				'databaseConversionDocumentation' => $this->urlGenerator->linkToDocs('admin-db-conversion'),
622
-				'isPhpMailerUsed' => $this->isPhpMailerUsed(),
623
-				'mailSettingsDocumentation' => $this->urlGenerator->getAbsoluteURL('index.php/settings/admin'),
624
-				'isMemoryLimitSufficient' => $this->memoryInfo->isMemoryLimitSufficient(),
625
-				'appDirsWithDifferentOwner' => $this->getAppDirsWithDifferentOwner(),
626
-			]
627
-		);
628
-	}
382
+            $formattedTextResponse .= print_r($completeResults, true);
383
+        } else {
384
+            $formattedTextResponse = 'No errors have been found.';
385
+        }
386
+
387
+
388
+        $response = new DataDisplayResponse(
389
+            $formattedTextResponse,
390
+            Http::STATUS_OK,
391
+            [
392
+                'Content-Type' => 'text/plain',
393
+            ]
394
+        );
395
+
396
+        return $response;
397
+    }
398
+
399
+    /**
400
+     * Checks whether a PHP opcache is properly set up
401
+     * @return bool
402
+     */
403
+    protected function isOpcacheProperlySetup() {
404
+        $iniWrapper = new IniGetWrapper();
405
+
406
+        if(!$iniWrapper->getBool('opcache.enable')) {
407
+            return false;
408
+        }
409
+
410
+        if(!$iniWrapper->getBool('opcache.save_comments')) {
411
+            return false;
412
+        }
413
+
414
+        if(!$iniWrapper->getBool('opcache.enable_cli')) {
415
+            return false;
416
+        }
417
+
418
+        if($iniWrapper->getNumeric('opcache.max_accelerated_files') < 10000) {
419
+            return false;
420
+        }
421
+
422
+        if($iniWrapper->getNumeric('opcache.memory_consumption') < 128) {
423
+            return false;
424
+        }
425
+
426
+        if($iniWrapper->getNumeric('opcache.interned_strings_buffer') < 8) {
427
+            return false;
428
+        }
429
+
430
+        return true;
431
+    }
432
+
433
+    /**
434
+     * Check if the required FreeType functions are present
435
+     * @return bool
436
+     */
437
+    protected function hasFreeTypeSupport() {
438
+        return function_exists('imagettfbbox') && function_exists('imagettftext');
439
+    }
440
+
441
+    protected function hasMissingIndexes(): array {
442
+        $indexInfo = new MissingIndexInformation();
443
+        // Dispatch event so apps can also hint for pending index updates if needed
444
+        $event = new GenericEvent($indexInfo);
445
+        $this->dispatcher->dispatch(IDBConnection::CHECK_MISSING_INDEXES_EVENT, $event);
446
+
447
+        return $indexInfo->getListOfMissingIndexes();
448
+    }
449
+
450
+    /**
451
+     * warn if outdated version of a memcache module is used
452
+     */
453
+    protected function getOutdatedCaches(): array {
454
+        $caches = [
455
+            'apcu'	=> ['name' => 'APCu', 'version' => '4.0.6'],
456
+            'redis'	=> ['name' => 'Redis', 'version' => '2.2.5'],
457
+        ];
458
+        $outdatedCaches = [];
459
+        foreach ($caches as $php_module => $data) {
460
+            $isOutdated = extension_loaded($php_module) && version_compare(phpversion($php_module), $data['version'], '<');
461
+            if ($isOutdated) {
462
+                $outdatedCaches[] = $data;
463
+            }
464
+        }
465
+
466
+        return $outdatedCaches;
467
+    }
468
+
469
+    protected function isSqliteUsed() {
470
+        return strpos($this->config->getSystemValue('dbtype'), 'sqlite') !== false;
471
+    }
472
+
473
+    protected function isReadOnlyConfig(): bool {
474
+        return \OC_Helper::isReadOnlyConfigEnabled();
475
+    }
476
+
477
+    protected function hasValidTransactionIsolationLevel(): bool {
478
+        try {
479
+            if ($this->db->getDatabasePlatform() instanceof SqlitePlatform) {
480
+                return true;
481
+            }
482
+
483
+            return $this->db->getTransactionIsolation() === Connection::TRANSACTION_READ_COMMITTED;
484
+        } catch (DBALException $e) {
485
+            // ignore
486
+        }
487
+
488
+        return true;
489
+    }
490
+
491
+    protected function hasFileinfoInstalled(): bool {
492
+        return \OC_Util::fileInfoLoaded();
493
+    }
494
+
495
+    protected function hasWorkingFileLocking(): bool {
496
+        return !($this->lockingProvider instanceof NoopLockingProvider);
497
+    }
498
+
499
+    protected function getSuggestedOverwriteCliURL(): string {
500
+        $suggestedOverwriteCliUrl = '';
501
+        if ($this->config->getSystemValue('overwrite.cli.url', '') === '') {
502
+            $suggestedOverwriteCliUrl = $this->request->getServerProtocol() . '://' . $this->request->getInsecureServerHost() . \OC::$WEBROOT;
503
+            if (!$this->config->getSystemValue('config_is_read_only', false)) {
504
+                // Set the overwrite URL when it was not set yet.
505
+                $this->config->setSystemValue('overwrite.cli.url', $suggestedOverwriteCliUrl);
506
+                $suggestedOverwriteCliUrl = '';
507
+            }
508
+        }
509
+        return $suggestedOverwriteCliUrl;
510
+    }
511
+
512
+    protected function getLastCronInfo(): array {
513
+        $lastCronRun = $this->config->getAppValue('core', 'lastcron', 0);
514
+        return [
515
+            'diffInSeconds' => time() - $lastCronRun,
516
+            'relativeTime' => $this->dateTimeFormatter->formatTimeSpan($lastCronRun),
517
+            'backgroundJobsUrl' => $this->urlGenerator->linkToRoute('settings.AdminSettings.index', ['section' => 'server']) . '#backgroundjobs',
518
+        ];
519
+    }
520
+
521
+    protected function getCronErrors() {
522
+        $errors = json_decode($this->config->getAppValue('core', 'cronErrors', ''), true);
523
+
524
+        if (is_array($errors)) {
525
+            return $errors;
526
+        }
527
+
528
+        return [];
529
+    }
530
+
531
+    protected function isPhpMailerUsed(): bool {
532
+        return $this->config->getSystemValue('mail_smtpmode', 'php') === 'php';
533
+    }
534
+
535
+    protected function hasOpcacheLoaded(): bool {
536
+        return function_exists('opcache_get_status');
537
+    }
538
+
539
+    /**
540
+     * Iterates through the configured app roots and
541
+     * tests if the subdirectories are owned by the same user than the current user.
542
+     *
543
+     * @return array
544
+     */
545
+    protected function getAppDirsWithDifferentOwner(): array {
546
+        $currentUser = posix_getpwuid(posix_getuid());
547
+        $appDirsWithDifferentOwner = [];
548
+
549
+        foreach (OC::$APPSROOTS as $appRoot) {
550
+            if ($appRoot['writable'] === true) {
551
+                $appDirsWithDifferentOwner = array_merge(
552
+                    $appDirsWithDifferentOwner,
553
+                    $this->getAppDirsWithDifferentOwnerForAppRoot($currentUser, $appRoot)
554
+                );
555
+            }
556
+        }
557
+
558
+        sort($appDirsWithDifferentOwner);
559
+        return $appDirsWithDifferentOwner;
560
+    }
561
+
562
+    /**
563
+     * Tests if the directories for one apps directory are writable by the current user.
564
+     *
565
+     * @param array $currentUser The current user
566
+     * @param array $appRoot The app root config
567
+     * @return string[] The none writable directory paths inside the app root
568
+     */
569
+    private function getAppDirsWithDifferentOwnerForAppRoot(array $currentUser, array $appRoot): array {
570
+        $appDirsWithDifferentOwner = [];
571
+        $appsPath = $appRoot['path'];
572
+        $appsDir = new DirectoryIterator($appRoot['path']);
573
+
574
+        foreach ($appsDir as $fileInfo) {
575
+            if ($fileInfo->isDir() && !$fileInfo->isDot()) {
576
+                $absAppPath = $appsPath . DIRECTORY_SEPARATOR . $fileInfo->getFilename();
577
+                $appDirUser = posix_getpwuid(fileowner($absAppPath));
578
+                if ($appDirUser !== $currentUser) {
579
+                    $appDirsWithDifferentOwner[] = $absAppPath . DIRECTORY_SEPARATOR . $fileInfo->getFilename();
580
+                }
581
+            }
582
+        }
583
+
584
+        return $appDirsWithDifferentOwner;
585
+    }
586
+
587
+    /**
588
+     * @return DataResponse
589
+     */
590
+    public function check() {
591
+        return new DataResponse(
592
+            [
593
+                'isGetenvServerWorking' => !empty(getenv('PATH')),
594
+                'isReadOnlyConfig' => $this->isReadOnlyConfig(),
595
+                'hasValidTransactionIsolationLevel' => $this->hasValidTransactionIsolationLevel(),
596
+                'outdatedCaches' => $this->getOutdatedCaches(),
597
+                'hasFileinfoInstalled' => $this->hasFileinfoInstalled(),
598
+                'hasWorkingFileLocking' => $this->hasWorkingFileLocking(),
599
+                'suggestedOverwriteCliURL' => $this->getSuggestedOverwriteCliURL(),
600
+                'cronInfo' => $this->getLastCronInfo(),
601
+                'cronErrors' => $this->getCronErrors(),
602
+                'serverHasInternetConnection' => $this->isInternetConnectionWorking(),
603
+                'isMemcacheConfigured' => $this->isMemcacheConfigured(),
604
+                'memcacheDocs' => $this->urlGenerator->linkToDocs('admin-performance'),
605
+                'isUrandomAvailable' => $this->isUrandomAvailable(),
606
+                'securityDocs' => $this->urlGenerator->linkToDocs('admin-security'),
607
+                'isUsedTlsLibOutdated' => $this->isUsedTlsLibOutdated(),
608
+                'phpSupported' => $this->isPhpSupported(),
609
+                'forwardedForHeadersWorking' => $this->forwardedForHeadersWorking(),
610
+                'reverseProxyDocs' => $this->urlGenerator->linkToDocs('admin-reverse-proxy'),
611
+                'isCorrectMemcachedPHPModuleInstalled' => $this->isCorrectMemcachedPHPModuleInstalled(),
612
+                'hasPassedCodeIntegrityCheck' => $this->checker->hasPassedCheck(),
613
+                'codeIntegrityCheckerDocumentation' => $this->urlGenerator->linkToDocs('admin-code-integrity'),
614
+                'isOpcacheProperlySetup' => $this->isOpcacheProperlySetup(),
615
+                'hasOpcacheLoaded' => $this->hasOpcacheLoaded(),
616
+                'phpOpcacheDocumentation' => $this->urlGenerator->linkToDocs('admin-php-opcache'),
617
+                'isSettimelimitAvailable' => $this->isSettimelimitAvailable(),
618
+                'hasFreeTypeSupport' => $this->hasFreeTypeSupport(),
619
+                'missingIndexes' => $this->hasMissingIndexes(),
620
+                'isSqliteUsed' => $this->isSqliteUsed(),
621
+                'databaseConversionDocumentation' => $this->urlGenerator->linkToDocs('admin-db-conversion'),
622
+                'isPhpMailerUsed' => $this->isPhpMailerUsed(),
623
+                'mailSettingsDocumentation' => $this->urlGenerator->getAbsoluteURL('index.php/settings/admin'),
624
+                'isMemoryLimitSufficient' => $this->memoryInfo->isMemoryLimitSufficient(),
625
+                'appDirsWithDifferentOwner' => $this->getAppDirsWithDifferentOwner(),
626
+            ]
627
+        );
628
+    }
629 629
 }
Please login to merge, or discard this patch.
console.php 2 patches
Indentation   +49 added lines, -49 removed lines patch added patch discarded remove patch
@@ -38,64 +38,64 @@
 block discarded – undo
38 38
 define('OC_CONSOLE', 1);
39 39
 
40 40
 function exceptionHandler($exception) {
41
-	echo "An unhandled exception has been thrown:" . PHP_EOL;
42
-	echo $exception;
43
-	exit(1);
41
+    echo "An unhandled exception has been thrown:" . PHP_EOL;
42
+    echo $exception;
43
+    exit(1);
44 44
 }
45 45
 try {
46
-	require_once __DIR__ . '/lib/base.php';
46
+    require_once __DIR__ . '/lib/base.php';
47 47
 
48
-	// set to run indefinitely if needed
49
-	if (strpos(@ini_get('disable_functions'), 'set_time_limit') === false) {
50
-		@set_time_limit(0);
51
-	}
48
+    // set to run indefinitely if needed
49
+    if (strpos(@ini_get('disable_functions'), 'set_time_limit') === false) {
50
+        @set_time_limit(0);
51
+    }
52 52
 
53
-	if (!OC::$CLI) {
54
-		echo "This script can be run from the command line only" . PHP_EOL;
55
-		exit(1);
56
-	}
53
+    if (!OC::$CLI) {
54
+        echo "This script can be run from the command line only" . PHP_EOL;
55
+        exit(1);
56
+    }
57 57
 
58
-	set_exception_handler('exceptionHandler');
58
+    set_exception_handler('exceptionHandler');
59 59
 
60
-	if (!function_exists('posix_getuid')) {
61
-		echo "The posix extensions are required - see http://php.net/manual/en/book.posix.php" . PHP_EOL;
62
-		exit(1);
63
-	}
64
-	$user = posix_getpwuid(posix_getuid());
65
-	$configUser = posix_getpwuid(fileowner(OC::$configDir . 'config.php'));
66
-	if ($user['name'] !== $configUser['name']) {
67
-		echo "Console has to be executed with the user that owns the file config/config.php" . PHP_EOL;
68
-		echo "Current user: " . $user['name'] . PHP_EOL;
69
-		echo "Owner of config.php: " . $configUser['name'] . PHP_EOL;
70
-		echo "Try adding 'sudo -u " . $configUser['name'] . " ' to the beginning of the command (without the single quotes)" . PHP_EOL;
71
-		exit(1);
72
-	}
60
+    if (!function_exists('posix_getuid')) {
61
+        echo "The posix extensions are required - see http://php.net/manual/en/book.posix.php" . PHP_EOL;
62
+        exit(1);
63
+    }
64
+    $user = posix_getpwuid(posix_getuid());
65
+    $configUser = posix_getpwuid(fileowner(OC::$configDir . 'config.php'));
66
+    if ($user['name'] !== $configUser['name']) {
67
+        echo "Console has to be executed with the user that owns the file config/config.php" . PHP_EOL;
68
+        echo "Current user: " . $user['name'] . PHP_EOL;
69
+        echo "Owner of config.php: " . $configUser['name'] . PHP_EOL;
70
+        echo "Try adding 'sudo -u " . $configUser['name'] . " ' to the beginning of the command (without the single quotes)" . PHP_EOL;
71
+        exit(1);
72
+    }
73 73
 
74
-	$oldWorkingDir = getcwd();
75
-	if ($oldWorkingDir === false) {
76
-		echo "This script can be run from the Nextcloud root directory only." . PHP_EOL;
77
-		echo "Can't determine current working dir - the script will continue to work but be aware of the above fact." . PHP_EOL;
78
-	} else if ($oldWorkingDir !== __DIR__ && !chdir(__DIR__)) {
79
-		echo "This script can be run from the Nextcloud root directory only." . PHP_EOL;
80
-		echo "Can't change to Nextcloud root directory." . PHP_EOL;
81
-		exit(1);
82
-	}
74
+    $oldWorkingDir = getcwd();
75
+    if ($oldWorkingDir === false) {
76
+        echo "This script can be run from the Nextcloud root directory only." . PHP_EOL;
77
+        echo "Can't determine current working dir - the script will continue to work but be aware of the above fact." . PHP_EOL;
78
+    } else if ($oldWorkingDir !== __DIR__ && !chdir(__DIR__)) {
79
+        echo "This script can be run from the Nextcloud root directory only." . PHP_EOL;
80
+        echo "Can't change to Nextcloud root directory." . PHP_EOL;
81
+        exit(1);
82
+    }
83 83
 
84
-	if (!function_exists('pcntl_signal') && !in_array('--no-warnings', $argv)) {
85
-		echo "The process control (PCNTL) extensions are required in case you want to interrupt long running commands - see http://php.net/manual/en/book.pcntl.php" . PHP_EOL;
86
-	}
84
+    if (!function_exists('pcntl_signal') && !in_array('--no-warnings', $argv)) {
85
+        echo "The process control (PCNTL) extensions are required in case you want to interrupt long running commands - see http://php.net/manual/en/book.pcntl.php" . PHP_EOL;
86
+    }
87 87
 
88
-	$application = new Application(
89
-		\OC::$server->getConfig(),
90
-		\OC::$server->getEventDispatcher(),
91
-		\OC::$server->getRequest(),
92
-		\OC::$server->getLogger(),
93
-		\OC::$server->query(\OC\MemoryInfo::class)
94
-	);
95
-	$application->loadCommands(new ArgvInput(), new ConsoleOutput());
96
-	$application->run();
88
+    $application = new Application(
89
+        \OC::$server->getConfig(),
90
+        \OC::$server->getEventDispatcher(),
91
+        \OC::$server->getRequest(),
92
+        \OC::$server->getLogger(),
93
+        \OC::$server->query(\OC\MemoryInfo::class)
94
+    );
95
+    $application->loadCommands(new ArgvInput(), new ConsoleOutput());
96
+    $application->run();
97 97
 } catch (Exception $ex) {
98
-	exceptionHandler($ex);
98
+    exceptionHandler($ex);
99 99
 } catch (Error $ex) {
100
-	exceptionHandler($ex);
100
+    exceptionHandler($ex);
101 101
 }
Please login to merge, or discard this patch.
Spacing   +15 added lines, -15 removed lines patch added patch discarded remove patch
@@ -29,7 +29,7 @@  discard block
 block discarded – undo
29 29
  *
30 30
  */
31 31
 
32
-require_once __DIR__ . '/lib/versioncheck.php';
32
+require_once __DIR__.'/lib/versioncheck.php';
33 33
 
34 34
 use OC\Console\Application;
35 35
 use Symfony\Component\Console\Input\ArgvInput;
@@ -38,12 +38,12 @@  discard block
 block discarded – undo
38 38
 define('OC_CONSOLE', 1);
39 39
 
40 40
 function exceptionHandler($exception) {
41
-	echo "An unhandled exception has been thrown:" . PHP_EOL;
41
+	echo "An unhandled exception has been thrown:".PHP_EOL;
42 42
 	echo $exception;
43 43
 	exit(1);
44 44
 }
45 45
 try {
46
-	require_once __DIR__ . '/lib/base.php';
46
+	require_once __DIR__.'/lib/base.php';
47 47
 
48 48
 	// set to run indefinitely if needed
49 49
 	if (strpos(@ini_get('disable_functions'), 'set_time_limit') === false) {
@@ -51,38 +51,38 @@  discard block
 block discarded – undo
51 51
 	}
52 52
 
53 53
 	if (!OC::$CLI) {
54
-		echo "This script can be run from the command line only" . PHP_EOL;
54
+		echo "This script can be run from the command line only".PHP_EOL;
55 55
 		exit(1);
56 56
 	}
57 57
 
58 58
 	set_exception_handler('exceptionHandler');
59 59
 
60 60
 	if (!function_exists('posix_getuid')) {
61
-		echo "The posix extensions are required - see http://php.net/manual/en/book.posix.php" . PHP_EOL;
61
+		echo "The posix extensions are required - see http://php.net/manual/en/book.posix.php".PHP_EOL;
62 62
 		exit(1);
63 63
 	}
64 64
 	$user = posix_getpwuid(posix_getuid());
65
-	$configUser = posix_getpwuid(fileowner(OC::$configDir . 'config.php'));
65
+	$configUser = posix_getpwuid(fileowner(OC::$configDir.'config.php'));
66 66
 	if ($user['name'] !== $configUser['name']) {
67
-		echo "Console has to be executed with the user that owns the file config/config.php" . PHP_EOL;
68
-		echo "Current user: " . $user['name'] . PHP_EOL;
69
-		echo "Owner of config.php: " . $configUser['name'] . PHP_EOL;
70
-		echo "Try adding 'sudo -u " . $configUser['name'] . " ' to the beginning of the command (without the single quotes)" . PHP_EOL;
67
+		echo "Console has to be executed with the user that owns the file config/config.php".PHP_EOL;
68
+		echo "Current user: ".$user['name'].PHP_EOL;
69
+		echo "Owner of config.php: ".$configUser['name'].PHP_EOL;
70
+		echo "Try adding 'sudo -u ".$configUser['name']." ' to the beginning of the command (without the single quotes)".PHP_EOL;
71 71
 		exit(1);
72 72
 	}
73 73
 
74 74
 	$oldWorkingDir = getcwd();
75 75
 	if ($oldWorkingDir === false) {
76
-		echo "This script can be run from the Nextcloud root directory only." . PHP_EOL;
77
-		echo "Can't determine current working dir - the script will continue to work but be aware of the above fact." . PHP_EOL;
76
+		echo "This script can be run from the Nextcloud root directory only.".PHP_EOL;
77
+		echo "Can't determine current working dir - the script will continue to work but be aware of the above fact.".PHP_EOL;
78 78
 	} else if ($oldWorkingDir !== __DIR__ && !chdir(__DIR__)) {
79
-		echo "This script can be run from the Nextcloud root directory only." . PHP_EOL;
80
-		echo "Can't change to Nextcloud root directory." . PHP_EOL;
79
+		echo "This script can be run from the Nextcloud root directory only.".PHP_EOL;
80
+		echo "Can't change to Nextcloud root directory.".PHP_EOL;
81 81
 		exit(1);
82 82
 	}
83 83
 
84 84
 	if (!function_exists('pcntl_signal') && !in_array('--no-warnings', $argv)) {
85
-		echo "The process control (PCNTL) extensions are required in case you want to interrupt long running commands - see http://php.net/manual/en/book.pcntl.php" . PHP_EOL;
85
+		echo "The process control (PCNTL) extensions are required in case you want to interrupt long running commands - see http://php.net/manual/en/book.pcntl.php".PHP_EOL;
86 86
 	}
87 87
 
88 88
 	$application = new Application(
Please login to merge, or discard this patch.
lib/private/Console/Application.php 2 patches
Indentation   +173 added lines, -173 removed lines patch added patch discarded remove patch
@@ -45,187 +45,187 @@
 block discarded – undo
45 45
 use Symfony\Component\EventDispatcher\EventDispatcherInterface;
46 46
 
47 47
 class Application {
48
-	/** @var IConfig */
49
-	private $config;
50
-	/** @var EventDispatcherInterface */
51
-	private $dispatcher;
52
-	/** @var IRequest */
53
-	private $request;
54
-	/** @var ILogger  */
55
-	private $logger;
56
-	/** @var MemoryInfo */
57
-	private $memoryInfo;
48
+    /** @var IConfig */
49
+    private $config;
50
+    /** @var EventDispatcherInterface */
51
+    private $dispatcher;
52
+    /** @var IRequest */
53
+    private $request;
54
+    /** @var ILogger  */
55
+    private $logger;
56
+    /** @var MemoryInfo */
57
+    private $memoryInfo;
58 58
 
59
-	/**
60
-	 * @param IConfig $config
61
-	 * @param EventDispatcherInterface $dispatcher
62
-	 * @param IRequest $request
63
-	 * @param ILogger $logger
64
-	 * @param MemoryInfo $memoryInfo
65
-	 */
66
-	public function __construct(IConfig $config,
67
-								EventDispatcherInterface $dispatcher,
68
-								IRequest $request,
69
-								ILogger $logger,
70
-								MemoryInfo $memoryInfo) {
71
-		$defaults = \OC::$server->getThemingDefaults();
72
-		$this->config = $config;
73
-		$this->application = new SymfonyApplication($defaults->getName(), \OC_Util::getVersionString());
74
-		$this->dispatcher = $dispatcher;
75
-		$this->request = $request;
76
-		$this->logger = $logger;
77
-		$this->memoryInfo = $memoryInfo;
78
-	}
59
+    /**
60
+     * @param IConfig $config
61
+     * @param EventDispatcherInterface $dispatcher
62
+     * @param IRequest $request
63
+     * @param ILogger $logger
64
+     * @param MemoryInfo $memoryInfo
65
+     */
66
+    public function __construct(IConfig $config,
67
+                                EventDispatcherInterface $dispatcher,
68
+                                IRequest $request,
69
+                                ILogger $logger,
70
+                                MemoryInfo $memoryInfo) {
71
+        $defaults = \OC::$server->getThemingDefaults();
72
+        $this->config = $config;
73
+        $this->application = new SymfonyApplication($defaults->getName(), \OC_Util::getVersionString());
74
+        $this->dispatcher = $dispatcher;
75
+        $this->request = $request;
76
+        $this->logger = $logger;
77
+        $this->memoryInfo = $memoryInfo;
78
+    }
79 79
 
80
-	/**
81
-	 * @param InputInterface $input
82
-	 * @param ConsoleOutputInterface $output
83
-	 * @throws \Exception
84
-	 */
85
-	public function loadCommands(
86
-		InputInterface $input,
87
-		ConsoleOutputInterface $output
88
-	) {
89
-		// $application is required to be defined in the register_command scripts
90
-		$application = $this->application;
91
-		$inputDefinition = $application->getDefinition();
92
-		$inputDefinition->addOption(
93
-			new InputOption(
94
-				'no-warnings', 
95
-				null, 
96
-				InputOption::VALUE_NONE, 
97
-				'Skip global warnings, show command output only', 
98
-				null
99
-			)
100
-		);
101
-		try {
102
-			$input->bind($inputDefinition);
103
-		} catch (\RuntimeException $e) {
104
-			//expected if there are extra options
105
-		}
106
-		if ($input->getOption('no-warnings')) {
107
-			$output->setVerbosity(OutputInterface::VERBOSITY_QUIET);
108
-		}
80
+    /**
81
+     * @param InputInterface $input
82
+     * @param ConsoleOutputInterface $output
83
+     * @throws \Exception
84
+     */
85
+    public function loadCommands(
86
+        InputInterface $input,
87
+        ConsoleOutputInterface $output
88
+    ) {
89
+        // $application is required to be defined in the register_command scripts
90
+        $application = $this->application;
91
+        $inputDefinition = $application->getDefinition();
92
+        $inputDefinition->addOption(
93
+            new InputOption(
94
+                'no-warnings', 
95
+                null, 
96
+                InputOption::VALUE_NONE, 
97
+                'Skip global warnings, show command output only', 
98
+                null
99
+            )
100
+        );
101
+        try {
102
+            $input->bind($inputDefinition);
103
+        } catch (\RuntimeException $e) {
104
+            //expected if there are extra options
105
+        }
106
+        if ($input->getOption('no-warnings')) {
107
+            $output->setVerbosity(OutputInterface::VERBOSITY_QUIET);
108
+        }
109 109
 
110
-		if ($this->memoryInfo->isMemoryLimitSufficient() === false) {
111
-			$output->getErrorOutput()->writeln(
112
-				'<comment>The current PHP memory limit ' .
113
-				'is below the recommended value of 512MB.</comment>'
114
-			);
115
-		}
110
+        if ($this->memoryInfo->isMemoryLimitSufficient() === false) {
111
+            $output->getErrorOutput()->writeln(
112
+                '<comment>The current PHP memory limit ' .
113
+                'is below the recommended value of 512MB.</comment>'
114
+            );
115
+        }
116 116
 
117
-		try {
118
-			require_once __DIR__ . '/../../../core/register_command.php';
119
-			if ($this->config->getSystemValue('installed', false)) {
120
-				if (\OCP\Util::needUpgrade()) {
121
-					throw new NeedsUpdateException();
122
-				} elseif ($this->config->getSystemValue('maintenance', false)) {
123
-					$this->writeMaintenanceModeInfo($input, $output);
124
-				} else {
125
-					OC_App::loadApps();
126
-					foreach (\OC::$server->getAppManager()->getInstalledApps() as $app) {
127
-						$appPath = \OC_App::getAppPath($app);
128
-						if ($appPath === false) {
129
-							continue;
130
-						}
131
-						// load commands using info.xml
132
-						$info = \OC_App::getAppInfo($app);
133
-						if (isset($info['commands'])) {
134
-							$this->loadCommandsFromInfoXml($info['commands']);
135
-						}
136
-						// load from register_command.php
137
-						\OC_App::registerAutoloading($app, $appPath);
138
-						$file = $appPath . '/appinfo/register_command.php';
139
-						if (file_exists($file)) {
140
-							try {
141
-								require $file;
142
-							} catch (\Exception $e) {
143
-								$this->logger->logException($e);
144
-							}
145
-						}
146
-					}
147
-				}
148
-			} else if ($input->getArgument('command') !== '_completion' && $input->getArgument('command') !== 'maintenance:install') {
149
-				$output->writeln("Nextcloud is not installed - only a limited number of commands are available");
150
-			}
151
-		} catch(NeedsUpdateException $e) {
152
-			if ($input->getArgument('command') !== '_completion') {
153
-				$output->writeln("Nextcloud or one of the apps require upgrade - only a limited number of commands are available");
154
-				$output->writeln("You may use your browser or the occ upgrade command to do the upgrade");
155
-			}
156
-		}
117
+        try {
118
+            require_once __DIR__ . '/../../../core/register_command.php';
119
+            if ($this->config->getSystemValue('installed', false)) {
120
+                if (\OCP\Util::needUpgrade()) {
121
+                    throw new NeedsUpdateException();
122
+                } elseif ($this->config->getSystemValue('maintenance', false)) {
123
+                    $this->writeMaintenanceModeInfo($input, $output);
124
+                } else {
125
+                    OC_App::loadApps();
126
+                    foreach (\OC::$server->getAppManager()->getInstalledApps() as $app) {
127
+                        $appPath = \OC_App::getAppPath($app);
128
+                        if ($appPath === false) {
129
+                            continue;
130
+                        }
131
+                        // load commands using info.xml
132
+                        $info = \OC_App::getAppInfo($app);
133
+                        if (isset($info['commands'])) {
134
+                            $this->loadCommandsFromInfoXml($info['commands']);
135
+                        }
136
+                        // load from register_command.php
137
+                        \OC_App::registerAutoloading($app, $appPath);
138
+                        $file = $appPath . '/appinfo/register_command.php';
139
+                        if (file_exists($file)) {
140
+                            try {
141
+                                require $file;
142
+                            } catch (\Exception $e) {
143
+                                $this->logger->logException($e);
144
+                            }
145
+                        }
146
+                    }
147
+                }
148
+            } else if ($input->getArgument('command') !== '_completion' && $input->getArgument('command') !== 'maintenance:install') {
149
+                $output->writeln("Nextcloud is not installed - only a limited number of commands are available");
150
+            }
151
+        } catch(NeedsUpdateException $e) {
152
+            if ($input->getArgument('command') !== '_completion') {
153
+                $output->writeln("Nextcloud or one of the apps require upgrade - only a limited number of commands are available");
154
+                $output->writeln("You may use your browser or the occ upgrade command to do the upgrade");
155
+            }
156
+        }
157 157
 
158
-		if ($input->getFirstArgument() !== 'check') {
159
-			$errors = \OC_Util::checkServer(\OC::$server->getSystemConfig());
160
-			if (!empty($errors)) {
161
-				foreach ($errors as $error) {
162
-					$output->writeln((string)$error['error']);
163
-					$output->writeln((string)$error['hint']);
164
-					$output->writeln('');
165
-				}
166
-				throw new \Exception("Environment not properly prepared.");
167
-			}
168
-		}
169
-	}
158
+        if ($input->getFirstArgument() !== 'check') {
159
+            $errors = \OC_Util::checkServer(\OC::$server->getSystemConfig());
160
+            if (!empty($errors)) {
161
+                foreach ($errors as $error) {
162
+                    $output->writeln((string)$error['error']);
163
+                    $output->writeln((string)$error['hint']);
164
+                    $output->writeln('');
165
+                }
166
+                throw new \Exception("Environment not properly prepared.");
167
+            }
168
+        }
169
+    }
170 170
 
171
-	/**
172
-	 * Write a maintenance mode info.
173
-	 * The commands "_completion" and "maintenance:mode" are excluded.
174
-	 *
175
-	 * @param InputInterface $input The input implementation for reading inputs.
176
-	 * @param ConsoleOutputInterface $output The output implementation
177
-	 * for writing outputs.
178
-	 * @return void
179
-	 */
180
-	private function writeMaintenanceModeInfo(
181
-		InputInterface $input, ConsoleOutputInterface $output
182
-	) {
183
-		if ($input->getArgument('command') !== '_completion'
184
-			&& $input->getArgument('command') !== 'maintenance:mode') {
185
-			$errOutput = $output->getErrorOutput();
186
-			$errOutput->writeln(
187
-				'<comment>Nextcloud is in maintenance mode - ' .
188
-				'no apps have been loaded</comment>' . PHP_EOL
189
-			);
190
-		}
191
-	}
171
+    /**
172
+     * Write a maintenance mode info.
173
+     * The commands "_completion" and "maintenance:mode" are excluded.
174
+     *
175
+     * @param InputInterface $input The input implementation for reading inputs.
176
+     * @param ConsoleOutputInterface $output The output implementation
177
+     * for writing outputs.
178
+     * @return void
179
+     */
180
+    private function writeMaintenanceModeInfo(
181
+        InputInterface $input, ConsoleOutputInterface $output
182
+    ) {
183
+        if ($input->getArgument('command') !== '_completion'
184
+            && $input->getArgument('command') !== 'maintenance:mode') {
185
+            $errOutput = $output->getErrorOutput();
186
+            $errOutput->writeln(
187
+                '<comment>Nextcloud is in maintenance mode - ' .
188
+                'no apps have been loaded</comment>' . PHP_EOL
189
+            );
190
+        }
191
+    }
192 192
 
193
-	/**
194
-	 * Sets whether to automatically exit after a command execution or not.
195
-	 *
196
-	 * @param bool $boolean Whether to automatically exit after a command execution or not
197
-	 */
198
-	public function setAutoExit($boolean) {
199
-		$this->application->setAutoExit($boolean);
200
-	}
193
+    /**
194
+     * Sets whether to automatically exit after a command execution or not.
195
+     *
196
+     * @param bool $boolean Whether to automatically exit after a command execution or not
197
+     */
198
+    public function setAutoExit($boolean) {
199
+        $this->application->setAutoExit($boolean);
200
+    }
201 201
 
202
-	/**
203
-	 * @param InputInterface $input
204
-	 * @param OutputInterface $output
205
-	 * @return int
206
-	 * @throws \Exception
207
-	 */
208
-	public function run(InputInterface $input = null, OutputInterface $output = null) {
209
-		$this->dispatcher->dispatch(ConsoleEvent::EVENT_RUN, new ConsoleEvent(
210
-			ConsoleEvent::EVENT_RUN,
211
-			$this->request->server['argv']
212
-		));
213
-		return $this->application->run($input, $output);
214
-	}
202
+    /**
203
+     * @param InputInterface $input
204
+     * @param OutputInterface $output
205
+     * @return int
206
+     * @throws \Exception
207
+     */
208
+    public function run(InputInterface $input = null, OutputInterface $output = null) {
209
+        $this->dispatcher->dispatch(ConsoleEvent::EVENT_RUN, new ConsoleEvent(
210
+            ConsoleEvent::EVENT_RUN,
211
+            $this->request->server['argv']
212
+        ));
213
+        return $this->application->run($input, $output);
214
+    }
215 215
 
216
-	private function loadCommandsFromInfoXml($commands) {
217
-		foreach ($commands as $command) {
218
-			try {
219
-				$c = \OC::$server->query($command);
220
-			} catch (QueryException $e) {
221
-				if (class_exists($command)) {
222
-					$c = new $command();
223
-				} else {
224
-					throw new \Exception("Console command '$command' is unknown and could not be loaded");
225
-				}
226
-			}
216
+    private function loadCommandsFromInfoXml($commands) {
217
+        foreach ($commands as $command) {
218
+            try {
219
+                $c = \OC::$server->query($command);
220
+            } catch (QueryException $e) {
221
+                if (class_exists($command)) {
222
+                    $c = new $command();
223
+                } else {
224
+                    throw new \Exception("Console command '$command' is unknown and could not be loaded");
225
+                }
226
+            }
227 227
 
228
-			$this->application->add($c);
229
-		}
230
-	}
228
+            $this->application->add($c);
229
+        }
230
+    }
231 231
 }
Please login to merge, or discard this patch.
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -109,13 +109,13 @@  discard block
 block discarded – undo
109 109
 
110 110
 		if ($this->memoryInfo->isMemoryLimitSufficient() === false) {
111 111
 			$output->getErrorOutput()->writeln(
112
-				'<comment>The current PHP memory limit ' .
112
+				'<comment>The current PHP memory limit '.
113 113
 				'is below the recommended value of 512MB.</comment>'
114 114
 			);
115 115
 		}
116 116
 
117 117
 		try {
118
-			require_once __DIR__ . '/../../../core/register_command.php';
118
+			require_once __DIR__.'/../../../core/register_command.php';
119 119
 			if ($this->config->getSystemValue('installed', false)) {
120 120
 				if (\OCP\Util::needUpgrade()) {
121 121
 					throw new NeedsUpdateException();
@@ -135,7 +135,7 @@  discard block
 block discarded – undo
135 135
 						}
136 136
 						// load from register_command.php
137 137
 						\OC_App::registerAutoloading($app, $appPath);
138
-						$file = $appPath . '/appinfo/register_command.php';
138
+						$file = $appPath.'/appinfo/register_command.php';
139 139
 						if (file_exists($file)) {
140 140
 							try {
141 141
 								require $file;
@@ -148,7 +148,7 @@  discard block
 block discarded – undo
148 148
 			} else if ($input->getArgument('command') !== '_completion' && $input->getArgument('command') !== 'maintenance:install') {
149 149
 				$output->writeln("Nextcloud is not installed - only a limited number of commands are available");
150 150
 			}
151
-		} catch(NeedsUpdateException $e) {
151
+		} catch (NeedsUpdateException $e) {
152 152
 			if ($input->getArgument('command') !== '_completion') {
153 153
 				$output->writeln("Nextcloud or one of the apps require upgrade - only a limited number of commands are available");
154 154
 				$output->writeln("You may use your browser or the occ upgrade command to do the upgrade");
@@ -159,8 +159,8 @@  discard block
 block discarded – undo
159 159
 			$errors = \OC_Util::checkServer(\OC::$server->getSystemConfig());
160 160
 			if (!empty($errors)) {
161 161
 				foreach ($errors as $error) {
162
-					$output->writeln((string)$error['error']);
163
-					$output->writeln((string)$error['hint']);
162
+					$output->writeln((string) $error['error']);
163
+					$output->writeln((string) $error['hint']);
164 164
 					$output->writeln('');
165 165
 				}
166 166
 				throw new \Exception("Environment not properly prepared.");
@@ -184,8 +184,8 @@  discard block
 block discarded – undo
184 184
 			&& $input->getArgument('command') !== 'maintenance:mode') {
185 185
 			$errOutput = $output->getErrorOutput();
186 186
 			$errOutput->writeln(
187
-				'<comment>Nextcloud is in maintenance mode - ' .
188
-				'no apps have been loaded</comment>' . PHP_EOL
187
+				'<comment>Nextcloud is in maintenance mode - '.
188
+				'no apps have been loaded</comment>'.PHP_EOL
189 189
 			);
190 190
 		}
191 191
 	}
Please login to merge, or discard this patch.
lib/private/MemoryInfo.php 2 patches
Indentation   +45 added lines, -45 removed lines patch added patch discarded remove patch
@@ -28,54 +28,54 @@
 block discarded – undo
28 28
  */
29 29
 class MemoryInfo {
30 30
 
31
-	const RECOMMENDED_MEMORY_LIMIT = 512 * 1024 * 1024;
31
+    const RECOMMENDED_MEMORY_LIMIT = 512 * 1024 * 1024;
32 32
 
33
-	/**
34
-	 * Tests if the memory limit is greater or equal the recommended value.
35
-	 *
36
-	 * @return bool
37
-	 */
38
-	public function isMemoryLimitSufficient(): bool {
39
-		$memoryLimit = $this->getMemoryLimit();
40
-		return $memoryLimit === -1 || $memoryLimit >= self::RECOMMENDED_MEMORY_LIMIT;
41
-	}
33
+    /**
34
+     * Tests if the memory limit is greater or equal the recommended value.
35
+     *
36
+     * @return bool
37
+     */
38
+    public function isMemoryLimitSufficient(): bool {
39
+        $memoryLimit = $this->getMemoryLimit();
40
+        return $memoryLimit === -1 || $memoryLimit >= self::RECOMMENDED_MEMORY_LIMIT;
41
+    }
42 42
 
43
-	/**
44
-	 * Returns the php memory limit.
45
-	 *
46
-	 * @return int The memory limit in bytes.
47
-	 */
48
-	public function getMemoryLimit(): int {
49
-		$iniValue = trim(ini_get('memory_limit'));
50
-		if ($iniValue === '-1') {
51
-			return -1;
52
-		} else if (is_numeric($iniValue) === true) {
53
-			return (int)$iniValue;
54
-		} else {
55
-			return $this->memoryLimitToBytes($iniValue);
56
-		}
57
-	}
43
+    /**
44
+     * Returns the php memory limit.
45
+     *
46
+     * @return int The memory limit in bytes.
47
+     */
48
+    public function getMemoryLimit(): int {
49
+        $iniValue = trim(ini_get('memory_limit'));
50
+        if ($iniValue === '-1') {
51
+            return -1;
52
+        } else if (is_numeric($iniValue) === true) {
53
+            return (int)$iniValue;
54
+        } else {
55
+            return $this->memoryLimitToBytes($iniValue);
56
+        }
57
+    }
58 58
 
59
-	/**
60
-	 * Converts the ini memory limit to bytes.
61
-	 *
62
-	 * @param string $memoryLimit The "memory_limit" ini value
63
-	 * @return int
64
-	 */
65
-	private function memoryLimitToBytes(string $memoryLimit): int {
66
-		$last = strtolower(substr($memoryLimit, -1));
67
-		$memoryLimit = (int)substr($memoryLimit, 0, -1);
59
+    /**
60
+     * Converts the ini memory limit to bytes.
61
+     *
62
+     * @param string $memoryLimit The "memory_limit" ini value
63
+     * @return int
64
+     */
65
+    private function memoryLimitToBytes(string $memoryLimit): int {
66
+        $last = strtolower(substr($memoryLimit, -1));
67
+        $memoryLimit = (int)substr($memoryLimit, 0, -1);
68 68
 
69
-		// intended fall trough
70
-		switch($last) {
71
-			case 'g':
72
-				$memoryLimit *= 1024;
73
-			case 'm':
74
-				$memoryLimit *= 1024;
75
-			case 'k':
76
-				$memoryLimit *= 1024;
77
-		}
69
+        // intended fall trough
70
+        switch($last) {
71
+            case 'g':
72
+                $memoryLimit *= 1024;
73
+            case 'm':
74
+                $memoryLimit *= 1024;
75
+            case 'k':
76
+                $memoryLimit *= 1024;
77
+        }
78 78
 
79
-		return $memoryLimit;
80
-	}
79
+        return $memoryLimit;
80
+    }
81 81
 }
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -50,7 +50,7 @@  discard block
 block discarded – undo
50 50
 		if ($iniValue === '-1') {
51 51
 			return -1;
52 52
 		} else if (is_numeric($iniValue) === true) {
53
-			return (int)$iniValue;
53
+			return (int) $iniValue;
54 54
 		} else {
55 55
 			return $this->memoryLimitToBytes($iniValue);
56 56
 		}
@@ -64,10 +64,10 @@  discard block
 block discarded – undo
64 64
 	 */
65 65
 	private function memoryLimitToBytes(string $memoryLimit): int {
66 66
 		$last = strtolower(substr($memoryLimit, -1));
67
-		$memoryLimit = (int)substr($memoryLimit, 0, -1);
67
+		$memoryLimit = (int) substr($memoryLimit, 0, -1);
68 68
 
69 69
 		// intended fall trough
70
-		switch($last) {
70
+		switch ($last) {
71 71
 			case 'g':
72 72
 				$memoryLimit *= 1024;
73 73
 			case 'm':
Please login to merge, or discard this patch.