From a5ddab2eae29c7caf2287d51301aa12f28357c67 Mon Sep 17 00:00:00 2001 From: Amrouche Hamza Date: Wed, 7 Aug 2019 07:37:35 +0200 Subject: [PATCH] [Lock] add type-hint whenever possible --- src/Symfony/Component/Lock/Lock.php | 4 ++-- src/Symfony/Component/Lock/LockInterface.php | 4 +--- .../Component/Lock/PersistingStoreInterface.php | 2 +- src/Symfony/Component/Lock/Store/CombinedStore.php | 2 +- src/Symfony/Component/Lock/Store/FlockStore.php | 2 +- src/Symfony/Component/Lock/Store/MemcachedStore.php | 2 +- src/Symfony/Component/Lock/Store/PdoStore.php | 2 +- src/Symfony/Component/Lock/Store/RedisStore.php | 2 +- .../Component/Lock/Store/RetryTillSaveStore.php | 2 +- src/Symfony/Component/Lock/Store/SemaphoreStore.php | 2 +- src/Symfony/Component/Lock/Store/ZookeeperStore.php | 2 +- .../Component/Lock/Strategy/ConsensusStrategy.php | 4 ++-- .../Component/Lock/Strategy/StrategyInterface.php | 10 ++-------- .../Component/Lock/Strategy/UnanimousStrategy.php | 4 ++-- 14 files changed, 18 insertions(+), 26 deletions(-) diff --git a/src/Symfony/Component/Lock/Lock.php b/src/Symfony/Component/Lock/Lock.php index f7da528d1c..f641258a47 100644 --- a/src/Symfony/Component/Lock/Lock.php +++ b/src/Symfony/Component/Lock/Lock.php @@ -67,7 +67,7 @@ final class Lock implements LockInterface, LoggerAwareInterface /** * {@inheritdoc} */ - public function acquire($blocking = false): ?bool + public function acquire(bool $blocking = false): bool { try { if ($blocking) { @@ -114,7 +114,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; diff --git a/src/Symfony/Component/Lock/LockInterface.php b/src/Symfony/Component/Lock/LockInterface.php index d5c0324857..40b75244b3 100644 --- a/src/Symfony/Component/Lock/LockInterface.php +++ b/src/Symfony/Component/Lock/LockInterface.php @@ -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. diff --git a/src/Symfony/Component/Lock/PersistingStoreInterface.php b/src/Symfony/Component/Lock/PersistingStoreInterface.php index f3095db0c0..03309a90b5 100644 --- a/src/Symfony/Component/Lock/PersistingStoreInterface.php +++ b/src/Symfony/Component/Lock/PersistingStoreInterface.php @@ -49,5 +49,5 @@ interface PersistingStoreInterface * * @throws LockConflictedException */ - public function putOffExpiration(Key $key, $ttl); + public function putOffExpiration(Key $key, float $ttl); } diff --git a/src/Symfony/Component/Lock/Store/CombinedStore.php b/src/Symfony/Component/Lock/Store/CombinedStore.php index 49d40566a4..4dee0fa269 100644 --- a/src/Symfony/Component/Lock/Store/CombinedStore.php +++ b/src/Symfony/Component/Lock/Store/CombinedStore.php @@ -106,7 +106,7 @@ class CombinedStore implements PersistingStoreInterface, LoggerAwareInterface /** * {@inheritdoc} */ - public function putOffExpiration(Key $key, $ttl) + public function putOffExpiration(Key $key, float $ttl) { $successCount = 0; $failureCount = 0; diff --git a/src/Symfony/Component/Lock/Store/FlockStore.php b/src/Symfony/Component/Lock/Store/FlockStore.php index d1c303c534..b2a8bc20d5 100644 --- a/src/Symfony/Component/Lock/Store/FlockStore.php +++ b/src/Symfony/Component/Lock/Store/FlockStore.php @@ -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. } diff --git a/src/Symfony/Component/Lock/Store/MemcachedStore.php b/src/Symfony/Component/Lock/Store/MemcachedStore.php index d16ca15450..505e6fa5ea 100644 --- a/src/Symfony/Component/Lock/Store/MemcachedStore.php +++ b/src/Symfony/Component/Lock/Store/MemcachedStore.php @@ -83,7 +83,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)); diff --git a/src/Symfony/Component/Lock/Store/PdoStore.php b/src/Symfony/Component/Lock/Store/PdoStore.php index a35e142061..bf2d6bc6ff 100644 --- a/src/Symfony/Component/Lock/Store/PdoStore.php +++ b/src/Symfony/Component/Lock/Store/PdoStore.php @@ -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)); diff --git a/src/Symfony/Component/Lock/Store/RedisStore.php b/src/Symfony/Component/Lock/Store/RedisStore.php index c1aecbfcd2..79403a138b 100644 --- a/src/Symfony/Component/Lock/Store/RedisStore.php +++ b/src/Symfony/Component/Lock/Store/RedisStore.php @@ -86,7 +86,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 diff --git a/src/Symfony/Component/Lock/Store/RetryTillSaveStore.php b/src/Symfony/Component/Lock/Store/RetryTillSaveStore.php index 18890536f0..79e28ce745 100644 --- a/src/Symfony/Component/Lock/Store/RetryTillSaveStore.php +++ b/src/Symfony/Component/Lock/Store/RetryTillSaveStore.php @@ -80,7 +80,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); } diff --git a/src/Symfony/Component/Lock/Store/SemaphoreStore.php b/src/Symfony/Component/Lock/Store/SemaphoreStore.php index 829da3bfc6..328380280b 100644 --- a/src/Symfony/Component/Lock/Store/SemaphoreStore.php +++ b/src/Symfony/Component/Lock/Store/SemaphoreStore.php @@ -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. } diff --git a/src/Symfony/Component/Lock/Store/ZookeeperStore.php b/src/Symfony/Component/Lock/Store/ZookeeperStore.php index 681416c905..0db550c469 100644 --- a/src/Symfony/Component/Lock/Store/ZookeeperStore.php +++ b/src/Symfony/Component/Lock/Store/ZookeeperStore.php @@ -96,7 +96,7 @@ class ZookeeperStore implements PersistingStoreInterface /** * {@inheritdoc} */ - public function putOffExpiration(Key $key, $ttl) + public function putOffExpiration(Key $key, float $ttl) { // do nothing, zookeeper locks forever. } diff --git a/src/Symfony/Component/Lock/Strategy/ConsensusStrategy.php b/src/Symfony/Component/Lock/Strategy/ConsensusStrategy.php index 047820a409..1338b10dd6 100644 --- a/src/Symfony/Component/Lock/Strategy/ConsensusStrategy.php +++ b/src/Symfony/Component/Lock/Strategy/ConsensusStrategy.php @@ -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); } diff --git a/src/Symfony/Component/Lock/Strategy/StrategyInterface.php b/src/Symfony/Component/Lock/Strategy/StrategyInterface.php index beaa7280a2..7c5f9d8cdf 100644 --- a/src/Symfony/Component/Lock/Strategy/StrategyInterface.php +++ b/src/Symfony/Component/Lock/Strategy/StrategyInterface.php @@ -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); } diff --git a/src/Symfony/Component/Lock/Strategy/UnanimousStrategy.php b/src/Symfony/Component/Lock/Strategy/UnanimousStrategy.php index 27404f3e9f..63f9d1b4a1 100644 --- a/src/Symfony/Component/Lock/Strategy/UnanimousStrategy.php +++ b/src/Symfony/Component/Lock/Strategy/UnanimousStrategy.php @@ -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; }