Passed
Push — master ( 736fbe...3f4941 )
by Roeland
13:30
created
lib/base.php 1 patch
Spacing   +56 added lines, -56 removed lines patch added patch discarded remove patch
@@ -128,14 +128,14 @@  discard block
 block discarded – undo
128 128
 	 * the app path list is empty or contains an invalid path
129 129
 	 */
130 130
 	public static function initPaths() {
131
-		if(defined('PHPUNIT_CONFIG_DIR')) {
132
-			self::$configDir = OC::$SERVERROOT . '/' . PHPUNIT_CONFIG_DIR . '/';
133
-		} elseif(defined('PHPUNIT_RUN') and PHPUNIT_RUN and is_dir(OC::$SERVERROOT . '/tests/config/')) {
134
-			self::$configDir = OC::$SERVERROOT . '/tests/config/';
135
-		} elseif($dir = getenv('NEXTCLOUD_CONFIG_DIR')) {
136
-			self::$configDir = rtrim($dir, '/') . '/';
131
+		if (defined('PHPUNIT_CONFIG_DIR')) {
132
+			self::$configDir = OC::$SERVERROOT.'/'.PHPUNIT_CONFIG_DIR.'/';
133
+		} elseif (defined('PHPUNIT_RUN') and PHPUNIT_RUN and is_dir(OC::$SERVERROOT.'/tests/config/')) {
134
+			self::$configDir = OC::$SERVERROOT.'/tests/config/';
135
+		} elseif ($dir = getenv('NEXTCLOUD_CONFIG_DIR')) {
136
+			self::$configDir = rtrim($dir, '/').'/';
137 137
 		} else {
138
-			self::$configDir = OC::$SERVERROOT . '/config/';
138
+			self::$configDir = OC::$SERVERROOT.'/config/';
139 139
 		}
140 140
 		self::$config = new \OC\Config(self::$configDir);
141 141
 
@@ -157,9 +157,9 @@  discard block
 block discarded – undo
157 157
 			//make sure suburi follows the same rules as scriptName
158 158
 			if (substr(OC::$SUBURI, -9) != 'index.php') {
159 159
 				if (substr(OC::$SUBURI, -1) != '/') {
160
-					OC::$SUBURI = OC::$SUBURI . '/';
160
+					OC::$SUBURI = OC::$SUBURI.'/';
161 161
 				}
162
-				OC::$SUBURI = OC::$SUBURI . 'index.php';
162
+				OC::$SUBURI = OC::$SUBURI.'index.php';
163 163
 			}
164 164
 		}
165 165
 
@@ -171,7 +171,7 @@  discard block
 block discarded – undo
171 171
 				OC::$WEBROOT = substr($scriptName, 0, 0 - strlen(OC::$SUBURI));
172 172
 
173 173
 				if (OC::$WEBROOT != '' && OC::$WEBROOT[0] !== '/') {
174
-					OC::$WEBROOT = '/' . OC::$WEBROOT;
174
+					OC::$WEBROOT = '/'.OC::$WEBROOT;
175 175
 				}
176 176
 			} else {
177 177
 				// The scriptName is not ending with OC::$SUBURI
@@ -200,11 +200,11 @@  discard block
 block discarded – undo
200 200
 					OC::$APPSROOTS[] = $paths;
201 201
 				}
202 202
 			}
