Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add rector #4045

Merged
merged 3 commits into from
Sep 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
6 changes: 5 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
"config": {
"platform": {
"php": "8.0"
},
"allow-plugins": {
"bamarni/composer-bin-plugin": true
}
},
"require": {
Expand All @@ -19,7 +22,8 @@
"friendsofphp/php-cs-fixer": "^3.8",
"nextcloud/coding-standard": "^1.0",
"nextcloud/ocp": "dev-master",
"phpunit/phpunit": "^9.5"
"phpunit/phpunit": "^9.5",
"bamarni/composer-bin-plugin": "^1.8"
},
"license": "AGPLv3",
"authors": [
Expand Down
195 changes: 153 additions & 42 deletions composer.lock

Large diffs are not rendered by default.

12 changes: 4 additions & 8 deletions lib/AppConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ public function getAppSettings() {

$keys = $this->config->getAppKeys(self::WATERMARK_APP_NAMESPACE);
foreach ($keys as $key) {
if (strpos($key, 'watermark_') === 0) {
if (str_starts_with($key, 'watermark_')) {
$value = $this->getAppValueArray($key);
$value = $value === 'yes' ? true : $value;
$result[$key] = $value === 'no' ? false : $value;
Expand Down Expand Up @@ -209,22 +209,18 @@ private function getFederationDomains(): array {
}

$federationService = \OCP\Server::get(FederationService::class);
$trustedNextcloudDomains = array_filter(array_map(function ($server) use ($federationService) {
return $federationService->isTrustedRemote($server) ? $server : null;
}, $federationService->getTrustedServers()));
$trustedNextcloudDomains = array_filter(array_map(fn ($server) => $federationService->isTrustedRemote($server) ? $server : null, $federationService->getTrustedServers()));

$trustedCollaboraDomains = array_filter(array_map(function ($server) use ($federationService) {
try {
return $federationService->getRemoteCollaboraURL($server);
} catch (\Exception $e) {
} catch (\Exception) {
// If there is no remote collabora server we can just skip that
return null;
}
}, $trustedNextcloudDomains));

return array_map(function ($url) {
return $this->domainOnly($url);
}, array_merge($trustedNextcloudDomains, $trustedCollaboraDomains));
return array_map(fn ($url) => $this->domainOnly($url), array_merge($trustedNextcloudDomains, $trustedCollaboraDomains));
}

private function getGSDomains(): array {
Expand Down
13 changes: 5 additions & 8 deletions lib/Backgroundjobs/Cleanup.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,12 @@
use OCP\IDBConnection;

class Cleanup extends TimedJob {
/** @var IDBConnection */
private $db;
/** @var WopiMapper $wopiMapper */
private $wopiMapper;

public function __construct(ITimeFactory $time, IDBConnection $db, WopiMapper $wopiMapper) {
public function __construct(
ITimeFactory $time,
private IDBConnection $db,
private WopiMapper $wopiMapper,
) {
parent::__construct($time);
$this->db = $db;
$this->wopiMapper = $wopiMapper;

$this->setInterval(60 * 60);
}
Expand Down
2 changes: 1 addition & 1 deletion lib/Capabilities.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public function __construct(
private PermissionManager $permissionManager,
private IAppManager $appManager,
private ?string $userId,
private IURLGenerator $urlGenerator
private IURLGenerator $urlGenerator,
) {
}

Expand Down
4 changes: 3 additions & 1 deletion lib/Command/ConvertToBigInt.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@
use Symfony\Component\Console\Question\ConfirmationQuestion;

class ConvertToBigInt extends Command {
public function __construct(private Connection $connection) {
public function __construct(
private Connection $connection,
) {
parent::__construct();
}

Expand Down
4 changes: 3 additions & 1 deletion lib/Command/InstallDefaultFonts.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@
use Symfony\Component\Console\Output\OutputInterface;

class InstallDefaultFonts extends Command {
public function __construct(private FontService $fontService) {
public function __construct(
private FontService $fontService,
) {
parent::__construct();
}

Expand Down
8 changes: 3 additions & 5 deletions lib/Command/UpdateEmptyTemplates.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,9 @@
use Symfony\Component\Console\Output\OutputInterface;

class UpdateEmptyTemplates extends Command {
/** @var TemplateManager */
private $templateManager;

public function __construct(TemplateManager $templateManager) {
$this->templateManager = $templateManager;
public function __construct(
private TemplateManager $templateManager,
) {
parent::__construct();
}

Expand Down
30 changes: 10 additions & 20 deletions lib/Controller/AssetsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,26 +22,16 @@
use OCP\IURLGenerator;

class AssetsController extends Controller {
private AssetMapper $assetMapper;
private IRootFolder $rootFolder;
private ?string $userId;
private UserScopeService $userScopeService;
private IURLGenerator $urlGenerator;

public function __construct($appName,
public function __construct(
$appName,
IRequest $request,
AssetMapper $assetMapper,
IRootFolder $rootFolder,
$userId,
UserScopeService $userScopeService,
IURLGenerator $urlGenerator) {
private AssetMapper $assetMapper,
private IRootFolder $rootFolder,
private ?string $userId,
private UserScopeService $userScopeService,
private IURLGenerator $urlGenerator,
) {
parent::__construct($appName, $request);

$this->assetMapper = $assetMapper;
$this->rootFolder = $rootFolder;
$this->userId = $userId;
$this->userScopeService = $userScopeService;
$this->urlGenerator = $urlGenerator;
}

/**
Expand All @@ -56,7 +46,7 @@ public function create($path) {

try {
$node = $userFolder->get($path);
} catch (NotFoundException $e) {
} catch (NotFoundException) {
return new JSONResponse([], Http::STATUS_NOT_FOUND);
}

Expand All @@ -80,7 +70,7 @@ public function create($path) {
public function get($token) {
try {
$asset = $this->assetMapper->getAssetByToken($token);
} catch (DoesNotExistException $e) {
} catch (DoesNotExistException) {
return new DataResponse([], Http::STATUS_NOT_FOUND);
}

Expand Down
2 changes: 1 addition & 1 deletion lib/Controller/DirectViewController.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public function __construct(
private AppConfig $appConfig,
private TemplateManager $templateManager,
private FederationService $federationService,
private LoggerInterface $logger
private LoggerInterface $logger,
) {
parent::__construct($appName, $request);
}
Expand Down
30 changes: 12 additions & 18 deletions lib/Controller/DocumentAPIController.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,23 +29,17 @@
use Throwable;

class DocumentAPIController extends \OCP\AppFramework\OCSController {
private $rootFolder;
private $shareManager;
private $templateManager;
private $l10n;
private $logger;
private $lockManager;
private $userId;

public function __construct(IRequest $request, IRootFolder $rootFolder, IManager $shareManager, TemplateManager $templateManager, IL10N $l10n, LoggerInterface $logger, ILockManager $lockManager, $userId) {
public function __construct(
IRequest $request,
private IRootFolder $rootFolder,
private IManager $shareManager,
private TemplateManager $templateManager,
private IL10N $l10n,
private LoggerInterface $logger,
private ILockManager $lockManager,
private $userId,
) {
parent::__construct(Application::APPNAME, $request);
$this->rootFolder = $rootFolder;
$this->shareManager = $shareManager;
$this->templateManager = $templateManager;
$this->l10n = $l10n;
$this->logger = $logger;
$this->lockManager = $lockManager;
$this->userId = $userId;
}

/**
Expand Down Expand Up @@ -153,9 +147,9 @@ public function openLocal(int $fileId): DataResponse {
Application::APPNAME
));
return new DataResponse([]);
} catch (NoLockProviderException|PreConditionNotMetException $e) {
} catch (NoLockProviderException|PreConditionNotMetException) {
return new DataResponse([], Http::STATUS_BAD_REQUEST);
} catch (\Exception $e) {
} catch (\Exception) {
return new DataResponse([], Http::STATUS_INTERNAL_SERVER_ERROR);
}

Expand Down
8 changes: 4 additions & 4 deletions lib/Controller/DocumentController.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public function __construct(
private TemplateManager $templateManager,
private FederationService $federationService,
private InitialStateService $initialState,
private IURLGenerator $urlGenerator
private IURLGenerator $urlGenerator,
) {
parent::__construct($appName, $request);
}
Expand Down Expand Up @@ -144,7 +144,7 @@ public function index($fileId, ?string $path = null): RedirectResponse|TemplateR
if ($encryptionManager->isEnabled()) {
// Update the current file to be accessible with system public shared key
$owner = $file->getOwner()->getUID();
$absPath = '/' . $owner . '/' . $file->getInternalPath();
$absPath = '/' . $owner . '/' . $file->getInternalPath();
$accessList = OC::$server->getEncryptionFilesHelper()->getAccessList($absPath);
$accessList['public'] = true;
$encryptionManager->getEncryptionModule()->update($absPath, $owner, $accessList);
Expand All @@ -169,7 +169,7 @@ public function createFromTemplate(int $templateId, string $fileName, string $di
$userFolder = $this->rootFolder->getUserFolder($this->userId);
try {
$folder = $userFolder->get($dir);
} catch (NotFoundException $e) {
} catch (NotFoundException) {
return new TemplateResponse('core', '403', [], 'guest');
}

Expand Down Expand Up @@ -286,7 +286,7 @@ public function remote(string $shareToken, string $remoteServer, string $remoteS
$response->addHeader('X-Frame-Options', 'ALLOW');
return $response;
}
} catch (ShareNotFound $e) {
} catch (ShareNotFound) {
return new TemplateResponse('core', '404', [], 'guest');
} catch (Exception $e) {
$this->logger->error($e->getMessage(), ['exception' => $e]);
Expand Down
2 changes: 1 addition & 1 deletion lib/Controller/DocumentTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ private function applyPolicies($response) {
private function domainOnly(string $url): string {
$parsed_url = parse_url($url);
$scheme = isset($parsed_url['scheme']) ? $parsed_url['scheme'] . '://' : '';
$host = isset($parsed_url['host']) ? $parsed_url['host'] : '';
$host = $parsed_url['host'] ?? '';
$port = isset($parsed_url['port']) ? ':' . $parsed_url['port'] : '';
return "$scheme$host$port";
}
Expand Down
38 changes: 9 additions & 29 deletions lib/Controller/FederationController.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,36 +19,16 @@
use Psr\Log\LoggerInterface;

class FederationController extends OCSController {
/** @var IConfig */
private $config;

/** @var LoggerInterface */
private $logger;

/** @var WopiMapper */
private $wopiMapper;

/** @var IUserManager */
private $userManager;

/** @var IURLGenerator */
private $urlGenerator;

public function __construct(
string $appName,
IRequest $request,
IConfig $config,
LoggerInterface $logger,
WopiMapper $wopiMapper,
IUserManager $userManager,
IURLGenerator $urlGenerator
private IConfig $config,
private LoggerInterface $logger,
private WopiMapper $wopiMapper,
private IUserManager $userManager,
private IURLGenerator $urlGenerator,
) {
parent::__construct($appName, $request);
$this->config = $config;
$this->logger = $logger;
$this->wopiMapper = $wopiMapper;
$this->userManager = $userManager;
$this->urlGenerator = $urlGenerator;
}

/**
Expand Down Expand Up @@ -97,10 +77,10 @@ public function remoteWopiToken($token): DataResponse {
}
$this->logger->debug('COOL-Federation-Initiator: Token ' . $token . ' returned');
return new DataResponse($initiatorWopi);
} catch (UnknownTokenException $e) {
} catch (UnknownTokenException) {
$this->logger->debug('COOL-Federation-Initiator: Token ' . $token . 'not found');
throw new OCSNotFoundException();
} catch (ExpiredTokenException $e) {
} catch (ExpiredTokenException) {
$this->logger->debug('COOL-Federation-Initiator: Token ' . $token . ' is expired');
throw new OCSNotFoundException();
}
Expand Down Expand Up @@ -132,10 +112,10 @@ public function initiatorUser($token): DataResponse {
'displayName' => $user->getDisplayName(),
'avatar' => $this->urlGenerator->linkToRouteAbsolute('core.avatar.getAvatar', ['userId' => $wopi->getEditorUid(), 'size' => WopiController::WOPI_AVATAR_SIZE])
]);
} catch (UnknownTokenException $e) {
} catch (UnknownTokenException) {
$this->logger->debug('COOL-Federation-Initiator-User: Token ' . $token . 'not found');
throw new OCSNotFoundException();
} catch (ExpiredTokenException $e) {
} catch (ExpiredTokenException) {
$this->logger->debug('COOL-Federation-Initiator-User: Token ' . $token . ' is expired.');
throw new OCSNotFoundException();
}
Expand Down
Loading
Loading