Skip to content

Commit

Permalink
Merge pull request #7 from EasyWelfare/fix-phpstan
Browse files Browse the repository at this point in the history
Add more typehints from phpstan
  • Loading branch information
jszobody committed Jul 18, 2018
2 parents daeb088 + 3867f0c commit 88b9a4a
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 30 deletions.
34 changes: 17 additions & 17 deletions src/Backoff.php
Expand Up @@ -47,14 +47,14 @@ class Backoff
];

/**
* @var
* @var int
*/
protected $maxAttempts;

/**
* The max wait time you want to allow, regardless of what the strategy says
*
* @var int In milliseconds
* @var int|null In milliseconds
*/
protected $waitCap;

Expand All @@ -81,11 +81,11 @@ class Backoff
protected $errorHandler;

/**
* @param null $maxAttempts
* @param null $strategy
* @param null $waitCap
* @param null $useJitter
* @param null $decider
* @param int $maxAttempts
* @param mixed $strategy
* @param int $waitCap
* @param bool $useJitter
* @param callable $decider
*/
public function __construct(
$maxAttempts = null,
Expand Down Expand Up @@ -118,7 +118,7 @@ public function getMaxAttempts()
}

/**
* @param $cap
* @param int|null $cap
*
* @return $this
*/
Expand All @@ -130,15 +130,15 @@ public function setWaitCap($cap)
}

/**
* @return int
* @return int|null
*/
public function getWaitCap()
{
return $this->waitCap;
}

/**
* @param $useJitter
* @param bool $useJitter
*
* @return $this
*/
Expand Down Expand Up @@ -221,7 +221,7 @@ protected function buildStrategy($strategy)
}

/**
* @param $callback
* @param callable $callback
*
* @return mixed
* @throws Exception
Expand Down Expand Up @@ -255,7 +255,7 @@ public function run($callback)

/**
* Sets the decider callback
* @param $callback
* @param callable $callback
* @return $this
*/
public function setDecider($callback)
Expand All @@ -266,7 +266,7 @@ public function setDecider($callback)

/**
* Sets the error handler callback
* @param $callback
* @param callable $callback
* @return $this
*/
public function setErrorHandler($callback)
Expand All @@ -291,7 +291,7 @@ protected function getDefaultDecider()
}

/**
* @param $attempt
* @param int $attempt
*/
public function wait($attempt)
{
Expand All @@ -303,7 +303,7 @@ public function wait($attempt)
}

/**
* @param $attempt
* @param int $attempt
*
* @return int
*/
Expand All @@ -315,7 +315,7 @@ public function getWaitTime($attempt)
}

/**
* @param $waitTime
* @param int $waitTime
*
* @return mixed
*/
Expand All @@ -327,7 +327,7 @@ protected function cap($waitTime)
}

/**
* @param $waitTime
* @param int $waitTime
*
* @return int
*/
Expand Down
6 changes: 3 additions & 3 deletions src/Strategies/AbstractStrategy.php
Expand Up @@ -21,7 +21,7 @@ abstract class AbstractStrategy
/**
* AbstractStrategy constructor.
*
* @param null $base
* @param int $base
*/
public function __construct($base = null)
{
Expand All @@ -31,14 +31,14 @@ public function __construct($base = null)
}

/**
* @param $attempt
* @param int $attempt
*
* @return int Time to wait in ms
*/
abstract public function getWaitTime($attempt);

/**
* @param $attempt
* @param int $attempt
*
* @return int
*/
Expand Down
2 changes: 1 addition & 1 deletion src/Strategies/ConstantStrategy.php
Expand Up @@ -8,7 +8,7 @@
class ConstantStrategy extends AbstractStrategy
{
/**
* @param $attempt
* @param int $attempt
*
* @return int
*/
Expand Down
7 changes: 4 additions & 3 deletions src/Strategies/ExponentialStrategy.php
Expand Up @@ -8,14 +8,15 @@
class ExponentialStrategy extends AbstractStrategy
{
/**
* @param $attempt
* @param int $attempt
*
* @return int
*/
public function getWaitTime($attempt)
{
return $attempt == 1
return (int) ($attempt == 1
? $this->base
: pow(2, $attempt) * $this->base;
: pow(2, $attempt) * $this->base
);
}
}
2 changes: 1 addition & 1 deletion src/Strategies/LinearStrategy.php
Expand Up @@ -8,7 +8,7 @@
class LinearStrategy extends AbstractStrategy
{
/**
* @param $attempt
* @param int $attempt
*
* @return int
*/
Expand Down
10 changes: 5 additions & 5 deletions src/Strategies/PolynomialStrategy.php
Expand Up @@ -8,15 +8,15 @@
class PolynomialStrategy extends AbstractStrategy
{
/**
* @var int|null
* @var int
*/
protected $degree = 2;

/**
* PolynomialStrategy constructor.
*
* @param null $degree
* @param null $base
* @param int $degree
* @param int $base
*/
public function __construct($base = null, $degree = null)
{
Expand All @@ -28,13 +28,13 @@ public function __construct($base = null, $degree = null)
}

/**
* @param $attempt
* @param int $attempt
*
* @return int
*/
public function getWaitTime($attempt)
{
return pow($attempt, $this->degree) * $this->base;
return (int) pow($attempt, $this->degree) * $this->base;
}

/**
Expand Down

0 comments on commit 88b9a4a

Please sign in to comment.