8000 [Lock] add type-hint whenever possible · symfony/symfony@a5ddab2 · GitHub
[go: up one dir, main page]

Skip to content

Commit a5ddab2

Browse files
Simperfitnicolas-grekas
authored andcommitted
[Lock] add type-hint whenever possible
1 parent d65189f commit a5ddab2

14 files changed

+18
-26
lines changed

src/Symfony/Component/Lock/Lock.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public function __destruct()
6767
/**
6868
* {@inheritdoc}
6969
*/
70-
public function acquire($blocking = false): ?bool
70+
public function acquire(bool $blocking = false): bool
7171
{
7272
try {
7373
if ($blocking) {
@@ -114,7 +114,7 @@ public function acquire($blocking = false): ?bool
114114
/**
115115
* {@inheritdoc}
116116
*/
117-
public function refresh($ttl = null)
117+
public function refresh(float $ttl = null)
118118
{
119119
if (null === $ttl) {
120120
$ttl = $this->ttl;

src/Symfony/Component/Lock/LockInterface.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,12 @@ interface LockInterface
2626
* Acquires the lock. If the lock is acquired by someone else, the parameter `blocking` determines whether or not
2727
* the call should block until the release of the lock.
2828
*
29-
* @param bool $blocking Whether or not the Lock should wait for the release of someone else
30-
*
3129
* @return bool whether or not the lock had been acquired
3230
*
3331
* @throws LockConflictedException If the lock is acquired by someone else in blocking mode
3432
* @throws LockAcquiringException If the lock can not be acquired
3533
*/
36-
public function acquire($blocking = false);
34+
public function acquire(bool $blocking = false);
3735

3836
/**
3937
* Increase the duration of an acquired lock.

src/Symfony/Component/Lock/PersistingStoreInterface.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,5 +49,5 @@ public function exists(Key $key);
4949
*
5050
* @throws LockConflictedException
5151
*/
52-
public function putOffExpiration(Key $key, $ttl);
52+
public function putOffExpiration(Key $key, float $ttl);
5353
}

src/Symfony/Component/Lock/Store/CombinedStore.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ public function waitAndSave(Key $key)
106106
/**
107107
* {@inheritdoc}
108108
*/
109-
public function putOffExpiration(Key $key, $ttl)
109+
public function putOffExpiration(Key $key, float $ttl)
110110
{
111111
$successCount = 0;
112112
$failureCount = 0;

src/Symfony/Component/Lock/Store/FlockStore.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ private function lock(Key $key, bool $blocking)
106106
/**
107107
* {@inheritdoc}
108108
*/
109-
public function putOffExpiration(Key $key, $ttl)
109+
public function putOffExpiration(Key $key, float $ttl)
110110
{
111111
// do nothing, the flock locks forever.
112112
}

src/Symfony/Component/Lock/Store/MemcachedStore.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ public function waitAndSave(Key $key)
8383
/**
8484
* {@inheritdoc}
8585
*/
86-
public function putOffExpiration(Key $key, $ttl)
86+
public function putOffExpiration(Key $key, float $ttl)
8787
{
8888
if ($ttl < 1) {
8989
throw new InvalidTtlException(sprintf('%s() expects a TTL greater or equals to 1 second. Got %s.', __METHOD__, $ttl));

src/Symfony/Component/Lock/Store/PdoStore.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ public function waitAndSave(Key $key)
152152
/**
153153
* {@inheritdoc}
154154
*/
155-
public function putOffExpiration(Key $key, $ttl)
155+
public function putOffExpiration(Key $key, float $ttl)
156156
{
157157
if ($ttl < 1) {
158158
throw new InvalidTtlException(sprintf('%s() expects a TTL greater or equals to 1 second. Got %s.', __METHOD__, $ttl));

src/Symfony/Component/Lock/Store/RedisStore.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ public function waitAndSave(Key $key)
8686
/**
8787
* {@inheritdoc}
8888
*/
89-
public function putOffExpiration(Key $key, $ttl)
89+
public function putOffExpiration(Key $key, float $ttl)
9090
{
9191
$script = '
9292
if redis.call("GET", KEYS[1]) == ARGV[1] then

src/Symfony/Component/Lock/Store/RetryTillSaveStore.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ public function waitAndSave(Key $key)
8080
/**
8181
* {@inheritdoc}
8282
*/
83-
public function putOffExpiration(Key $key, $ttl)
83+
public function putOffExpiration(Key $key, float $ttl)
8484
{
8585
$this->decorated->putOffExpiration($key, $ttl);
8686
}

src/Symfony/Component/Lock/Store/SemaphoreStore.php

Lines changed: 1 addition & 1 deletion
Original file line numberD 10000 iff line numberDiff line change
@@ -100,7 +100,7 @@ public function delete(Key $key)
100100
/**
101101
* {@inheritdoc}
102102
*/
103-
public function putOffExpiration(Key $key, $ttl)
103+
public function putOffExpiration(Key $key, float $ttl)
104104
{
105105
// do nothing, the semaphore locks forever.
106106
}

src/Symfony/Component/Lock/Store/ZookeeperStore.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ public function waitAndSave(Key $key)
9696
/**
9797
* {@inheritdoc}
9898
*/
99-
public function putOffExpiration(Key $key, $ttl)
99+
public function putOffExpiration(Key $key, float $ttl)
100100
{
101101
// do nothing, zookeeper locks forever.
102102
}

src/Symfony/Component/Lock/Strategy/ConsensusStrategy.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,15 @@ class ConsensusStrategy implements StrategyInterface
2121
/**
2222
* {@inheritdoc}
2323
*/
24-
public function isMet($numberOfSuccess, $numberOfItems)
24+
public function isMet(int $numberOfSuccess, int $numberOfItems)
2525
{
2626
return $numberOfSuccess > ($numberOfItems / 2);
2727
}
2828

2929
/**
3030
* {@inheritdoc}
3131
*/
32-
public function canBeMet($numberOfFailure, $numberOfItems)
32+
public function canBeMet(int $numberOfFailure, int $numberOfItems)
3333
{
3434
return $numberOfFailure < ($numberOfItems / 2);
3535
}

src/Symfony/Component/Lock/Strategy/StrategyInterface.php

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,23 +21,17 @@ interface StrategyInterface
2121
/**
2222
* Returns whether or not the quorum is met.
2323
*
24-
* @param int $numberOfSuccess
25-
* @param int $numberOfItems
26-
*
2724
* @return bool
2825
*/
29-
public function isMet($numberOfSuccess, $numberOfItems);
26+
public function isMet(int $numberOfSuccess, int $numberOfItems);
3027

3128
/**
3229
* Returns whether or not the quorum *could* be met.
3330
*
3431
* This method does not mean the quorum *would* be met for sure, but can be useful to stop a process early when you
3532
* known there is no chance to meet the quorum.
3633
*
37-
* @param int $numberOfFailure
38-
* @param int $numberOfItems
39-
*
4034
* @return bool
4135
*/
42-
public function canBeMet($numberOfFailure, $numberOfItems);
36+
public function canBeMet(int $numberOfFailure, int $numberOfItems);
4337
}

src/Symfony/Component/Lock/Strategy/UnanimousStrategy.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,15 @@ class UnanimousStrategy implements StrategyInterface
2121
/**
2222
* {@inheritdoc}
2323
*/
24-
public function isMet($numberOfSuccess, $numberOfItems)
24+
public function isMet(int $numberOfSuccess, int $numberOfItems)
2525
{
2626
return $numberOfSuccess === $numberOfItems;
2727
}
2828

2929
/**
3030
* {@inheritdoc}
3131
*/
32-
public function canBeMet($numberOfFailure, $numberOfItems)
32+
public function canBeMet(int $numberOfFailure, int $numberOfItems)
3333
{
3434
return 0 === $numberOfFailure;
3535
}

0 commit comments

Comments
 (0)
0