203
-		} elseif (file_exists(OC::$SERVERROOT . '/apps')) {
204
-			OC::$APPSROOTS[] = array('path' => OC::$SERVERROOT . '/apps', 'url' => '/apps', 'writable' => true);
205
-		} elseif (file_exists(OC::$SERVERROOT . '/../apps')) {
203
+		} elseif (file_exists(OC::$SERVERROOT.'/apps')) {
204
+			OC::$APPSROOTS[] = array('path' => OC::$SERVERROOT.'/apps', 'url' => '/apps', 'writable' => true);
205
+		} elseif (file_exists(OC::$SERVERROOT.'/../apps')) {
206 206
 			OC::$APPSROOTS[] = array(
207
-				'path' => rtrim(dirname(OC::$SERVERROOT), '/') . '/apps',
207
+				'path' => rtrim(dirname(OC::$SERVERROOT), '/').'/apps',
208 208
 				'url' => '/apps',
209 209
 				'writable' => true
210 210
 			);
@@ -234,8 +234,8 @@  discard block
 block discarded – undo
234 234
 		$l = \OC::$server->getL10N('lib');
235 235
 
236 236
 		// Create config if it does not already exist
237
-		$configFilePath = self::$configDir .'/config.php';
238
-		if(!file_exists($configFilePath)) {
237
+		$configFilePath = self::$configDir.'/config.php';
238
+		if (!file_exists($configFilePath)) {
239 239
 			@touch($configFilePath);
240 240
 		}
241 241
 
@@ -249,18 +249,18 @@  discard block
 block discarded – undo
249 249
 			if (self::$CLI) {
250 250
 				echo $l->t('Cannot write into "config" directory!')."\n";
251 251
 				echo $l->t('This can usually be fixed by giving the webserver write access to the config directory')."\n";
252
-				echo $l->t('See %s', [ $urlGenerator->linkToDocs('admin-dir_permissions') ])."\n";
252
+				echo $l->t('See %s', [$urlGenerator->linkToDocs('admin-dir_permissions')])."\n";
253 253
 				echo "\n";
254 254
 				echo $l->t('Or, if you prefer to keep config.php file read only, set the option "config_is_read_only" to true in it.')."\n";
255
-				echo $l->t('See %s', [ $urlGenerator->linkToDocs('admin-config') ])."\n";
255
+				echo $l->t('See %s', [$urlGenerator->linkToDocs('admin-config')])."\n";
256 256
 				exit;
257 257
 			} else {
258 258
 				OC_Template::printErrorPage(
259 259
 					$l->t('Cannot write into "config" directory!'),
260 260
 					$l->t('This can usually be fixed by giving the webserver write access to the config directory. See %s',
261
-					[ $urlGenerator->linkToDocs('admin-dir_permissions') ]) . '. '
261
+					[$urlGenerator->linkToDocs('admin-dir_permissions')]).'. '
262 262
 					. $l->t('Or, if you prefer to keep config.php file read only, set the option "config_is_read_only" to true in it. See %s',
263
-					[ $urlGenerator->linkToDocs('admin-config') ] ),
263
+					[$urlGenerator->linkToDocs('admin-config')]),
264 264
 					503
265 265
 				);
266 266
 			}
@@ -276,8 +276,8 @@  discard block
 block discarded – undo
276 276
 			if (OC::$CLI) {
277 277
 				throw new Exception('Not installed');
278 278
 			} else {
279
-				$url = OC::$WEBROOT . '/index.php';
280
-				header('Location: ' . $url);
279
+				$url = OC::$WEBROOT.'/index.php';
280
+				header('Location: '.$url);
281 281
 			}
282 282
 			exit();
283 283
 		}
@@ -382,14 +382,14 @@  discard block
 block discarded – undo
382 382
 		$incompatibleShippedApps = [];
383 383
 		foreach ($incompatibleApps as $appInfo) {
384 384
 			if ($appManager->isShipped($appInfo['id'])) {
385
-				$incompatibleShippedApps[] = $appInfo['name'] . ' (' . $appInfo['id'] . ')';
385
+				$incompatibleShippedApps[] = $appInfo['name'].' ('.$appInfo['id'].')';
386 386
 			}
387 387
 		}
388 388
 
389 389
 		if (!empty($incompatibleShippedApps)) {
390 390
 			$l = \OC::$server->getL10N('core');
391 391
 			$hint = $l->t('The files of the app %1$s were not replaced correctly. Make sure it is a version compatible with the server.', [implode(', ', $incompatibleShippedApps)]);
392
-			throw new \OC\HintException('The files of the app ' . implode(', ', $incompatibleShippedApps) . ' were not replaced correctly. Make sure it is a version compatible with the server.', $hint);
392
+			throw new \OC\HintException('The files of the app '.implode(', ', $incompatibleShippedApps).' were not replaced correctly. Make sure it is a version compatible with the server.', $hint);
393 393
 		}
