Skip to content

Commit 701fcbf

Browse files
Merge pull request #52853 from nextcloud/refactor/rector-top-level
2 parents cac44fd + 3b42c92 commit 701fcbf

File tree

7 files changed

+62
-29
lines changed

7 files changed

+62
-29
lines changed

build/rector.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,18 @@ public function shouldSkip(File $file, FullyQualifiedObjectType $fullyQualifiedO
5353
->withPaths([
5454
$nextcloudDir . '/apps',
5555
$nextcloudDir . '/core',
56+
$nextcloudDir . '/ocs',
57+
$nextcloudDir . '/ocs-provider',
58+
$nextcloudDir . '/console.php',
59+
$nextcloudDir . '/cron.php',
60+
$nextcloudDir . '/index.php',
61+
$nextcloudDir . '/occ',
62+
$nextcloudDir . '/public.php',
63+
$nextcloudDir . '/remote.php',
5664
$nextcloudDir . '/status.php',
65+
$nextcloudDir . '/version.php',
5766
// $nextcloudDir . '/config',
5867
// $nextcloudDir . '/lib',
59-
// $nextcloudDir . '/ocs',
60-
// $nextcloudDir . '/ocs-provider',
6168
// $nextcloudDir . '/tests',
6269
// $nextcloudDir . '/themes',
6370
])

console.php

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
declare(strict_types=1);
44

5+
use OCP\IConfig;
6+
use OCP\Server;
7+
58
/**
69
* SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
710
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
@@ -37,7 +40,7 @@ function exceptionHandler($exception) {
3740
exit(1);
3841
}
3942

40-
$config = \OCP\Server::get(\OCP\IConfig::class);
43+
$config = Server::get(IConfig::class);
4144
set_exception_handler('exceptionHandler');
4245

4346
if (!function_exists('posix_getuid')) {
@@ -71,10 +74,10 @@ function exceptionHandler($exception) {
7174
echo "Additionally the function 'pcntl_signal' and 'pcntl_signal_dispatch' need to be enabled in your php.ini." . PHP_EOL;
7275
}
7376

74-
$eventLogger = \OCP\Server::get(IEventLogger::class);
77+
$eventLogger = Server::get(IEventLogger::class);
7578
$eventLogger->start('console:build_application', 'Build Application instance and load commands');
7679

77-
$application = \OCP\Server::get(Application::class);
80+
$application = Server::get(Application::class);
7881
/* base.php will have removed eventual debug options from argv in $_SERVER */
7982
$argv = $_SERVER['argv'];
8083
$input = new ArgvInput($argv);
@@ -88,10 +91,10 @@ function exceptionHandler($exception) {
8891

8992
$eventLogger->end('console:run');
9093

91-
$profiler = \OCP\Server::get(IProfiler::class);
94+
$profiler = Server::get(IProfiler::class);
9295
if ($profiler->isEnabled()) {
9396
$eventLogger->end('runtime');
94-
$profile = $profiler->collect(\OCP\Server::get(IRequest::class), new Response());
97+
$profile = $profiler->collect(Server::get(IRequest::class), new Response());
9598
$profile->setMethod('occ');
9699
$profile->setUrl(implode(' ', $argv));
97100
$profiler->saveProfile($profile);

cron.php

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22

33
declare(strict_types=1);
44

5+
use OC\Files\SetupManager;
6+
use OC\Session\CryptoWrapper;
7+
use OC\Session\Memory;
8+
use OCP\ILogger;
9+
510
/**
611
* SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
712
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
@@ -64,8 +69,8 @@
6469
$verbose = isset($argv[1]) && ($argv[1] === '-v' || $argv[1] === '--verbose');
6570

6671
// initialize a dummy memory session
67-
$session = new \OC\Session\Memory();
68-
$cryptoWrapper = \OC::$server->getSessionCryptoWrapper();
72+
$session = new Memory();
73+
$cryptoWrapper = Server::get(CryptoWrapper::class);
6974
$session = $cryptoWrapper->wrapSession($session);
7075
\OC::$server->setSession($session);
7176

@@ -177,11 +182,11 @@
177182
$timeSpent = $timeAfter - $timeBefore;
178183
if ($timeSpent > $cronInterval) {
179184
$logLevel = match (true) {
180-
$timeSpent > $cronInterval * 128 => \OCP\ILogger::FATAL,
181-
$timeSpent > $cronInterval * 64 => \OCP\ILogger::ERROR,
182-
$timeSpent > $cronInterval * 16 => \OCP\ILogger::WARN,
183-
$timeSpent > $cronInterval * 8 => \OCP\ILogger::INFO,
184-
default => \OCP\ILogger::DEBUG,
185+
$timeSpent > $cronInterval * 128 => ILogger::FATAL,
186+
$timeSpent > $cronInterval * 64 => ILogger::ERROR,
187+
$timeSpent > $cronInterval * 16 => ILogger::WARN,
188+
$timeSpent > $cronInterval * 8 => ILogger::INFO,
189+
default => ILogger::DEBUG,
185190
};
186191
$logger->log(
187192
$logLevel,
@@ -206,7 +211,7 @@
206211
}
207212

208213
// clean up after unclean jobs
209-
Server::get(\OC\Files\SetupManager::class)->tearDown();
214+
Server::get(SetupManager::class)->tearDown();
210215
$tempManager->clean();
211216

212217
if ($verbose) {

ocs/providers.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
<?php
2+
3+
use OCP\IRequest;
4+
use OCP\Server;
5+
26
/**
37
* SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
48
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
@@ -9,7 +13,7 @@
913

1014
header('Content-type: application/xml');
1115

12-
$request = \OC::$server->getRequest();
16+
$request = Server::get(IRequest::class);
1317

1418
$url = $request->getServerProtocol() . '://' . substr($request->getServerHost() . $request->getRequestUri(), 0, -17) . 'ocs/v1.php/';
1519

ocs/v1.php

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,14 @@
22

33
declare(strict_types=1);
44

5+
use OC\Route\Router;
6+
use OC\SystemConfig;
7+
use OC\User\LoginException;
8+
use OCP\IConfig;
9+
use OCP\IRequest;
10+
use OCP\IUserSession;
11+
use OCP\Server;
12+
513
/**
614
* SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
715
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
@@ -21,7 +29,7 @@
2129
use Symfony\Component\Routing\Exception\ResourceNotFoundException;
2230

2331
if (Util::needUpgrade()
24-
|| \OC::$server->getConfig()->getSystemValueBool('maintenance')) {
32+
|| Server::get(IConfig::class)->getSystemValueBool('maintenance')) {
2533
// since the behavior of apps or remotes are unpredictable during
2634
// an upgrade, return a 503 directly
2735
ApiHelper::respond(503, 'Service unavailable', ['X-Nextcloud-Maintenance-Mode' => '1'], 503);
@@ -42,11 +50,11 @@
4250
// side effects in existing apps
4351
OC_App::loadApps();
4452

45-
if (!\OC::$server->getUserSession()->isLoggedIn()) {
46-
OC::handleLogin(\OC::$server->getRequest());
53+
if (!Server::get(IUserSession::class)->isLoggedIn()) {
54+
OC::handleLogin(Server::get(IRequest::class));
4755
}
4856

49-
OC::$server->get(\OC\Route\Router::class)->match('/ocsapp' . \OC::$server->getRequest()->getRawPathInfo());
57+
Server::get(Router::class)->match('/ocsapp' . Server::get(IRequest::class)->getRawPathInfo());
5058
} catch (MaxDelayReached $ex) {
5159
ApiHelper::respond(Http::STATUS_TOO_MANY_REQUESTS, $ex->getMessage());
5260
} catch (ResourceNotFoundException $e) {
@@ -56,14 +64,14 @@
5664
} catch (MethodNotAllowedException $e) {
5765
ApiHelper::setContentType();
5866
http_response_code(405);
59-
} catch (\OC\User\LoginException $e) {
67+
} catch (LoginException $e) {
6068
ApiHelper::respond(OCSController::RESPOND_UNAUTHORISED, 'Unauthorised');
6169
} catch (\Exception $e) {
62-
\OCP\Server::get(LoggerInterface::class)->error($e->getMessage(), ['exception' => $e]);
70+
Server::get(LoggerInterface::class)->error($e->getMessage(), ['exception' => $e]);
6371

6472
$txt = 'Internal Server Error' . "\n";
6573
try {
66-
if (\OC::$server->getSystemConfig()->getValue('debug', false)) {
74+
if (Server::get(SystemConfig::class)->getValue('debug', false)) {
6775
$txt .= $e->getMessage();
6876
}
6977
} catch (\Throwable $e) {

public.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
declare(strict_types=1);
44

5+
use OC\ServiceUnavailableException;
6+
57
/**
68
* SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
79
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
@@ -88,7 +90,7 @@ function resolveService(string $service): string {
8890
require_once $file;
8991
} catch (Exception $ex) {
9092
$status = 500;
91-
if ($ex instanceof \OC\ServiceUnavailableException) {
93+
if ($ex instanceof ServiceUnavailableException) {
9294
$status = 503;
9395
}
9496
//show the user a detailed error page

remote.php

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
<?php
22

3+
use OC\ServiceUnavailableException;
4+
use OCP\IConfig;
5+
use OCP\Util;
6+
37
/**
48
* SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
59
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
@@ -35,7 +39,7 @@ function handleException(Exception|Error $e): void {
3539
// we shall not log on RemoteException
3640
$server->addPlugin(new ExceptionLoggerPlugin('webdav', \OCP\Server::get(LoggerInterface::class)));
3741
}
38-
$server->on('beforeMethod:*', function () use ($e) {
42+
$server->on('beforeMethod:*', function () use ($e): void {
3943
if ($e instanceof RemoteException) {
4044
switch ($e->getCode()) {
4145
case 503:
@@ -51,7 +55,7 @@ function handleException(Exception|Error $e): void {
5155
$server->exec();
5256
} else {
5357
$statusCode = 500;
54-
if ($e instanceof \OC\ServiceUnavailableException) {
58+
if ($e instanceof ServiceUnavailableException) {
5559
$statusCode = 503;
5660
}
5761
if ($e instanceof RemoteException) {
@@ -86,7 +90,7 @@ function resolveService($service) {
8690
return $services[$service];
8791
}
8892

89-
return \OC::$server->getConfig()->getAppValue('core', 'remote_' . $service);
93+
return \OCP\Server::get(IConfig::class)->getAppValue('core', 'remote_' . $service);
9094
}
9195

9296
try {
@@ -97,13 +101,13 @@ function resolveService($service) {
97101
// this policy with a softer one if debug mode is enabled.
98102
header("Content-Security-Policy: default-src 'none';");
99103

100-
if (\OCP\Util::needUpgrade()) {
104+
if (Util::needUpgrade()) {
101105
// since the behavior of apps or remotes are unpredictable during
102106
// an upgrade, return a 503 directly
103107
throw new RemoteException('Service unavailable', 503);
104108
}
105109

106-
$request = \OC::$server->getRequest();
110+
$request = \OCP\Server::get(IRequest::class);
107111
$pathInfo = $request->getPathInfo();
108112
if ($pathInfo === false || $pathInfo === '') {
109113
throw new RemoteException('Path not found', 404);

0 commit comments

Comments
 (0)