minor #33004 [Lock] add type-hint whenever possible (Simperfit)

This PR was merged into the 5.0-dev branch.

Discussion
----------

[Lock] add type-hint whenever possible

| Q             | A
| ------------- | ---
| Branch?       | 5.0
| Bug fix?      | no
| New feature?  | no <!-- please update src/**/CHANGELOG.md files -->
| BC breaks?    | no     <!-- see https://symfony.com/bc -->
| Deprecations? |no <!-- please update UPGRADE-*.md and src/**/CHANGELOG.md files -->
| Tests pass?   | yes    <!-- please add some, will be required by reviewers -->
| Fixed tickets | Contribute to #32179 <!-- #-prefixed issue number(s), if any -->
| License       | MIT
| Doc PR        | symfony/symfony-docs#... <!-- required for new features -->

<!--
Replace this notice by a short README for your feature/bugfix. This will help people
understand your PR and can be used as a start for the documentation.

Additionally (see https://symfony.com/roadmap):
 - Bug fixes must be submitted against the lowest maintained branch where they apply
   (lowest branches are regularly merged to upper ones so they get the fixes too).
 - Features and deprecations must be submitted against branch 4.4.
 - Legacy code removals go to the master branch.
-->
Add type-hint in the lock component

Commits
-------

a5ddab2eae [Lock] add type-hint whenever possible
This commit is contained in:
Nicolas Grekas 2019-08-08 14:18:32 +02:00
commit 3f6c59ae7b
14 changed files with 18 additions and 26 deletions

View File

@ -65,7 +65,7 @@ final class Lock implements LockInterface, LoggerAwareInterface
/**
* {@inheritdoc}
*/
public function acquire($blocking = false): bool
public function acquire(bool $blocking = false): bool
{
try {
if ($blocking) {
@ -112,7 +112,7 @@ final class Lock implements LockInterface, LoggerAwareInterface
/**
* {@inheritdoc}
*/
public function refresh($ttl = null)
public function refresh(float $ttl = null)
{
if (null === $ttl) {
$ttl = $this->ttl;

View File

@ -26,14 +26,12 @@ interface LockInterface
* Acquires the lock. If the lock is acquired by someone else, the parameter `blocking` determines whether or not
* the call should block until the release of the lock.
*
* @param bool $blocking Whether or not the Lock should wait for the release of someone else
*
* @return bool whether or not the lock had been acquired
*
* @throws LockConflictedException If the lock is acquired by someone else in blocking mode
* @throws LockAcquiringException If the lock can not be acquired
*/
public function acquire($blocking = false);
public function acquire(bool $blocking = false);
/**
* Increase the duration of an acquired lock.

View File

@ -49,5 +49,5 @@ interface PersistingStoreInterface
*
* @throws LockConflictedException
*/
public function putOffExpiration(Key $key, $ttl);
public function putOffExpiration(Key $key, float $ttl);
}

View File

@ -93,7 +93,7 @@ class CombinedStore implements PersistingStoreInterface, LoggerAwareInterface
/**
* {@inheritdoc}
*/
public function putOffExpiration(Key $key, $ttl)
public function putOffExpiration(Key $key, float $ttl)
{
$successCount = 0;
$failureCount = 0;

View File

@ -106,7 +106,7 @@ class FlockStore implements BlockingStoreInterface
/**
* {@inheritdoc}
*/
public function putOffExpiration(Key $key, $ttl)
public function putOffExpiration(Key $key, float $ttl)
{
// do nothing, the flock locks forever.
}

View File

@ -72,7 +72,7 @@ class MemcachedStore implements PersistingStoreInterface
/**
* {@inheritdoc}
*/
public function putOffExpiration(Key $key, $ttl)
public function putOffExpiration(Key $key, float $ttl)
{
if ($ttl < 1) {
throw new InvalidTtlException(sprintf('%s() expects a TTL greater or equals to 1 second. Got %s.', __METHOD__, $ttl));

View File

@ -152,7 +152,7 @@ class PdoStore implements PersistingStoreInterface
/**
* {@inheritdoc}
*/
public function putOffExpiration(Key $key, $ttl)
public function putOffExpiration(Key $key, float $ttl)
{
if ($ttl < 1) {
throw new InvalidTtlException(sprintf('%s() expects a TTL greater or equals to 1 second. Got %s.', __METHOD__, $ttl));

View File

@ -75,7 +75,7 @@ class RedisStore implements PersistingStoreInterface
/**
* {@inheritdoc}
*/
public function putOffExpiration(Key $key, $ttl)
public function putOffExpiration(Key $key, float $ttl)
{
$script = '
if redis.call("GET", KEYS[1]) == ARGV[1] then

View File

@ -79,7 +79,7 @@ class RetryTillSaveStore implements BlockingStoreInterface, LoggerAwareInterface
/**
* {@inheritdoc}
*/
public function putOffExpiration(Key $key, $ttl)
public function putOffExpiration(Key $key, float $ttl)
{
$this->decorated->putOffExpiration($key, $ttl);
}

View File

@ -100,7 +100,7 @@ class SemaphoreStore implements BlockingStoreInterface
/**
* {@inheritdoc}
*/
public function putOffExpiration(Key $key, $ttl)
public function putOffExpiration(Key $key, float $ttl)
{
// do nothing, the semaphore locks forever.
}

View File

@ -84,7 +84,7 @@ class ZookeeperStore implements PersistingStoreInterface
/**
* {@inheritdoc}
*/
public function putOffExpiration(Key $key, $ttl)
public function putOffExpiration(Key $key, float $ttl)
{
// do nothing, zookeeper locks forever.
}

View File

@ -21,7 +21,7 @@ class ConsensusStrategy implements StrategyInterface
/**
* {@inheritdoc}
*/
public function isMet($numberOfSuccess, $numberOfItems)
public function isMet(int $numberOfSuccess, int $numberOfItems)
{
return $numberOfSuccess > ($numberOfItems / 2);
}
@ -29,7 +29,7 @@ class ConsensusStrategy implements StrategyInterface
/**
* {@inheritdoc}
*/
public function canBeMet($numberOfFailure, $numberOfItems)
public function canBeMet(int $numberOfFailure, int $numberOfItems)
{
return $numberOfFailure < ($numberOfItems / 2);
}

View File

@ -21,12 +21,9 @@ interface StrategyInterface
/**
* Returns whether or not the quorum is met.
*
* @param int $numberOfSuccess
* @param int $numberOfItems
*
* @return bool
*/
public function isMet($numberOfSuccess, $numberOfItems);
public function isMet(int $numberOfSuccess, int $numberOfItems);
/**
* Returns whether or not the quorum *could* be met.
@ -34,10 +31,7 @@ interface StrategyInterface
* This method does not mean the quorum *would* be met for sure, but can be useful to stop a process early when you
* known there is no chance to meet the quorum.
*
* @param int $numberOfFailure
* @param int $numberOfItems
*
* @return bool
*/
public function canBeMet($numberOfFailure, $numberOfItems);
public function canBeMet(int $numberOfFailure, int $numberOfItems);
}

View File

@ -21,7 +21,7 @@ class UnanimousStrategy implements StrategyInterface
/**
* {@inheritdoc}
*/
public function isMet($numberOfSuccess, $numberOfItems)
public function isMet(int $numberOfSuccess, int $numberOfItems)
{
return $numberOfSuccess === $numberOfItems;
}
@ -29,7 +29,7 @@ class UnanimousStrategy implements StrategyInterface
/**
* {@inheritdoc}
*/
public function canBeMet($numberOfFailure, $numberOfItems)
public function canBeMet(int $numberOfFailure, int $numberOfItems)
{
return 0 === $numberOfFailure;
}