From f48db5ac83bd6ab5157a913112d900e2fc9f5578 Mon Sep 17 00:00:00 2001 From: Hamid Dehnavi Date: Fri, 7 Jul 2023 04:19:27 +0330 Subject: [PATCH 01/17] Refactor core/Controller Signed-off-by: Hamid Dehnavi --- core/Controller/AppPasswordController.php | 2 ++ core/Controller/AvatarController.php | 22 +++++++----- core/Controller/ClientFlowLoginController.php | 11 ++++-- .../ClientFlowLoginV2Controller.php | 5 +-- core/Controller/ContactsMenuController.php | 4 ++- core/Controller/CssController.php | 3 +- core/Controller/GuestAvatarController.php | 8 +++-- core/Controller/JsController.php | 3 +- core/Controller/LoginController.php | 19 ++++++---- core/Controller/LostController.php | 4 +-- core/Controller/PreviewController.php | 36 ++++++++++++++++--- core/Controller/ProfileApiController.php | 9 +++++ core/Controller/SetupController.php | 2 +- .../TwoFactorChallengeController.php | 18 ++++++---- core/Controller/UnifiedSearchController.php | 4 +-- core/Controller/UserController.php | 2 +- core/Controller/WellKnownController.php | 1 + 17 files changed, 111 insertions(+), 42 deletions(-) diff --git a/core/Controller/AppPasswordController.php b/core/Controller/AppPasswordController.php index 90020330ea19e..a080ce05ad4a1 100644 --- a/core/Controller/AppPasswordController.php +++ b/core/Controller/AppPasswordController.php @@ -102,6 +102,7 @@ public function getAppPassword(): DataResponse { /** * @NoAdminRequired + * @throws OCSForbiddenException */ public function deleteAppPassword(): DataResponse { if (!$this->session->exists('app_password')) { @@ -122,6 +123,7 @@ public function deleteAppPassword(): DataResponse { /** * @NoAdminRequired + * @throws OCSForbiddenException */ public function rotateAppPassword(): DataResponse { if (!$this->session->exists('app_password')) { diff --git a/core/Controller/AvatarController.php b/core/Controller/AvatarController.php index ba1792af7089b..8340a04b3f23f 100644 --- a/core/Controller/AvatarController.php +++ b/core/Controller/AvatarController.php @@ -31,6 +31,8 @@ namespace OC\Core\Controller; use OC\AppFramework\Utility\TimeFactory; +use OC\Files\Filesystem; +use OC\NotSquareException; use OCP\AppFramework\Controller; use OCP\AppFramework\Http; use OCP\AppFramework\Http\DataDisplayResponse; @@ -38,9 +40,11 @@ use OCP\AppFramework\Http\JSONResponse; use OCP\Files\File; use OCP\Files\IRootFolder; +use OCP\Files\NotPermittedException; use OCP\IAvatarManager; use OCP\ICache; use OCP\IL10N; +use OCP\Image; use OCP\IRequest; use OCP\IUserManager; use Psr\Log\LoggerInterface; @@ -74,7 +78,7 @@ public function __construct( * * @return JSONResponse|FileDisplayResponse */ - public function getAvatarDark(string $userId, int $size) { + public function getAvatarDark(string $userId, int $size): FileDisplayResponse|JSONResponse { if ($size <= 64) { if ($size !== 64) { $this->logger->debug('Avatar requested in deprecated size ' . $size); @@ -113,7 +117,7 @@ public function getAvatarDark(string $userId, int $size) { * * @return JSONResponse|FileDisplayResponse */ - public function getAvatar(string $userId, int $size) { + public function getAvatar(string $userId, int $size): FileDisplayResponse|JSONResponse { if ($size <= 64) { if ($size !== 64) { $this->logger->debug('Avatar requested in deprecated size ' . $size); @@ -173,7 +177,7 @@ public function postAvatar(?string $path = null): JSONResponse { try { $content = $node->getContent(); - } catch (\OCP\Files\NotPermittedException $e) { + } catch (NotPermittedException $e) { return new JSONResponse( ['data' => ['message' => $this->l10n->t('The selected file cannot be read.')]], Http::STATUS_BAD_REQUEST @@ -183,7 +187,7 @@ public function postAvatar(?string $path = null): JSONResponse { if ( $files['error'][0] === 0 && is_uploaded_file($files['tmp_name'][0]) && - !\OC\Files\Filesystem::isFileBlacklisted($files['tmp_name'][0]) + !Filesystem::isFileBlacklisted($files['tmp_name'][0]) ) { if ($files['size'][0] > 20 * 1024 * 1024) { return new JSONResponse( @@ -221,7 +225,7 @@ public function postAvatar(?string $path = null): JSONResponse { } try { - $image = new \OCP\Image(); + $image = new Image(); $image->loadFromData($content); $image->readExif($content); $image->fixOrientation(); @@ -284,7 +288,7 @@ public function deleteAvatar(): JSONResponse { * * @return JSONResponse|DataDisplayResponse */ - public function getTmpAvatar() { + public function getTmpAvatar(): JSONResponse|DataDisplayResponse { $tmpAvatar = $this->cache->get('tmpAvatar'); if (is_null($tmpAvatar)) { return new JSONResponse(['data' => [ @@ -293,7 +297,7 @@ public function getTmpAvatar() { Http::STATUS_NOT_FOUND); } - $image = new \OCP\Image(); + $image = new Image(); $image->loadFromData($tmpAvatar); $resp = new DataDisplayResponse( @@ -329,7 +333,7 @@ public function postCroppedAvatar(?array $crop = null): JSONResponse { Http::STATUS_BAD_REQUEST); } - $image = new \OCP\Image(); + $image = new Image(); $image->loadFromData($tmpAvatar); $image->crop($crop['x'], $crop['y'], (int)round($crop['w']), (int)round($crop['h'])); try { @@ -338,7 +342,7 @@ public function postCroppedAvatar(?array $crop = null): JSONResponse { // Clean up $this->cache->remove('tmpAvatar'); return new JSONResponse(['status' => 'success']); - } catch (\OC\NotSquareException $e) { + } catch (NotSquareException $e) { return new JSONResponse(['data' => ['message' => $this->l10n->t('Crop is not square')]], Http::STATUS_BAD_REQUEST); } catch (\Exception $e) { diff --git a/core/Controller/ClientFlowLoginController.php b/core/Controller/ClientFlowLoginController.php index 082d5b3f92ebb..cc2b9620164b7 100644 --- a/core/Controller/ClientFlowLoginController.php +++ b/core/Controller/ClientFlowLoginController.php @@ -39,11 +39,14 @@ use OCA\OAuth2\Db\AccessToken; use OCA\OAuth2\Db\AccessTokenMapper; use OCA\OAuth2\Db\ClientMapper; +use OCA\OAuth2\Exceptions\ClientNotFoundException; use OCP\AppFramework\Controller; use OCP\AppFramework\Http; use OCP\AppFramework\Http\Attribute\UseSession; +use OCP\AppFramework\Http\RedirectResponse; use OCP\AppFramework\Http\Response; use OCP\AppFramework\Http\StandaloneTemplateResponse; +use OCP\DB\Exception; use OCP\Defaults; use OCP\EventDispatcher\IEventDispatcher; use OCP\IL10N; @@ -224,11 +227,15 @@ public function grantPage(string $stateToken = '', /** * @NoAdminRequired * - * @return Http\RedirectResponse|Response + * @param string $stateToken + * @param string $clientIdentifier + * @return Response|StandaloneTemplateResponse|RedirectResponse + * @throws ClientNotFoundException + * @throws Exception */ #[UseSession] public function generateAppPassword(string $stateToken, - string $clientIdentifier = '') { + string $clientIdentifier = ''): Response|StandaloneTemplateResponse|Http\RedirectResponse { if (!$this->isValidToken($stateToken)) { $this->session->remove(self::STATE_NAME); return $this->stateTokenForbiddenResponse(); diff --git a/core/Controller/ClientFlowLoginV2Controller.php b/core/Controller/ClientFlowLoginV2Controller.php index 8a21148f5895f..65426ef0fa11f 100644 --- a/core/Controller/ClientFlowLoginV2Controller.php +++ b/core/Controller/ClientFlowLoginV2Controller.php @@ -28,6 +28,7 @@ namespace OC\Core\Controller; use OC\Authentication\Exceptions\InvalidTokenException; +use OC\Authentication\Token\IProvider; use OC\Core\Db\LoginFlowV2; use OC\Core\Exception\LoginFlowV2NotFoundException; use OC\Core\Service\LoginFlowV2Service; @@ -170,7 +171,7 @@ public function grantPage(?string $stateToken): StandaloneTemplateResponse { /** * @PublicPage */ - public function apptokenRedirect(?string $stateToken, string $user, string $password) { + public function apptokenRedirect(?string $stateToken, string $user, string $password): StandaloneTemplateResponse { if ($stateToken === null) { return $this->stateTokenMissingResponse(); } @@ -192,7 +193,7 @@ public function apptokenRedirect(?string $stateToken, string $user, string $pass $this->session->remove(self::STATE_NAME); try { - $token = \OC::$server->get(\OC\Authentication\Token\IProvider::class)->getToken($password); + $token = \OC::$server->get(IProvider::class)->getToken($password); if ($token->getLoginName() !== $user) { throw new InvalidTokenException('login name does not match'); } diff --git a/core/Controller/ContactsMenuController.php b/core/Controller/ContactsMenuController.php index 7b8f2e50aa54a..78848e86883c2 100644 --- a/core/Controller/ContactsMenuController.php +++ b/core/Controller/ContactsMenuController.php @@ -54,10 +54,12 @@ public function index(?string $filter = null): array { /** * @NoAdminRequired * + * @param int $shareType + * @param string $shareWith * @return JSONResponse|\JsonSerializable * @throws Exception */ - public function findOne(int $shareType, string $shareWith) { + public function findOne(int $shareType, string $shareWith): JSONResponse|\JsonSerializable { $contact = $this->manager->findOne($this->userSession->getUser(), $shareType, $shareWith); if ($contact) { diff --git a/core/Controller/CssController.php b/core/Controller/CssController.php index 7aec5850aea5a..4bac668278f0d 100644 --- a/core/Controller/CssController.php +++ b/core/Controller/CssController.php @@ -64,7 +64,8 @@ public function __construct( * * @param string $fileName css filename with extension * @param string $appName css folder name - * @return FileDisplayResponse|NotFoundResponse + * @return Response + * @throws \Exception */ public function getCss(string $fileName, string $appName): Response { try { diff --git a/core/Controller/GuestAvatarController.php b/core/Controller/GuestAvatarController.php index 6f06451b796a7..622af81646205 100644 --- a/core/Controller/GuestAvatarController.php +++ b/core/Controller/GuestAvatarController.php @@ -25,6 +25,7 @@ use OCP\AppFramework\Controller; use OCP\AppFramework\Http; use OCP\AppFramework\Http\FileDisplayResponse; +use OCP\AppFramework\Http\Response; use OCP\IAvatarManager; use OCP\IRequest; use Psr\Log\LoggerInterface; @@ -53,9 +54,10 @@ public function __construct( * * @param string $guestName The guest name, e.g. "Albert" * @param string $size The desired avatar size, e.g. 64 for 64x64px - * @return FileDisplayResponse|Http\Response + * @param bool|null $darkTheme + * @return FileDisplayResponse|Response */ - public function getAvatar(string $guestName, string $size, ?bool $darkTheme = false) { + public function getAvatar(string $guestName, string $size, ?bool $darkTheme = false): Http\Response|FileDisplayResponse { $size = (int) $size; $darkTheme = $darkTheme ?? false; @@ -98,7 +100,7 @@ public function getAvatar(string $guestName, string $size, ?bool $darkTheme = fa * @PublicPage * @NoCSRFRequired */ - public function getAvatarDark(string $guestName, string $size) { + public function getAvatarDark(string $guestName, string $size): Response|FileDisplayResponse { return $this->getAvatar($guestName, $size, true); } } diff --git a/core/Controller/JsController.php b/core/Controller/JsController.php index 0ad78d5f87f0c..bf1e1f245dc5b 100644 --- a/core/Controller/JsController.php +++ b/core/Controller/JsController.php @@ -64,7 +64,8 @@ public function __construct( * * @param string $fileName js filename with extension * @param string $appName js folder name - * @return FileDisplayResponse|NotFoundResponse + * @return Response + * @throws \Exception */ public function getJs(string $fileName, string $appName): Response { try { diff --git a/core/Controller/LoginController.php b/core/Controller/LoginController.php index 1bee366b00fbe..c975712cd61dc 100644 --- a/core/Controller/LoginController.php +++ b/core/Controller/LoginController.php @@ -45,6 +45,7 @@ use OCP\AppFramework\Http\Attribute\UseSession; use OCP\AppFramework\Http\DataResponse; use OCP\AppFramework\Http\RedirectResponse; +use OCP\AppFramework\Http\Response; use OCP\AppFramework\Http\TemplateResponse; use OCP\Defaults; use OCP\IConfig; @@ -86,7 +87,7 @@ public function __construct( * @return RedirectResponse */ #[UseSession] - public function logout() { + public function logout(): RedirectResponse { $loginToken = $this->request->getCookie('nc_token'); if (!is_null($loginToken)) { $this->config->deleteUserValue($this->userSession->getUser()->getUID(), 'login_token', $loginToken); @@ -113,10 +114,10 @@ public function logout() { * @PublicPage * @NoCSRFRequired * - * @param string $user - * @param string $redirect_url + * @param string|null $user + * @param string|null $redirect_url * - * @return TemplateResponse|RedirectResponse + * @return Response */ #[UseSession] public function showLoginForm(string $user = null, string $redirect_url = null): Http\Response { @@ -196,7 +197,7 @@ public function showLoginForm(string $user = null, string $redirect_url = null): /** * Sets the password reset state * - * @param string $username + * @param string|null $username */ private function setPasswordResetInitialState(?string $username): void { if ($username !== null && $username !== '') { @@ -264,6 +265,12 @@ private function generateRedirect(?string $redirectUrl): RedirectResponse { * @NoCSRFRequired * @BruteForceProtection(action=login) * + * @param Chain $loginChain + * @param string $user + * @param string $password + * @param string|null $redirect_url + * @param string $timezone + * @param string $timezone_offset * @return RedirectResponse */ #[UseSession] @@ -327,7 +334,7 @@ public function tryLogin(Chain $loginChain, * @return RedirectResponse */ private function createLoginFailedResponse( - $user, $originalUser, $redirect_url, string $loginMessage) { + string $user, string $originalUser, string $redirect_url, string $loginMessage): RedirectResponse { // Read current user and append if possible we need to // return the unmodified user otherwise we will leak the login name $args = $user !== null ? ['user' => $originalUser, 'direct' => 1] : []; diff --git a/core/Controller/LostController.php b/core/Controller/LostController.php index 7de93b7107a4a..ed3628273c008 100644 --- a/core/Controller/LostController.php +++ b/core/Controller/LostController.php @@ -60,6 +60,7 @@ use OC\Core\Exception\ResetPasswordException; use OC\Security\RateLimiting\Exception\RateLimitExceededException; use OC\Security\RateLimiting\Limiter; +use OCP\Util; use Psr\Log\LoggerInterface; use function array_filter; use function count; @@ -176,7 +177,7 @@ public function email(string $user): JSONResponse { $user = trim($user); - \OCP\Util::emitHook( + Util::emitHook( '\OCA\Files_Sharing\API\Server2Server', 'preLoginNameUsedAsUserName', ['uid' => &$user] @@ -252,7 +253,6 @@ public function setPassword(string $token, string $userId, string $password, boo /** * @throws ResetPasswordException - * @throws \OCP\PreConditionNotMetException */ protected function sendEmail(string $input): void { $user = $this->findUserByIdOrMail($input); diff --git a/core/Controller/PreviewController.php b/core/Controller/PreviewController.php index 38373e2d14776..8b79bb28a64da 100644 --- a/core/Controller/PreviewController.php +++ b/core/Controller/PreviewController.php @@ -27,15 +27,19 @@ */ namespace OC\Core\Controller; +use OC\User\NoUserException; use OCA\Files_Sharing\SharedStorage; use OCP\AppFramework\Controller; use OCP\AppFramework\Http; use OCP\AppFramework\Http\DataResponse; use OCP\AppFramework\Http\FileDisplayResponse; +use OCP\AppFramework\Http\Response; use OCP\Files\File; +use OCP\Files\InvalidPathException; use OCP\Files\IRootFolder; use OCP\Files\Node; use OCP\Files\NotFoundException; +use OCP\Files\NotPermittedException; use OCP\IPreview; use OCP\IRequest; @@ -54,7 +58,15 @@ public function __construct( * @NoAdminRequired * @NoCSRFRequired * - * @return DataResponse|FileDisplayResponse + * @param string $file + * @param int $x + * @param int $y + * @param bool $a + * @param bool $forceIcon + * @param string $mode + * @return Response + * @throws NotPermittedException + * @throws NoUserException */ public function getPreview( string $file = '', @@ -81,7 +93,15 @@ public function getPreview( * @NoAdminRequired * @NoCSRFRequired * - * @return DataResponse|FileDisplayResponse + * @param int $fileId + * @param int $x + * @param int $y + * @param bool $a + * @param bool $forceIcon + * @param string $mode + * @return DataResponse|Response|FileDisplayResponse + * @throws NoUserException + * @throws NotPermittedException */ public function getPreviewByFileId( int $fileId = -1, @@ -89,7 +109,7 @@ public function getPreviewByFileId( int $y = 32, bool $a = false, bool $forceIcon = true, - string $mode = 'fill') { + string $mode = 'fill'): DataResponse|Response|FileDisplayResponse { if ($fileId === -1 || $x === 0 || $y === 0) { return new DataResponse([], Http::STATUS_BAD_REQUEST); } @@ -107,7 +127,15 @@ public function getPreviewByFileId( } /** - * @return DataResponse|FileDisplayResponse + * @param Node $node + * @param int $x + * @param int $y + * @param bool $a + * @param bool $forceIcon + * @param string $mode + * @return Response + * @throws NotFoundException + * @throws InvalidPathException */ private function fetchPreview( Node $node, diff --git a/core/Controller/ProfileApiController.php b/core/Controller/ProfileApiController.php index e66d4f21c2bf6..bb2bc8344a62a 100644 --- a/core/Controller/ProfileApiController.php +++ b/core/Controller/ProfileApiController.php @@ -32,6 +32,7 @@ use OCP\AppFramework\OCS\OCSForbiddenException; use OCP\AppFramework\OCS\OCSNotFoundException; use OCP\AppFramework\OCSController; +use OCP\DB\Exception; use OCP\IRequest; use OCP\IUserManager; use OCP\IUserSession; @@ -53,6 +54,14 @@ public function __construct( * @NoSubAdminRequired * @PasswordConfirmationRequired * @UserRateThrottle(limit=40, period=600) + * @param string $targetUserId + * @param string $paramId + * @param string $visibility + * @return DataResponse + * @throws OCSBadRequestException + * @throws OCSForbiddenException + * @throws OCSNotFoundException + * @throws Exception */ public function setVisibility(string $targetUserId, string $paramId, string $visibility): DataResponse { $requestingUser = $this->userSession->getUser(); diff --git a/core/Controller/SetupController.php b/core/Controller/SetupController.php index 69c3b2f2a2394..16a085c7c0196 100644 --- a/core/Controller/SetupController.php +++ b/core/Controller/SetupController.php @@ -78,7 +78,7 @@ public function run(array $post): void { } } - private function displaySetupForbidden() { + private function displaySetupForbidden(): void { \OC_Template::printGuestPage('', 'installation_forbidden'); } diff --git a/core/Controller/TwoFactorChallengeController.php b/core/Controller/TwoFactorChallengeController.php index 40b100c41bdab..4f8f8ed5b9bb8 100644 --- a/core/Controller/TwoFactorChallengeController.php +++ b/core/Controller/TwoFactorChallengeController.php @@ -57,7 +57,7 @@ public function __construct( /** * @return string */ - protected function getLogoutUrl() { + protected function getLogoutUrl(): string { return OC_User::getLogoutUrl($this->urlGenerator); } @@ -85,8 +85,9 @@ private function splitProvidersAndBackupCodes(array $providers): array { * * @param string $redirect_url * @return StandaloneTemplateResponse + * @throws \Exception */ - public function selectChallenge($redirect_url) { + public function selectChallenge($redirect_url): StandaloneTemplateResponse { $user = $this->userSession->getUser(); $providerSet = $this->twoFactorManager->getProviderSet($user); $allProviders = $providerSet->getProviders(); @@ -112,9 +113,10 @@ public function selectChallenge($redirect_url) { * @param string $challengeProviderId * @param string $redirect_url * @return StandaloneTemplateResponse|RedirectResponse + * @throws \Exception */ #[UseSession] - public function showChallenge($challengeProviderId, $redirect_url) { + public function showChallenge(string $challengeProviderId, string $redirect_url): StandaloneTemplateResponse|RedirectResponse { $user = $this->userSession->getUser(); $providerSet = $this->twoFactorManager->getProviderSet($user); $provider = $providerSet->getProvider($challengeProviderId); @@ -164,11 +166,11 @@ public function showChallenge($challengeProviderId, $redirect_url) { * * @param string $challengeProviderId * @param string $challenge - * @param string $redirect_url + * @param string|null $redirect_url * @return RedirectResponse */ #[UseSession] - public function solveChallenge($challengeProviderId, $challenge, $redirect_url = null) { + public function solveChallenge(string $challengeProviderId, string $challenge, string $redirect_url = null): RedirectResponse { $user = $this->userSession->getUser(); $provider = $this->twoFactorManager->getProvider($user, $challengeProviderId); if (is_null($provider)) { @@ -204,6 +206,7 @@ public function solveChallenge($challengeProviderId, $challenge, $redirect_url = /** * @NoAdminRequired * @NoCSRFRequired + * @throws \Exception */ public function setupProviders(): StandaloneTemplateResponse { $user = $this->userSession->getUser(); @@ -220,8 +223,9 @@ public function setupProviders(): StandaloneTemplateResponse { /** * @NoAdminRequired * @NoCSRFRequired + * @throws \Exception */ - public function setupProvider(string $providerId) { + public function setupProvider(string $providerId): StandaloneTemplateResponse|RedirectResponse { $user = $this->userSession->getUser(); $providers = $this->twoFactorManager->getLoginSetupProviders($user); @@ -254,7 +258,7 @@ public function setupProvider(string $providerId) { * * @todo handle the extreme edge case of an invalid provider ID and redirect to the provider selection page */ - public function confirmProviderSetup(string $providerId) { + public function confirmProviderSetup(string $providerId): RedirectResponse { return new RedirectResponse($this->urlGenerator->linkToRoute( 'core.TwoFactorChallenge.showChallenge', [ diff --git a/core/Controller/UnifiedSearchController.php b/core/Controller/UnifiedSearchController.php index 7e73ac8100fd1..313be45f51489 100644 --- a/core/Controller/UnifiedSearchController.php +++ b/core/Controller/UnifiedSearchController.php @@ -116,7 +116,7 @@ protected function getRouteInformation(string $url): array { // Optionally strip webroot from URL. Required for route matching on setups // with Nextcloud in a webserver subfolder (webroot). $webroot = $this->urlGenerator->getWebroot(); - if ($webroot !== '' && substr($urlPath, 0, strlen($webroot)) === $webroot) { + if ($webroot !== '' && str_starts_with($urlPath, $webroot)) { $urlPath = substr($urlPath, strlen($webroot)); } @@ -125,7 +125,7 @@ protected function getRouteInformation(string $url): array { // contacts.PageController.index => contacts.Page.index $route = $parameters['caller']; - if (substr($route[1], -10) === 'Controller') { + if (str_ends_with($route[1], 'Controller')) { $route[1] = substr($route[1], 0, -10); } $routeStr = implode('.', $route); diff --git a/core/Controller/UserController.php b/core/Controller/UserController.php index f8dbc1af02700..f8076cfb3f6c3 100644 --- a/core/Controller/UserController.php +++ b/core/Controller/UserController.php @@ -47,7 +47,7 @@ public function __construct( * * @return JSONResponse */ - public function getDisplayNames($users) { + public function getDisplayNames(array $users): JSONResponse { $result = []; foreach ($users as $user) { diff --git a/core/Controller/WellKnownController.php b/core/Controller/WellKnownController.php index 2e317ae01b5d9..44cf29fa8ffe4 100644 --- a/core/Controller/WellKnownController.php +++ b/core/Controller/WellKnownController.php @@ -44,6 +44,7 @@ public function __construct( * @PublicPage * @NoCSRFRequired * + * @param string $service * @return Response */ public function handle(string $service): Response { From 51040b13103da5e7cc63d3dbb1d94dac1a55dbc1 Mon Sep 17 00:00:00 2001 From: Hamid Dehnavi Date: Fri, 14 Jul 2023 17:31:30 +0330 Subject: [PATCH 02/17] Update core/Controller/GuestAvatarController.php Co-authored-by: Joas Schilling <213943+nickvergessen@users.noreply.github.com> Signed-off-by: Hamid Dehnavi --- core/Controller/GuestAvatarController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/Controller/GuestAvatarController.php b/core/Controller/GuestAvatarController.php index 622af81646205..b84c83a9aa597 100644 --- a/core/Controller/GuestAvatarController.php +++ b/core/Controller/GuestAvatarController.php @@ -57,7 +57,7 @@ public function __construct( * @param bool|null $darkTheme * @return FileDisplayResponse|Response */ - public function getAvatar(string $guestName, string $size, ?bool $darkTheme = false): Http\Response|FileDisplayResponse { + public function getAvatar(string $guestName, string $size, ?bool $darkTheme = false): Response|FileDisplayResponse { $size = (int) $size; $darkTheme = $darkTheme ?? false; From be9e908dda0f35c1f6993eff1d22991cd0513b51 Mon Sep 17 00:00:00 2001 From: Hamid Dehnavi Date: Fri, 14 Jul 2023 17:35:43 +0330 Subject: [PATCH 03/17] Make adjustments based on the review Co-authored-by: Joas Schilling Signed-off-by: Hamid Dehnavi --- core/Controller/LoginController.php | 2 +- core/Controller/PreviewController.php | 6 ------ 2 files changed, 1 insertion(+), 7 deletions(-) diff --git a/core/Controller/LoginController.php b/core/Controller/LoginController.php index c975712cd61dc..0da983bf22cdc 100644 --- a/core/Controller/LoginController.php +++ b/core/Controller/LoginController.php @@ -117,7 +117,7 @@ public function logout(): RedirectResponse { * @param string|null $user * @param string|null $redirect_url * - * @return Response + * @return TemplateResponse|RedirectResponse */ #[UseSession] public function showLoginForm(string $user = null, string $redirect_url = null): Http\Response { diff --git a/core/Controller/PreviewController.php b/core/Controller/PreviewController.php index 8b79bb28a64da..bd5d96bdba206 100644 --- a/core/Controller/PreviewController.php +++ b/core/Controller/PreviewController.php @@ -58,12 +58,6 @@ public function __construct( * @NoAdminRequired * @NoCSRFRequired * - * @param string $file - * @param int $x - * @param int $y - * @param bool $a - * @param bool $forceIcon - * @param string $mode * @return Response * @throws NotPermittedException * @throws NoUserException From 7e4ca27097a0f56590d6bc3670d40d1ef86c460b Mon Sep 17 00:00:00 2001 From: Hamid Dehnavi Date: Fri, 14 Jul 2023 17:39:30 +0330 Subject: [PATCH 04/17] Make adjustments based on the review Co-authored-by: Joas Schilling Signed-off-by: Hamid Dehnavi --- core/Controller/PreviewController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/Controller/PreviewController.php b/core/Controller/PreviewController.php index bd5d96bdba206..2deff40d44265 100644 --- a/core/Controller/PreviewController.php +++ b/core/Controller/PreviewController.php @@ -103,7 +103,7 @@ public function getPreviewByFileId( int $y = 32, bool $a = false, bool $forceIcon = true, - string $mode = 'fill'): DataResponse|Response|FileDisplayResponse { + string $mode = 'fill'): DataResponse|FileDisplayResponse { if ($fileId === -1 || $x === 0 || $y === 0) { return new DataResponse([], Http::STATUS_BAD_REQUEST); } From dbda4220932cb67e88ced9c4061e841f6ed2d918 Mon Sep 17 00:00:00 2001 From: Hamid Dehnavi Date: Fri, 14 Jul 2023 17:44:21 +0330 Subject: [PATCH 05/17] Make adjustments based on the review Co-authored-by: Joas Schilling Signed-off-by: Hamid Dehnavi --- core/Controller/PreviewController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/Controller/PreviewController.php b/core/Controller/PreviewController.php index 2deff40d44265..e0787da9d5bea 100644 --- a/core/Controller/PreviewController.php +++ b/core/Controller/PreviewController.php @@ -93,7 +93,7 @@ public function getPreview( * @param bool $a * @param bool $forceIcon * @param string $mode - * @return DataResponse|Response|FileDisplayResponse + * @return DataResponse|FileDisplayResponse * @throws NoUserException * @throws NotPermittedException */ From 8913eb89d5b8747caeb06fde2df0afbf0eb1d6a8 Mon Sep 17 00:00:00 2001 From: Hamid Dehnavi Date: Wed, 19 Jul 2023 15:52:47 +0330 Subject: [PATCH 06/17] Update core/Controller/ClientFlowLoginController.php Co-authored-by: Joas Schilling <213943+nickvergessen@users.noreply.github.com> Signed-off-by: Hamid Dehnavi --- core/Controller/ClientFlowLoginController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/Controller/ClientFlowLoginController.php b/core/Controller/ClientFlowLoginController.php index cc2b9620164b7..823de32aaeabe 100644 --- a/core/Controller/ClientFlowLoginController.php +++ b/core/Controller/ClientFlowLoginController.php @@ -235,7 +235,7 @@ public function grantPage(string $stateToken = '', */ #[UseSession] public function generateAppPassword(string $stateToken, - string $clientIdentifier = ''): Response|StandaloneTemplateResponse|Http\RedirectResponse { + string $clientIdentifier = ''): Response|StandaloneTemplateResponse|RedirectResponse { if (!$this->isValidToken($stateToken)) { $this->session->remove(self::STATE_NAME); return $this->stateTokenForbiddenResponse(); From f24dc3fac6343da12ef319dbd0934a6d7f22443c Mon Sep 17 00:00:00 2001 From: Hamid Dehnavi Date: Wed, 19 Jul 2023 15:52:55 +0330 Subject: [PATCH 07/17] Update core/Controller/CssController.php Co-authored-by: Joas Schilling <213943+nickvergessen@users.noreply.github.com> Signed-off-by: Hamid Dehnavi --- core/Controller/CssController.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/core/Controller/CssController.php b/core/Controller/CssController.php index 4bac668278f0d..f6b77b32df3d8 100644 --- a/core/Controller/CssController.php +++ b/core/Controller/CssController.php @@ -64,10 +64,9 @@ public function __construct( * * @param string $fileName css filename with extension * @param string $appName css folder name - * @return Response - * @throws \Exception + * @return FileDisplayResponse|NotFoundResponse */ - public function getCss(string $fileName, string $appName): Response { + public function getCss(string $fileName, string $appName): FileDisplayResponse|NotFoundResponse { try { $folder = $this->appData->getFolder($appName); $gzip = false; From bc5dbd2c0ceef710e9481283dbf8211ecfd3491c Mon Sep 17 00:00:00 2001 From: Hamid Dehnavi Date: Wed, 19 Jul 2023 15:53:00 +0330 Subject: [PATCH 08/17] Update core/Controller/ContactsMenuController.php Co-authored-by: Joas Schilling <213943+nickvergessen@users.noreply.github.com> Signed-off-by: Hamid Dehnavi --- core/Controller/ContactsMenuController.php | 3 --- 1 file changed, 3 deletions(-) diff --git a/core/Controller/ContactsMenuController.php b/core/Controller/ContactsMenuController.php index 78848e86883c2..7c88bbdeba806 100644 --- a/core/Controller/ContactsMenuController.php +++ b/core/Controller/ContactsMenuController.php @@ -54,9 +54,6 @@ public function index(?string $filter = null): array { /** * @NoAdminRequired * - * @param int $shareType - * @param string $shareWith - * @return JSONResponse|\JsonSerializable * @throws Exception */ public function findOne(int $shareType, string $shareWith): JSONResponse|\JsonSerializable { From 1c942b4f268a04d208b379e4e713b115c1b15e49 Mon Sep 17 00:00:00 2001 From: Hamid Dehnavi Date: Wed, 19 Jul 2023 15:53:07 +0330 Subject: [PATCH 09/17] Update core/Controller/JsController.php Co-authored-by: Joas Schilling <213943+nickvergessen@users.noreply.github.com> Signed-off-by: Hamid Dehnavi --- core/Controller/JsController.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/core/Controller/JsController.php b/core/Controller/JsController.php index bf1e1f245dc5b..a8b9f1f5d1447 100644 --- a/core/Controller/JsController.php +++ b/core/Controller/JsController.php @@ -64,10 +64,9 @@ public function __construct( * * @param string $fileName js filename with extension * @param string $appName js folder name - * @return Response - * @throws \Exception + * @return FileDisplayResponse|NotFoundResponse */ - public function getJs(string $fileName, string $appName): Response { + public function getJs(string $fileName, string $appName): FileDisplayResponse|NotFoundResponse { try { $folder = $this->appData->getFolder($appName); $gzip = false; From 2302df8e5ed4627f48bc9cb745cc42e5c7f13ca7 Mon Sep 17 00:00:00 2001 From: Hamid Dehnavi Date: Wed, 19 Jul 2023 15:53:14 +0330 Subject: [PATCH 10/17] Update core/Controller/LoginController.php Co-authored-by: Joas Schilling <213943+nickvergessen@users.noreply.github.com> Signed-off-by: Hamid Dehnavi --- core/Controller/LoginController.php | 8 -------- 1 file changed, 8 deletions(-) diff --git a/core/Controller/LoginController.php b/core/Controller/LoginController.php index 0da983bf22cdc..ecdc38a3caafa 100644 --- a/core/Controller/LoginController.php +++ b/core/Controller/LoginController.php @@ -264,14 +264,6 @@ private function generateRedirect(?string $redirectUrl): RedirectResponse { * @PublicPage * @NoCSRFRequired * @BruteForceProtection(action=login) - * - * @param Chain $loginChain - * @param string $user - * @param string $password - * @param string|null $redirect_url - * @param string $timezone - * @param string $timezone_offset - * @return RedirectResponse */ #[UseSession] public function tryLogin(Chain $loginChain, From ee576ef14d2ff8a5df1ce9bc8c54dffde6c827b4 Mon Sep 17 00:00:00 2001 From: Hamid Dehnavi Date: Wed, 19 Jul 2023 15:53:20 +0330 Subject: [PATCH 11/17] Update core/Controller/TwoFactorChallengeController.php Co-authored-by: Joas Schilling <213943+nickvergessen@users.noreply.github.com> Signed-off-by: Hamid Dehnavi --- core/Controller/TwoFactorChallengeController.php | 1 - 1 file changed, 1 deletion(-) diff --git a/core/Controller/TwoFactorChallengeController.php b/core/Controller/TwoFactorChallengeController.php index 4f8f8ed5b9bb8..d58c15f3ce03e 100644 --- a/core/Controller/TwoFactorChallengeController.php +++ b/core/Controller/TwoFactorChallengeController.php @@ -85,7 +85,6 @@ private function splitProvidersAndBackupCodes(array $providers): array { * * @param string $redirect_url * @return StandaloneTemplateResponse - * @throws \Exception */ public function selectChallenge($redirect_url): StandaloneTemplateResponse { $user = $this->userSession->getUser(); From b169a24658573901fde7ef0671688c1d4529315e Mon Sep 17 00:00:00 2001 From: Hamid Dehnavi Date: Wed, 19 Jul 2023 15:53:27 +0330 Subject: [PATCH 12/17] Update core/Controller/TwoFactorChallengeController.php Co-authored-by: Joas Schilling <213943+nickvergessen@users.noreply.github.com> Signed-off-by: Hamid Dehnavi --- core/Controller/TwoFactorChallengeController.php | 1 - 1 file changed, 1 deletion(-) diff --git a/core/Controller/TwoFactorChallengeController.php b/core/Controller/TwoFactorChallengeController.php index d58c15f3ce03e..7856d29f4d481 100644 --- a/core/Controller/TwoFactorChallengeController.php +++ b/core/Controller/TwoFactorChallengeController.php @@ -112,7 +112,6 @@ public function selectChallenge($redirect_url): StandaloneTemplateResponse { * @param string $challengeProviderId * @param string $redirect_url * @return StandaloneTemplateResponse|RedirectResponse - * @throws \Exception */ #[UseSession] public function showChallenge(string $challengeProviderId, string $redirect_url): StandaloneTemplateResponse|RedirectResponse { From f2b03d171cef6923dfe20940abdc75430b4c299e Mon Sep 17 00:00:00 2001 From: Hamid Dehnavi Date: Wed, 19 Jul 2023 15:53:34 +0330 Subject: [PATCH 13/17] Update core/Controller/TwoFactorChallengeController.php Co-authored-by: Joas Schilling <213943+nickvergessen@users.noreply.github.com> Signed-off-by: Hamid Dehnavi --- core/Controller/TwoFactorChallengeController.php | 1 - 1 file changed, 1 deletion(-) diff --git a/core/Controller/TwoFactorChallengeController.php b/core/Controller/TwoFactorChallengeController.php index 7856d29f4d481..7967e3c4970e7 100644 --- a/core/Controller/TwoFactorChallengeController.php +++ b/core/Controller/TwoFactorChallengeController.php @@ -204,7 +204,6 @@ public function solveChallenge(string $challengeProviderId, string $challenge, s /** * @NoAdminRequired * @NoCSRFRequired - * @throws \Exception */ public function setupProviders(): StandaloneTemplateResponse { $user = $this->userSession->getUser(); From cd4bbc537c233a5840052b77af13abd521098cb2 Mon Sep 17 00:00:00 2001 From: Hamid Dehnavi Date: Wed, 19 Jul 2023 15:53:43 +0330 Subject: [PATCH 14/17] Update core/Controller/WellKnownController.php Co-authored-by: Joas Schilling <213943+nickvergessen@users.noreply.github.com> Signed-off-by: Hamid Dehnavi --- core/Controller/WellKnownController.php | 3 --- 1 file changed, 3 deletions(-) diff --git a/core/Controller/WellKnownController.php b/core/Controller/WellKnownController.php index 44cf29fa8ffe4..cf8f660a97f65 100644 --- a/core/Controller/WellKnownController.php +++ b/core/Controller/WellKnownController.php @@ -43,9 +43,6 @@ public function __construct( /** * @PublicPage * @NoCSRFRequired - * - * @param string $service - * @return Response */ public function handle(string $service): Response { $response = $this->requestManager->process( From c54a665e14e6e29efa3fcefb929c97a963b916dd Mon Sep 17 00:00:00 2001 From: Hamid Dehnavi Date: Wed, 19 Jul 2023 15:53:53 +0330 Subject: [PATCH 15/17] Update core/Controller/TwoFactorChallengeController.php Co-authored-by: Joas Schilling <213943+nickvergessen@users.noreply.github.com> Signed-off-by: Hamid Dehnavi --- core/Controller/TwoFactorChallengeController.php | 1 - 1 file changed, 1 deletion(-) diff --git a/core/Controller/TwoFactorChallengeController.php b/core/Controller/TwoFactorChallengeController.php index 7967e3c4970e7..59997e54b4aed 100644 --- a/core/Controller/TwoFactorChallengeController.php +++ b/core/Controller/TwoFactorChallengeController.php @@ -220,7 +220,6 @@ public function setupProviders(): StandaloneTemplateResponse { /** * @NoAdminRequired * @NoCSRFRequired - * @throws \Exception */ public function setupProvider(string $providerId): StandaloneTemplateResponse|RedirectResponse { $user = $this->userSession->getUser(); From dde0ef77f8081890aa1a32de15045a7753f7e5a6 Mon Sep 17 00:00:00 2001 From: Hamid Dehnavi Date: Wed, 19 Jul 2023 16:05:32 +0330 Subject: [PATCH 16/17] Make adjustments based on the review Co-authored-by: Louis Chemineau Signed-off-by: Hamid Dehnavi --- core/Controller/ClientFlowLoginController.php | 3 --- 1 file changed, 3 deletions(-) diff --git a/core/Controller/ClientFlowLoginController.php b/core/Controller/ClientFlowLoginController.php index 823de32aaeabe..4b57f8e3186fa 100644 --- a/core/Controller/ClientFlowLoginController.php +++ b/core/Controller/ClientFlowLoginController.php @@ -227,9 +227,6 @@ public function grantPage(string $stateToken = '', /** * @NoAdminRequired * - * @param string $stateToken - * @param string $clientIdentifier - * @return Response|StandaloneTemplateResponse|RedirectResponse * @throws ClientNotFoundException * @throws Exception */ From 78a0f522374d74bb51389306ecd9c093c475495f Mon Sep 17 00:00:00 2001 From: Hamid Dehnavi Date: Mon, 24 Jul 2023 15:22:18 +0330 Subject: [PATCH 17/17] Make adjustments based on the review Signed-off-by: Hamid Dehnavi --- core/Controller/LoginController.php | 1 - core/Controller/PreviewController.php | 21 ------------------- core/Controller/ProfileApiController.php | 8 ------- .../TwoFactorChallengeController.php | 2 +- 4 files changed, 1 insertion(+), 31 deletions(-) diff --git a/core/Controller/LoginController.php b/core/Controller/LoginController.php index ecdc38a3caafa..6788443d4b545 100644 --- a/core/Controller/LoginController.php +++ b/core/Controller/LoginController.php @@ -45,7 +45,6 @@ use OCP\AppFramework\Http\Attribute\UseSession; use OCP\AppFramework\Http\DataResponse; use OCP\AppFramework\Http\RedirectResponse; -use OCP\AppFramework\Http\Response; use OCP\AppFramework\Http\TemplateResponse; use OCP\Defaults; use OCP\IConfig; diff --git a/core/Controller/PreviewController.php b/core/Controller/PreviewController.php index e0787da9d5bea..0e44f458afa27 100644 --- a/core/Controller/PreviewController.php +++ b/core/Controller/PreviewController.php @@ -86,16 +86,6 @@ public function getPreview( /** * @NoAdminRequired * @NoCSRFRequired - * - * @param int $fileId - * @param int $x - * @param int $y - * @param bool $a - * @param bool $forceIcon - * @param string $mode - * @return DataResponse|FileDisplayResponse - * @throws NoUserException - * @throws NotPermittedException */ public function getPreviewByFileId( int $fileId = -1, @@ -120,17 +110,6 @@ public function getPreviewByFileId( return $this->fetchPreview($node, $x, $y, $a, $forceIcon, $mode); } - /** - * @param Node $node - * @param int $x - * @param int $y - * @param bool $a - * @param bool $forceIcon - * @param string $mode - * @return Response - * @throws NotFoundException - * @throws InvalidPathException - */ private function fetchPreview( Node $node, int $x, diff --git a/core/Controller/ProfileApiController.php b/core/Controller/ProfileApiController.php index bb2bc8344a62a..c503327e0e8c7 100644 --- a/core/Controller/ProfileApiController.php +++ b/core/Controller/ProfileApiController.php @@ -54,14 +54,6 @@ public function __construct( * @NoSubAdminRequired * @PasswordConfirmationRequired * @UserRateThrottle(limit=40, period=600) - * @param string $targetUserId - * @param string $paramId - * @param string $visibility - * @return DataResponse - * @throws OCSBadRequestException - * @throws OCSForbiddenException - * @throws OCSNotFoundException - * @throws Exception */ public function setVisibility(string $targetUserId, string $paramId, string $visibility): DataResponse { $requestingUser = $this->userSession->getUser(); diff --git a/core/Controller/TwoFactorChallengeController.php b/core/Controller/TwoFactorChallengeController.php index 59997e54b4aed..6080ce52bba4c 100644 --- a/core/Controller/TwoFactorChallengeController.php +++ b/core/Controller/TwoFactorChallengeController.php @@ -168,7 +168,7 @@ public function showChallenge(string $challengeProviderId, string $redirect_url) * @return RedirectResponse */ #[UseSession] - public function solveChallenge(string $challengeProviderId, string $challenge, string $redirect_url = null): RedirectResponse { + public function solveChallenge(string $challengeProviderId, string $challenge, ?string $redirect_url = null): RedirectResponse { $user = $this->userSession->getUser(); $provider = $this->twoFactorManager->getProvider($user, $challengeProviderId); if (is_null($provider)) {