From 7c50fabedd558cf1c794951501e51603a36a3f88 Mon Sep 17 00:00:00 2001 From: Brad <28307684+mad-briller@users.noreply.github.com> Date: Thu, 15 Sep 2022 13:32:04 +0100 Subject: [PATCH] Add psalm types to public interfaces to guide static analysis. --- src/Ganesha.php | 1 + src/Ganesha/Configuration.php | 1 + src/Ganesha/Storage.php | 1 - src/Ganesha/Strategy/Count/Builder.php | 5 +++++ src/Ganesha/Strategy/Rate/Builder.php | 7 +++++++ src/Ganesha/StrategyInterface.php | 1 - 6 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/Ganesha.php b/src/Ganesha.php index beb5161..3436ba2 100644 --- a/src/Ganesha.php +++ b/src/Ganesha.php @@ -113,6 +113,7 @@ public function isAvailable($service): bool /** * @param callable $callable + * @psalm-param callable(self::EVENT_*, string, string): void $callable * @return void */ public function subscribe(callable $callable): void diff --git a/src/Ganesha/Configuration.php b/src/Ganesha/Configuration.php index 9d82099..4db8868 100644 --- a/src/Ganesha/Configuration.php +++ b/src/Ganesha/Configuration.php @@ -21,6 +21,7 @@ class Configuration */ private $params; + /** @param array $params */ public function __construct($params) { if (!isset($params[self::STORAGE_KEYS])) { diff --git a/src/Ganesha/Storage.php b/src/Ganesha/Storage.php index 7c3be36..4bcb885 100644 --- a/src/Ganesha/Storage.php +++ b/src/Ganesha/Storage.php @@ -5,7 +5,6 @@ use Ackintosh\Ganesha\Storage\Adapter\TumblingTimeWindowInterface; use Ackintosh\Ganesha\Storage\Adapter\SlidingTimeWindowInterface; use Ackintosh\Ganesha\Storage\AdapterInterface; -use Ackintosh\Ganesha\Storage\StorageKeys; use Ackintosh\Ganesha\Storage\StorageKeysInterface; class Storage diff --git a/src/Ganesha/Strategy/Count/Builder.php b/src/Ganesha/Strategy/Count/Builder.php index 276a935..7c62cfb 100644 --- a/src/Ganesha/Strategy/Count/Builder.php +++ b/src/Ganesha/Strategy/Count/Builder.php @@ -4,6 +4,8 @@ use Ackintosh\Ganesha; use Ackintosh\Ganesha\Configuration; use Ackintosh\Ganesha\Storage\AdapterInterface; +use Ackintosh\Ganesha\Storage\Adapter\SlidingTimeWindowInterface; +use Ackintosh\Ganesha\Storage\Adapter\TumblingTimeWindowInterface; class Builder { @@ -27,6 +29,7 @@ class Builder /** * @param AdapterInterface $adapter + * @psalm-param (AdapterInterface&SlidingTimeWindowInterface)|(AdapterInterface&TumblingTimeWindowInterface) $adapter * @return $this */ public function adapter(AdapterInterface $adapter): self @@ -37,6 +40,7 @@ public function adapter(AdapterInterface $adapter): self /** * @param int $failureCountThreshold + * @psalm-param int<1, max> $failureCountThreshold * @return $this */ public function failureCountThreshold(int $failureCountThreshold): self @@ -47,6 +51,7 @@ public function failureCountThreshold(int $failureCountThreshold): self /** * @param int $intervalToHalfOpen + * @psalm-param int<1, max> $intervalToHalfOpen * @return $this */ public function intervalToHalfOpen(int $intervalToHalfOpen): self diff --git a/src/Ganesha/Strategy/Rate/Builder.php b/src/Ganesha/Strategy/Rate/Builder.php index 409dd99..754b5bc 100644 --- a/src/Ganesha/Strategy/Rate/Builder.php +++ b/src/Ganesha/Strategy/Rate/Builder.php @@ -3,6 +3,8 @@ use Ackintosh\Ganesha\Configuration; use Ackintosh\Ganesha\Storage\AdapterInterface; +use Ackintosh\Ganesha\Storage\Adapter\SlidingTimeWindowInterface; +use Ackintosh\Ganesha\Storage\Adapter\TumblingTimeWindowInterface; use Ackintosh\Ganesha\Storage\StorageKeysInterface; use Ackintosh\Ganesha\Traits\BuildGanesha; @@ -32,6 +34,7 @@ class Builder /** * @param AdapterInterface $adapter + * @psalm-param (AdapterInterface&SlidingTimeWindowInterface)|(AdapterInterface&TumblingTimeWindowInterface) $adapter * @return $this */ public function adapter(AdapterInterface $adapter): self @@ -42,6 +45,7 @@ public function adapter(AdapterInterface $adapter): self /** * @param int $failureRateThreshold + * @psalm-param int<1, 100> $failureRateThreshold * @return $this */ public function failureRateThreshold(int $failureRateThreshold): self @@ -52,6 +56,7 @@ public function failureRateThreshold(int $failureRateThreshold): self /** * @param int $intervalToHalfOpen + * @psalm-param int<1, max> $intervalToHalfOpen * @return $this */ public function intervalToHalfOpen(int $intervalToHalfOpen): self @@ -72,6 +77,7 @@ public function storageKeys(StorageKeysInterface $storageKeys): self /** * @param int $minimumRequests + * @psalm-param int<1, max> $minimumRequests * @return $this */ public function minimumRequests(int $minimumRequests): self @@ -82,6 +88,7 @@ public function minimumRequests(int $minimumRequests): self /** * @param int $timeWindow + * @psalm-param int<1, max> $timeWindow * @return $this */ public function timeWindow(int $timeWindow): self diff --git a/src/Ganesha/StrategyInterface.php b/src/Ganesha/StrategyInterface.php index 498a949..69b087f 100644 --- a/src/Ganesha/StrategyInterface.php +++ b/src/Ganesha/StrategyInterface.php @@ -2,7 +2,6 @@ namespace Ackintosh\Ganesha; use Ackintosh\Ganesha\Storage\AdapterInterface; -use LogicException; interface StrategyInterface {