Merge pull request #25895 from nextcloud/techdept/psalm/pimp_sharingcheckmiddleware

Pimp sharingcheckmiddleware
This commit is contained in:
Roeland Jago Douma 2021-03-03 10:28:32 +01:00 committed by GitHub
commit a1be5f33af
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 9 additions and 16 deletions

View File

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