diff options
author | Roeland Jago Douma <roeland@famdouma.nl> | 2019-08-19 19:35:47 +0200 |
---|---|---|
committer | Roeland Jago Douma <roeland@famdouma.nl> | 2019-08-19 19:38:43 +0200 |
commit | 7927aebdeb3a1cf0f7e953ed3adfd1f34898d98c (patch) | |
tree | 9c34d43901b390923ee97943306f2771dde9590f | |
parent | 1521da14ff292cb257f442a5f16c41b29faec337 (diff) | |
download | nextcloud-server-7927aebdeb3a1cf0f7e953ed3adfd1f34898d98c.tar.gz nextcloud-server-7927aebdeb3a1cf0f7e953ed3adfd1f34898d98c.zip |
Fix report of phpstan in Limiter
* unneeded arguments to constructor
* added return types
* let automatic DI do its work
Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
-rw-r--r-- | lib/private/Security/RateLimiting/Limiter.php | 14 | ||||
-rw-r--r-- | lib/private/Server.php | 8 | ||||
-rw-r--r-- | tests/lib/Security/RateLimiting/LimiterTest.php | 8 |
3 files changed, 4 insertions, 26 deletions
diff --git a/lib/private/Security/RateLimiting/Limiter.php b/lib/private/Security/RateLimiting/Limiter.php index 5267497f86f..c272120a898 100644 --- a/lib/private/Security/RateLimiting/Limiter.php +++ b/lib/private/Security/RateLimiting/Limiter.php @@ -28,9 +28,7 @@ use OC\Security\Normalizer\IpAddress; use OC\Security\RateLimiting\Backend\IBackend; use OC\Security\RateLimiting\Exception\RateLimitExceededException; use OCP\AppFramework\Utility\ITimeFactory; -use OCP\IRequest; use OCP\IUser; -use OCP\IUserSession; class Limiter { /** @var IBackend */ @@ -39,14 +37,10 @@ class Limiter { private $timeFactory; /** - * @param IUserSession $userSession - * @param IRequest $request * @param ITimeFactory $timeFactory * @param IBackend $backend */ - public function __construct(IUserSession $userSession, - IRequest $request, - ITimeFactory $timeFactory, + public function __construct(ITimeFactory $timeFactory, IBackend $backend) { $this->backend = $backend; $this->timeFactory = $timeFactory; @@ -62,7 +56,7 @@ class Limiter { private function register(string $methodIdentifier, string $userIdentifier, int $period, - int $limit) { + int $limit): void { $existingAttempts = $this->backend->getAttempts($methodIdentifier, $userIdentifier, $period); if ($existingAttempts >= $limit) { throw new RateLimitExceededException(); @@ -83,7 +77,7 @@ class Limiter { public function registerAnonRequest(string $identifier, int $anonLimit, int $anonPeriod, - string $ip) { + string $ip): void { $ipSubnet = (new IpAddress($ip))->getSubnet(); $anonHashIdentifier = hash('sha512', 'anon::' . $identifier . $ipSubnet); @@ -102,7 +96,7 @@ class Limiter { public function registerUserRequest(string $identifier, int $userLimit, int $userPeriod, - IUser $user) { + IUser $user): void { $userHashIdentifier = hash('sha512', 'user::' . $identifier . $user->getUID()); $this->register($identifier, $userHashIdentifier, $userPeriod, $userLimit); } diff --git a/lib/private/Server.php b/lib/private/Server.php index f919e0b4efb..bce4f0feaef 100644 --- a/lib/private/Server.php +++ b/lib/private/Server.php @@ -597,14 +597,6 @@ class Server extends ServerContainer implements IServerContainer { }); $this->registerAlias('Search', \OCP\ISearch::class); - $this->registerService(\OC\Security\RateLimiting\Limiter::class, function (Server $c) { - return new \OC\Security\RateLimiting\Limiter( - $this->getUserSession(), - $this->getRequest(), - new \OC\AppFramework\Utility\TimeFactory(), - $c->query(\OC\Security\RateLimiting\Backend\IBackend::class) - ); - }); $this->registerService(\OC\Security\RateLimiting\Backend\IBackend::class, function ($c) { return new \OC\Security\RateLimiting\Backend\MemoryCache( $this->getMemCacheFactory(), diff --git a/tests/lib/Security/RateLimiting/LimiterTest.php b/tests/lib/Security/RateLimiting/LimiterTest.php index 80b63ebb391..5d42104ba82 100644 --- a/tests/lib/Security/RateLimiting/LimiterTest.php +++ b/tests/lib/Security/RateLimiting/LimiterTest.php @@ -31,10 +31,6 @@ use OCP\IUserSession; use Test\TestCase; class LimiterTest extends TestCase { - /** @var IUserSession|\PHPUnit_Framework_MockObject_MockObject */ - private $userSession; - /** @var IRequest|\PHPUnit_Framework_MockObject_MockObject */ - private $request; /** @var ITimeFactory|\PHPUnit_Framework_MockObject_MockObject */ private $timeFactory; /** @var IBackend|\PHPUnit_Framework_MockObject_MockObject */ @@ -45,14 +41,10 @@ class LimiterTest extends TestCase { public function setUp() { parent::setUp(); - $this->userSession = $this->createMock(IUserSession::class); - $this->request = $this->createMock(IRequest::class); $this->timeFactory = $this->createMock(ITimeFactory::class); $this->backend = $this->createMock(IBackend::class); $this->limiter = new Limiter( - $this->userSession, - $this->request, $this->timeFactory, $this->backend ); |