Skip to content

Commit 68792cb

Browse files
authored
Merge pull request #99 from mad-briller/add.psalm-types
Add psalm types to public interfaces to guide static analysis.
2 parents 3e6247e + 7c50fab commit 68792cb

File tree

6 files changed

+14
-2
lines changed

6 files changed

+14
-2
lines changed

src/Ganesha.php

+1
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ public function isAvailable($service): bool
113113

114114
/**
115115
* @param callable $callable
116+
* @psalm-param callable(self::EVENT_*, string, string): void $callable
116117
* @return void
117118
*/
118119
public function subscribe(callable $callable): void

src/Ganesha/Configuration.php

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ class Configuration
2121
*/
2222
private $params;
2323

24+
/** @param array $params */
2425
public function __construct($params)
2526
{
2627
if (!isset($params[self::STORAGE_KEYS])) {

src/Ganesha/Storage.php

-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
use Ackintosh\Ganesha\Storage\Adapter\TumblingTimeWindowInterface;
66
use Ackintosh\Ganesha\Storage\Adapter\SlidingTimeWindowInterface;
77
use Ackintosh\Ganesha\Storage\AdapterInterface;
8-
use Ackintosh\Ganesha\Storage\StorageKeys;
98
use Ackintosh\Ganesha\Storage\StorageKeysInterface;
109

1110
class Storage

src/Ganesha/Strategy/Count/Builder.php

+5
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
use Ackintosh\Ganesha;
55
use Ackintosh\Ganesha\Configuration;
66
use Ackintosh\Ganesha\Storage\AdapterInterface;
7+
use Ackintosh\Ganesha\Storage\Adapter\SlidingTimeWindowInterface;
8+
use Ackintosh\Ganesha\Storage\Adapter\TumblingTimeWindowInterface;
79

810
class Builder
911
{
@@ -27,6 +29,7 @@ class Builder
2729

2830
/**
2931
* @param AdapterInterface $adapter
32+
* @psalm-param (AdapterInterface&SlidingTimeWindowInterface)|(AdapterInterface&TumblingTimeWindowInterface) $adapter
3033
* @return $this
3134
*/
3235
public function adapter(AdapterInterface $adapter): self
@@ -37,6 +40,7 @@ public function adapter(AdapterInterface $adapter): self
3740

3841
/**
3942
* @param int $failureCountThreshold
43+
* @psalm-param int<1, max> $failureCountThreshold
4044
* @return $this
4145
*/
4246
public function failureCountThreshold(int $failureCountThreshold): self
@@ -47,6 +51,7 @@ public function failureCountThreshold(int $failureCountThreshold): self
4751

4852
/**
4953
* @param int $intervalToHalfOpen
54+
* @psalm-param int<1, max> $intervalToHalfOpen
5055
* @return $this
5156
*/
5257
public function intervalToHalfOpen(int $intervalToHalfOpen): self

src/Ganesha/Strategy/Rate/Builder.php

+7
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33

44
use Ackintosh\Ganesha\Configuration;
55
use Ackintosh\Ganesha\Storage\AdapterInterface;
6+
use Ackintosh\Ganesha\Storage\Adapter\SlidingTimeWindowInterface;
7+
use Ackintosh\Ganesha\Storage\Adapter\TumblingTimeWindowInterface;
68
use Ackintosh\Ganesha\Storage\StorageKeysInterface;
79
use Ackintosh\Ganesha\Traits\BuildGanesha;
810

@@ -32,6 +34,7 @@ class Builder
3234

3335
/**
3436
* @param AdapterInterface $adapter
37+
* @psalm-param (AdapterInterface&SlidingTimeWindowInterface)|(AdapterInterface&TumblingTimeWindowInterface) $adapter
3538
* @return $this
3639
*/
3740
public function adapter(AdapterInterface $adapter): self
@@ -42,6 +45,7 @@ public function adapter(AdapterInterface $adapter): self
4245

4346
/**
4447
* @param int $failureRateThreshold
48+
* @psalm-param int<1, 100> $failureRateThreshold
4549
* @return $this
4650
*/
4751
public function failureRateThreshold(int $failureRateThreshold): self
@@ -52,6 +56,7 @@ public function failureRateThreshold(int $failureRateThreshold): self
5256

5357
/**
5458
* @param int $intervalToHalfOpen
59+
* @psalm-param int<1, max> $intervalToHalfOpen
5560
* @return $this
5661
*/
5762
public function intervalToHalfOpen(int $intervalToHalfOpen): self
@@ -72,6 +77,7 @@ public function storageKeys(StorageKeysInterface $storageKeys): self
7277

7378
/**
7479
* @param int $minimumRequests
80+
* @psalm-param int<1, max> $minimumRequests
7581
* @return $this
7682
*/
7783
public function minimumRequests(int $minimumRequests): self
@@ -82,6 +88,7 @@ public function minimumRequests(int $minimumRequests): self
8288

8389
/**
8490
* @param int $timeWindow
91+
* @psalm-param int<1, max> $timeWindow
8592
* @return $this
8693
*/
8794
public function timeWindow(int $timeWindow): self

src/Ganesha/StrategyInterface.php

-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
namespace Ackintosh\Ganesha;
33

44
use Ackintosh\Ganesha\Storage\AdapterInterface;
5-
use LogicException;
65

76
interface StrategyInterface
87
{

0 commit comments

Comments
 (0)