Pimp sharingcheckmiddleware

Reported by psalm

Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
This commit is contained in:
Roeland Jago Douma 2021-03-02 20:36:04 +01:00
parent 04dc321ee7
commit 5c952e83fc
1 changed files with 9 additions and 16 deletions

View File

@ -1,4 +1,6 @@
<?php <?php
declare(strict_types=1);
/** /**
* @copyright Copyright (c) 2016, ownCloud, Inc. * @copyright Copyright (c) 2016, ownCloud, Inc.
* *
@ -33,12 +35,12 @@ use OCP\App\IAppManager;
use OCP\AppFramework\Controller; use OCP\AppFramework\Controller;
use OCP\AppFramework\Http\JSONResponse; use OCP\AppFramework\Http\JSONResponse;
use OCP\AppFramework\Http\NotFoundResponse; use OCP\AppFramework\Http\NotFoundResponse;
use OCP\AppFramework\Http\Response;
use OCP\AppFramework\Middleware; use OCP\AppFramework\Middleware;
use OCP\AppFramework\Utility\IControllerMethodReflector; use OCP\AppFramework\Utility\IControllerMethodReflector;
use OCP\Files\NotFoundException; use OCP\Files\NotFoundException;
use OCP\IConfig; use OCP\IConfig;
use OCP\IRequest; use OCP\IRequest;
use OCP\Share\Exceptions\ShareNotFound;
use OCP\Share\IManager; use OCP\Share\IManager;
/** /**
@ -61,15 +63,7 @@ class SharingCheckMiddleware extends Middleware {
/** @var IRequest */ /** @var IRequest */
protected $request; protected $request;
/*** public function __construct(string $appName,
* @param string $appName
* @param IConfig $config
* @param IAppManager $appManager
* @param IControllerMethodReflector $reflector
* @param IManager $shareManager
* @param IRequest $request
*/
public function __construct($appName,
IConfig $config, IConfig $config,
IAppManager $appManager, IAppManager $appManager,
IControllerMethodReflector $reflector, IControllerMethodReflector $reflector,
@ -91,9 +85,8 @@ class SharingCheckMiddleware extends Middleware {
* @param string $methodName * @param string $methodName
* @throws NotFoundException * @throws NotFoundException
* @throws S2SException * @throws S2SException
* @throws ShareNotFound
*/ */
public function beforeController($controller, $methodName) { public function beforeController($controller, $methodName): void {
if (!$this->isSharingEnabled()) { if (!$this->isSharingEnabled()) {
throw new NotFoundException('Sharing is disabled.'); throw new NotFoundException('Sharing is disabled.');
} }
@ -110,10 +103,10 @@ class SharingCheckMiddleware extends Middleware {
* @param Controller $controller * @param Controller $controller
* @param string $methodName * @param string $methodName
* @param \Exception $exception * @param \Exception $exception
* @return NotFoundResponse * @return Response
* @throws \Exception * @throws \Exception
*/ */
public function afterException($controller, $methodName, \Exception $exception) { public function afterException($controller, $methodName, \Exception $exception): Response {
if (is_a($exception, NotFoundException::class)) { if (is_a($exception, NotFoundException::class)) {
return new NotFoundResponse(); return new NotFoundResponse();
} }
@ -129,7 +122,7 @@ class SharingCheckMiddleware extends Middleware {
* Checks for externalshares controller * Checks for externalshares controller
* @return bool * @return bool
*/ */
private function externalSharesChecks() { private function externalSharesChecks(): bool {
if (!$this->reflector->hasAnnotation('NoIncomingFederatedSharingRequired') && if (!$this->reflector->hasAnnotation('NoIncomingFederatedSharingRequired') &&
$this->config->getAppValue('files_sharing', 'incoming_server2server_share_enabled', 'yes') !== 'yes') { $this->config->getAppValue('files_sharing', 'incoming_server2server_share_enabled', 'yes') !== 'yes') {
return false; return false;
@ -147,7 +140,7 @@ class SharingCheckMiddleware extends Middleware {
* Check whether sharing is enabled * Check whether sharing is enabled
* @return bool * @return bool
*/ */
private function isSharingEnabled() { private function isSharingEnabled(): bool {
// FIXME: This check is done here since the route is globally defined and not inside the files_sharing app // FIXME: This check is done here since the route is globally defined and not inside the files_sharing app
// Check whether the sharing application is enabled // Check whether the sharing application is enabled
if (!$this->appManager->isEnabledForUser($this->appName)) { if (!$this->appManager->isEnabledForUser($this->appName)) {