394 394
 
395 395
 		$tmpl->assign('appsToUpgrade', $appManager->getAppsNeedingUpgrade($ocVersion));
@@ -400,7 +400,7 @@  discard block
 block discarded – undo
400 400
 	}
401 401
 
402 402
 	public static function initSession() {
403
-		if(self::$server->getRequest()->getServerProtocol() === 'https') {
403
+		if (self::$server->getRequest()->getServerProtocol() === 'https') {
404 404
 			ini_set('session.cookie_secure', true);
405 405
 		}
406 406
 
@@ -408,7 +408,7 @@  discard block
 block discarded – undo
408 408
 		ini_set('session.cookie_httponly', 'true');
409 409
 
410 410
 		// set the cookie path to the Nextcloud directory
411
-		$cookie_path = OC::$WEBROOT ? : '/';
411
+		$cookie_path = OC::$WEBROOT ?: '/';
412 412
 		ini_set('session.cookie_path', $cookie_path);
413 413
 
414 414
 		// Let the session name be changed in the initSession Hook
@@ -441,7 +441,7 @@  discard block
 block discarded – undo
441 441
 		// session timeout
442 442
 		if ($session->exists('LAST_ACTIVITY') && (time() - $session->get('LAST_ACTIVITY') > $sessionLifeTime)) {
443 443
 			if (isset($_COOKIE[session_name()])) {
444
-				setcookie(session_name(), '', -1, self::$WEBROOT ? : '/');
444
+				setcookie(session_name(), '', -1, self::$WEBROOT ?: '/');
445 445
 			}
446 446
 			\OC::$server->getUserSession()->logout();
447 447
 		}
@@ -477,14 +477,14 @@  discard block
 block discarded – undo
477 477
 
478 478
 		// Append __Host to the cookie if it meets the requirements
479 479
 		$cookiePrefix = '';
480
-		if($cookieParams['secure'] === true && $cookieParams['path'] === '/') {
480
+		if ($cookieParams['secure'] === true && $cookieParams['path'] === '/') {
481 481
 			$cookiePrefix = '__Host-';
482 482
 		}
483 483
 
484
-		foreach($policies as $policy) {
484
+		foreach ($policies as $policy) {
485 485
 			header(
486 486
 				sprintf(
487
-					'Set-Cookie: %snc_sameSiteCookie%s=true; path=%s; httponly;' . $secureCookie . 'expires=Fri, 31-Dec-2100 23:59:59 GMT; SameSite=%s',
487
+					'Set-Cookie: %snc_sameSiteCookie%s=true; path=%s; httponly;'.$secureCookie.'expires=Fri, 31-Dec-2100 23:59:59 GMT; SameSite=%s',
488 488
 					$cookiePrefix,
489 489
 					$policy,
490 490
 					$cookieParams['path'],
@@ -523,31 +523,31 @@  discard block
 block discarded – undo
523 523
 			];
524 524
 		}
525 525
 
526
-		if($request->isUserAgent($incompatibleUserAgents)) {
526
+		if ($request->isUserAgent($incompatibleUserAgents)) {
527 527
 			return;
528 528
 		}
529 529
 
530
-		if(count($_COOKIE) > 0) {
530
+		if (count($_COOKIE) > 0) {
531 531
 			$requestUri = $request->getScriptName();
532 532
 			$processingScript = explode('/', $requestUri);
533
-			$processingScript = $processingScript[count($processingScript)-1];
533
+			$processingScript = $processingScript[count($processingScript) - 1];
534 534
 
535 535
 			// index.php routes are handled in the middleware
536
-			if($processingScript === 'index.php') {
536
+			if ($processingScript === 'index.php') {
537 537
 				return;
538 538
 			}
539 539
 
540 540
 			// All other endpoints require the lax and the strict cookie
541
-			if(!$request->passesStrictCookieCheck()) {
541
+			if (!$request->passesStrictCookieCheck()) {
542 542
 				self::sendSameSiteCookies();
543 543
 				// Debug mode gets access to the resources without strict cookie
544 544
 				// due to the fact that the SabreDAV browser also lives there.
545
-				if(!\OC::$server->getConfig()->getSystemValue('debug', false)) {
545
+				if (!\OC::$server->getConfig()->getSystemValue('debug', false)) {
546 546
 					http_response_code(\OCP\AppFramework\Http::STATUS_SERVICE_UNAVAILABLE);
547 547
 					exit();
548 548
 				}
549 549
 			}
550
-		} elseif(!isset($_COOKIE['nc_sameSiteCookielax']) || !isset($_COOKIE['nc_sameSiteCookiestrict'])) {
550
+		} elseif (!isset($_COOKIE['nc_sameSiteCookielax']) || !isset($_COOKIE['nc_sameSiteCookiestrict'])) {
551 551
 			self::sendSameSiteCookies();
552 552
 		}
553 553
 	}
@@ -558,12 +558,12 @@  discard block
 block discarded – undo
558 558
 
559 559
 		// register autoloader
560 560
 		$loaderStart = microtime(true);
561
-		require_once __DIR__ . '/autoloader.php';
561
+		require_once __DIR__.'/autoloader.php';
562 562
 		self::$loader = new \OC\Autoloader([
563
-			OC::$SERVERROOT . '/lib/private/legacy',
563
+			OC::$SERVERROOT.'/lib/private/legacy',
564 564
 		]);
565 565
 		if (defined('PHPUNIT_RUN')) {
566
-			self::$loader->addValidRoot(OC::$SERVERROOT . '/tests');
566
+			self::$loader->addValidRoot(OC::$SERVERROOT.'/tests');
567 567
 		}
568 568
 		spl_autoload_register(array(self::$loader, 'load'));
569 569
 		$loaderEnd = microtime(true);
@@ -571,12 +571,12 @@  discard block
 block discarded – undo
571 571
 		self::$CLI = (php_sapi_name() == 'cli');
572 572
 
573 573
 		// Add default composer PSR-4 autoloader
574
-		self::$composerAutoloader = require_once OC::$SERVERROOT . '/lib/composer/autoload.php';
574
+		self::$composerAutoloader = require_once OC::$SERVERROOT.'/lib/composer/autoload.php';
575 575
 
576 576
 		try {
577 577
 			self::initPaths();
578 578
 			// setup 3rdparty autoloader
579
-			$vendorAutoLoad = OC::$SERVERROOT. '/3rdparty/autoload.php';
579
+			$vendorAutoLoad = OC::$SERVERROOT.'/3rdparty/autoload.php';
580 580
 			if (!file_exists($vendorAutoLoad)) {
581 581
 				throw new \RuntimeException('Composer autoloader not found, unable to continue. Check the folder "3rdparty". Running "git submodule update --init" will initialize the git submodule that handles the subfolder "3rdparty".');
582 582
 			}
@@ -602,7 +602,7 @@  discard block
 block discarded – undo
602 602
 		@ini_set('display_errors', '0');
603 603
 		@ini_set('log_errors', '1');
604 604
 
605
-		if(!date_default_timezone_set('UTC')) {
605
+		if (!date_default_timezone_set('UTC')) {
606 606
 			throw new \RuntimeException('Could not set timezone to UTC');
607 607
 		}
608 608
 
@@ -656,11 +656,11 @@  discard block
 block discarded – undo
656 656
 					// Convert l10n string into regular string for usage in database
657 657
 					$staticErrors = [];
658 658
 					foreach ($errors as $error) {
659
-						echo $error['error'] . "\n";
660
-						echo $error['hint'] . "\n\n";
659
+						echo $error['error']."\n";
660
+						echo $error['hint']."\n\n";
661 661
 						$staticErrors[] = [
662
-							'error' => (string)$error['error'],
663
-							'hint' => (string)$error['hint'],
662
+							'error' => (string) $error['error'],
663
+							'hint' => (string) $error['hint'],
664 664
 						];
665 665
 					}
666 666
 
@@ -682,7 +682,7 @@  discard block
 block discarded – undo
682 682
 		}
683 683
 		//try to set the session lifetime
684 684
 		$sessionLifeTime = self::getSessionLifeTime();
685
-		@ini_set('gc_maxlifetime', (string)$sessionLifeTime);
685
+		@ini_set('gc_maxlifetime', (string) $sessionLifeTime);
686 686
 
687 687
 		$systemConfig = \OC::$server->getSystemConfig();
688 688
 
@@ -731,7 +731,7 @@  discard block
 block discarded – undo
731 731
 		register_shutdown_function(array($lockProvider, 'releaseAll'));
732 732
 
733 733
 		// Check whether the sample configuration has been copied
734
-		if($systemConfig->getValue('copied_sample_config', false)) {
734
+		if ($systemConfig->getValue('copied_sample_config', false)) {
735 735
 			$l = \OC::$server->getL10N('lib');
736 736
 			OC_Template::printErrorPage(
737 737
 				$l->t('Sample configuration detected'),
@@ -756,11 +756,11 @@  discard block
 block discarded – undo
756 756
 		) {
757 757
 			// Allow access to CSS resources
758 758
 			$isScssRequest = false;
759
-			if(strpos($request->getPathInfo(), '/css/') === 0) {
759
+			if (strpos($request->getPathInfo(), '/css/') === 0) {
760 760
 				$isScssRequest = true;
761 761
 			}
762 762
 
763
-			if(substr($request->getRequestUri(), -11) === '/status.php') {
763
+			if (substr($request->getRequestUri(), -11) === '/status.php') {
764 764
 				http_response_code(400);
765 765
 				header('Content-Type: application/json');
766 766
 				echo '{"error": "Trusted domain error.", "code": 15}';
@@ -798,7 +798,7 @@  discard block
 block discarded – undo
798 798
 
799 799
 			// NOTE: This will be replaced to use OCP
800 800
 			$userSession = self::$server->getUserSession();
801
-			$userSession->listen('\OC\User', 'postLogin', function () use ($userSession) {
801
+			$userSession->listen('\OC\User', 'postLogin', function() use ($userSession) {
802 802
 				if (!defined('PHPUNIT_RUN')) {
803 803
 					// reset brute force delay for this IP address and username
804 804
 					$uid = \OC::$server->getUserSession()->getUser()->getUID();
@@ -936,12 +936,12 @@  discard block
 block discarded – undo
936 936
 		// emergency app disabling
937 937
 		if ($requestPath === '/disableapp'
938 938
 			&& $request->getMethod() === 'POST'
939
-			&& ((array)$request->getParam('appid')) !== ''
939
+			&& ((array) $request->getParam('appid')) !== ''
940 940
 		) {
941 941
 			\OC_JSON::callCheck();
942 942
 			\OC_JSON::checkAdminUser();
943
-			$appIds = (array)$request->getParam('appid');
944
-			foreach($appIds as $appId) {
943
+			$appIds = (array) $request->getParam('appid');
944
+			foreach ($appIds as $appId) {
945 945
 				$appId = \OC_App::cleanAppId($appId);
946 946
 				\OC::$server->getAppManager()->disableApp($appId);
947 947
 			}
@@ -956,7 +956,7 @@  discard block
 block discarded – undo
956 956
 		if (!\OCP\Util::needUpgrade()
957 957
 			&& !((bool) $systemConfig->getValue('maintenance', false))) {
958 958
 			// For logged-in users: Load everything
959
-			if(\OC::$server->getUserSession()->isLoggedIn()) {
959
+			if (\OC::$server->getUserSession()->isLoggedIn()) {
960 960
 				OC_App::loadApps();
961 961
 			} else {
962 962
 				// For guests: Load only filesystem and logging
Please login to merge, or discard this patch.