Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
refactor: Extend rector to all top-level files
Signed-off-by: provokateurin <[email protected]>
  • Loading branch information
provokateurin committed May 15, 2025
commit 6d6d83d3d9ec355e2d99d5ddc2ef1ee9b4e1d3ba
7 changes: 7 additions & 0 deletions build/rector.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,14 @@ public function shouldSkip(File $file, FullyQualifiedObjectType $fullyQualifiedO
->withPaths([
$nextcloudDir . '/apps',
$nextcloudDir . '/core',
$nextcloudDir . '/console.php',
$nextcloudDir . '/cron.php',
$nextcloudDir . '/index.php',
$nextcloudDir . '/occ',
$nextcloudDir . '/public.php',
$nextcloudDir . '/remote.php',
$nextcloudDir . '/status.php',
$nextcloudDir . '/version.php',
// $nextcloudDir . '/config',
// $nextcloudDir . '/lib',
// $nextcloudDir . '/ocs',
Expand Down
13 changes: 8 additions & 5 deletions console.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

declare(strict_types=1);

use OCP\IConfig;
use OCP\Server;

/**
* SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
Expand Down Expand Up @@ -37,7 +40,7 @@ function exceptionHandler($exception) {
exit(1);
}

$config = \OCP\Server::get(\OCP\IConfig::class);
$config = Server::get(IConfig::class);
set_exception_handler('exceptionHandler');

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

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

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

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

$profiler = \OCP\Server::get(IProfiler::class);
$profiler = Server::get(IProfiler::class);
if ($profiler->isEnabled()) {
$eventLogger->end('runtime');
$profile = $profiler->collect(\OCP\Server::get(IRequest::class), new Response());
$profile = $profiler->collect(Server::get(IRequest::class), new Response());
$profile->setMethod('occ');
$profile->setUrl(implode(' ', $argv));
$profiler->saveProfile($profile);
Expand Down
21 changes: 13 additions & 8 deletions cron.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

declare(strict_types=1);

use OC\Files\SetupManager;
use OC\Session\CryptoWrapper;
use OC\Session\Memory;
use OCP\ILogger;

/**
* SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
Expand Down Expand Up @@ -64,8 +69,8 @@
$verbose = isset($argv[1]) && ($argv[1] === '-v' || $argv[1] === '--verbose');

// initialize a dummy memory session
$session = new \OC\Session\Memory();
$cryptoWrapper = \OC::$server->getSessionCryptoWrapper();
$session = new Memory();
$cryptoWrapper = Server::get(CryptoWrapper::class);
$session = $cryptoWrapper->wrapSession($session);
\OC::$server->setSession($session);

Expand Down Expand Up @@ -177,11 +182,11 @@
$timeSpent = $timeAfter - $timeBefore;
if ($timeSpent > $cronInterval) {
$logLevel = match (true) {
$timeSpent > $cronInterval * 128 => \OCP\ILogger::FATAL,
$timeSpent > $cronInterval * 64 => \OCP\ILogger::ERROR,
$timeSpent > $cronInterval * 16 => \OCP\ILogger::WARN,
$timeSpent > $cronInterval * 8 => \OCP\ILogger::INFO,
default => \OCP\ILogger::DEBUG,
$timeSpent > $cronInterval * 128 => ILogger::FATAL,
$timeSpent > $cronInterval * 64 => ILogger::ERROR,
$timeSpent > $cronInterval * 16 => ILogger::WARN,
$timeSpent > $cronInterval * 8 => ILogger::INFO,
default => ILogger::DEBUG,
};
$logger->log(
$logLevel,
Expand All @@ -206,7 +211,7 @@
}

// clean up after unclean jobs
Server::get(\OC\Files\SetupManager::class)->tearDown();
Server::get(SetupManager::class)->tearDown();
$tempManager->clean();

if ($verbose) {
Expand Down
4 changes: 3 additions & 1 deletion public.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

declare(strict_types=1);

use OC\ServiceUnavailableException;

/**
* SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
Expand Down Expand Up @@ -88,7 +90,7 @@ function resolveService(string $service): string {
require_once $file;
} catch (Exception $ex) {
$status = 500;
if ($ex instanceof \OC\ServiceUnavailableException) {
if ($ex instanceof ServiceUnavailableException) {
$status = 503;
}
//show the user a detailed error page
Expand Down
14 changes: 9 additions & 5 deletions remote.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
<?php

use OC\ServiceUnavailableException;
use OCP\IConfig;
use OCP\Util;

/**
* SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
Expand Down Expand Up @@ -35,7 +39,7 @@ function handleException(Exception|Error $e): void {
// we shall not log on RemoteException
$server->addPlugin(new ExceptionLoggerPlugin('webdav', \OCP\Server::get(LoggerInterface::class)));
}
$server->on('beforeMethod:*', function () use ($e) {
$server->on('beforeMethod:*', function () use ($e): void {
if ($e instanceof RemoteException) {
switch ($e->getCode()) {
case 503:
Expand All @@ -51,7 +55,7 @@ function handleException(Exception|Error $e): void {
$server->exec();
} else {
$statusCode = 500;
if ($e instanceof \OC\ServiceUnavailableException) {
if ($e instanceof ServiceUnavailableException) {
$statusCode = 503;
}
if ($e instanceof RemoteException) {
Expand Down Expand Up @@ -86,7 +90,7 @@ function resolveService($service) {
return $services[$service];
}

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

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

if (\OCP\Util::needUpgrade()) {
if (Util::needUpgrade()) {
// since the behavior of apps or remotes are unpredictable during
// an upgrade, return a 503 directly
throw new RemoteException('Service unavailable', 503);
}

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