Skip to content

Commit

Permalink
Merge pull request #99 from mad-briller/add.psalm-types
Browse files Browse the repository at this point in the history
Add psalm types to public interfaces to guide static analysis.
  • Loading branch information
ackintosh authored Sep 21, 2022
2 parents 3e6247e + 7c50fab commit 68792cb
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/Ganesha.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/Ganesha/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class Configuration
*/
private $params;

/** @param array $params */
public function __construct($params)
{
if (!isset($params[self::STORAGE_KEYS])) {
Expand Down
1 change: 0 additions & 1 deletion src/Ganesha/Storage.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions src/Ganesha/Strategy/Count/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -27,6 +29,7 @@ class Builder

/**
* @param AdapterInterface $adapter
* @psalm-param (AdapterInterface&SlidingTimeWindowInterface)|(AdapterInterface&TumblingTimeWindowInterface) $adapter
* @return $this
*/
public function adapter(AdapterInterface $adapter): self
Expand All @@ -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
Expand All @@ -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
Expand Down
7 changes: 7 additions & 0 deletions src/Ganesha/Strategy/Rate/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -32,6 +34,7 @@ class Builder

/**
* @param AdapterInterface $adapter
* @psalm-param (AdapterInterface&SlidingTimeWindowInterface)|(AdapterInterface&TumblingTimeWindowInterface) $adapter
* @return $this
*/
public function adapter(AdapterInterface $adapter): self
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
1 change: 0 additions & 1 deletion src/Ganesha/StrategyInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
namespace Ackintosh\Ganesha;

use Ackintosh\Ganesha\Storage\AdapterInterface;
use LogicException;

interface StrategyInterface
{
Expand Down

0 comments on commit 68792cb

Please sign in to comment.