Skip to content

Commit ce56502

Browse files
wouterjnicolas-grekas
authored andcommitted
[Components] Convert to native return types
1 parent c239615 commit ce56502

18 files changed

+61
-231
lines changed

BlockingSharedLockStoreInterface.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,7 @@ interface BlockingSharedLockStoreInterface extends SharedLockStoreInterface
2121
/**
2222
* Waits until a key becomes free for reading, then stores the resource.
2323
*
24-
* @return void
25-
*
2624
* @throws LockConflictedException
2725
*/
28-
public function waitAndSaveRead(Key $key);
26+
public function waitAndSaveRead(Key $key): void;
2927
}

BlockingStoreInterface.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,7 @@ interface BlockingStoreInterface extends PersistingStoreInterface
2121
/**
2222
* Waits until a key becomes free, then stores the resource.
2323
*
24-
* @return void
25-
*
2624
* @throws LockConflictedException
2725
*/
28-
public function waitAndSave(Key $key);
26+
public function waitAndSave(Key $key): void;
2927
}

LockFactory.php

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,8 @@ public function __construct(PersistingStoreInterface $store)
4040
* @param string $resource The resource to lock
4141
* @param float|null $ttl Maximum expected lock duration in seconds
4242
* @param bool $autoRelease Whether to automatically release the lock or not when the lock instance is destroyed
43-
*
44-
* @return SharedLockInterface
4543
*/
46-
public function createLock(string $resource, ?float $ttl = 300.0, bool $autoRelease = true): LockInterface
44+
public function createLock(string $resource, ?float $ttl = 300.0, bool $autoRelease = true): SharedLockInterface
4745
{
4846
return $this->createLockFromKey(new Key($resource), $ttl, $autoRelease);
4947
}
@@ -54,10 +52,8 @@ public function createLock(string $resource, ?float $ttl = 300.0, bool $autoRele
5452
* @param Key $key The key containing the lock's state
5553
* @param float|null $ttl Maximum expected lock duration in seconds
5654
* @param bool $autoRelease Whether to automatically release the lock or not when the lock instance is destroyed
57-
*
58-
* @return SharedLockInterface
5955
*/
60-
public function createLockFromKey(Key $key, ?float $ttl = 300.0, bool $autoRelease = true): LockInterface
56+
public function createLockFromKey(Key $key, ?float $ttl = 300.0, bool $autoRelease = true): SharedLockInterface
6157
{
6258
$lock = new Lock($key, $this->store, $ttl, $autoRelease);
6359
$lock->setLogger($this->logger);

LockInterface.php

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,10 @@ public function acquire(bool $blocking = false): bool;
3636
*
3737
* @param float|null $ttl Maximum expected lock duration in seconds
3838
*
39-
* @return void
40-
*
4139
* @throws LockConflictedException If the lock is acquired by someone else
4240
* @throws LockAcquiringException If the lock cannot be refreshed
4341
*/
44-
public function refresh(float $ttl = null);
42+
public function refresh(float $ttl = null): void;
4543

4644
/**
4745
* Returns whether or not the lock is acquired.
@@ -51,11 +49,9 @@ public function isAcquired(): bool;
5149
/**
5250
* Release the lock.
5351
*
54-
* @return void
55-
*
5652
* @throws LockReleasingException If the lock cannot be released
5753
*/
58-
public function release();
54+
public function release(): void;
5955

6056
public function isExpired(): bool;
6157

PersistingStoreInterface.php

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,21 +23,17 @@ interface PersistingStoreInterface
2323
/**
2424
* Stores the resource if it's not locked by someone else.
2525
*
26-
* @return void
27-
*
2826
* @throws LockAcquiringException
2927
* @throws LockConflictedException
3028
*/
31-
public function save(Key $key);
29+
public function save(Key $key): void;
3230

3331
/**
3432
* Removes a resource from the storage.
3533
*
36-
* @return void
37-
*
3834
* @throws LockReleasingException
3935
*/
40-
public function delete(Key $key);
36+
public function delete(Key $key): void;
4137

4238
/**
4339
* Returns whether or not the resource exists in the storage.
@@ -49,9 +45,7 @@ public function exists(Key $key): bool;
4945
*
5046
* @param float $ttl amount of seconds to keep the lock in the store
5147
*
52-
* @return void
53-
*
5448
* @throws LockConflictedException
5549
*/
56-
public function putOffExpiration(Key $key, float $ttl);
50+
public function putOffExpiration(Key $key, float $ttl): void;
5751
}

SharedLockStoreInterface.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,7 @@ interface SharedLockStoreInterface extends PersistingStoreInterface
2121
/**
2222
* Stores the resource if it's not locked for reading by someone else.
2323
*
24-
* @return void
25-
*
2624
* @throws LockConflictedException
2725
*/
28-
public function saveRead(Key $key);
26+
public function saveRead(Key $key): void;
2927
}

Store/CombinedStore.php

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,7 @@ public function __construct(array $stores, StrategyInterface $strategy)
5353
$this->logger = new NullLogger();
5454
}
5555

56-
/**
57-
* @return void
58-
*/
59-
public function save(Key $key)
56+
public function save(Key $key): void
6057
{
6158
$successCount = 0;
6259
$failureCount = 0;
@@ -90,10 +87,7 @@ public function save(Key $key)
9087
throw new LockConflictedException();
9188
}
9289

93-
/**
94-
* @return void
95-
*/
96-
public function saveRead(Key $key)
90+
public function saveRead(Key $key): void
9791
{
9892
$successCount = 0;
9993
$failureCount = 0;
@@ -131,10 +125,7 @@ public function saveRead(Key $key)
131125
throw new LockConflictedException();
132126
}
133127

134-
/**
135-
* @return void
136-
*/
137-
public function putOffExpiration(Key $key, float $ttl)
128+
public function putOffExpiration(Key $key, float $ttl): void
138129
{
139130
$successCount = 0;
140131
$failureCount = 0;
@@ -175,10 +166,7 @@ public function putOffExpiration(Key $key, float $ttl)
175166
throw new LockConflictedException();
176167
}
177168

178-
/**
179-
* @return void
180-
*/
181-
public function delete(Key $key)
169+
public function delete(Key $key): void
182170
{
183171
foreach ($this->stores as $store) {
184172
try {

Store/DoctrineDbalPostgreSqlStore.php

Lines changed: 6 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,7 @@ public function __construct(#[\SensitiveParameter] Connection|string $connOrUrl)
7171
}
7272
}
7373

74-
/**
75-
* @return void
76-
*/
77-
public function save(Key $key)
74+
public function save(Key $key): void
7875
{
7976
// prevent concurrency within the same connection
8077
$this->getInternalStore()->save($key);
@@ -106,10 +103,7 @@ public function save(Key $key)
106103
throw new LockConflictedException();
107104
}
108105

109-
/**
110-
* @return void
111-
*/
112-
public function saveRead(Key $key)
106+
public function saveRead(Key $key): void
113107
{
114108
// prevent concurrency within the same connection
115109
$this->getInternalStore()->saveRead($key);
@@ -141,10 +135,7 @@ public function saveRead(Key $key)
141135
throw new LockConflictedException();
142136
}
143137

144-
/**
145-
* @return void
146-
*/
147-
public function putOffExpiration(Key $key, float $ttl)
138+
public function putOffExpiration(Key $key, float $ttl): void
148139
{
149140
// postgresql locks forever.
150141
// check if lock still exists
@@ -153,10 +144,7 @@ public function putOffExpiration(Key $key, float $ttl)
153144
}
154145
}
155146

156-
/**
157-
* @return void
158-
*/
159-
public function delete(Key $key)
147+
public function delete(Key $key): void
160148
{
161149
// Prevent deleting locks own by an other key in the same connection
162150
if (!$this->exists($key)) {
@@ -193,10 +181,7 @@ public function exists(Key $key): bool
193181
return false;
194182
}
195183

196-
/**
197-
* @return void
198-
*/
199-
public function waitAndSave(Key $key)
184+
public function waitAndSave(Key $key): void
200185
{
201186
// prevent concurrency within the same connection
202187
// Internal store does not allow blocking mode, because there is no way to acquire one in a single process
@@ -219,10 +204,7 @@ public function waitAndSave(Key $key)
219204
$this->unlockShared($key);
220205
}
221206

222-
/**
223-
* @return void
224-
*/
225-
public function waitAndSaveRead(Key $key)
207+
public function waitAndSaveRead(Key $key): void
226208
{
227209
// prevent concurrency within the same connection
228210
// Internal store does not allow blocking mode, because there is no way to acquire one in a single process

Store/DoctrineDbalStore.php

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -90,10 +90,7 @@ public function __construct(Connection|string $connOrUrl, array $options = [], f
9090
}
9191
}
9292

93-
/**
94-
* @return void
95-
*/
96-
public function save(Key $key)
93+
public function save(Key $key): void
9794
{
9895
$key->reduceLifetime($this->initialTtl);
9996

@@ -132,10 +129,7 @@ public function save(Key $key)
132129
$this->checkNotExpired($key);
133130
}
134131

135-
/**
136-
* @return void
137-
*/
138-
public function putOffExpiration(Key $key, $ttl)
132+
public function putOffExpiration(Key $key, $ttl): void
139133
{
140134
if ($ttl < 1) {
141135
throw new InvalidTtlException(sprintf('"%s()" expects a TTL greater or equals to 1 second. Got "%s".', __METHOD__, $ttl));
@@ -166,10 +160,7 @@ public function putOffExpiration(Key $key, $ttl)
166160
$this->checkNotExpired($key);
167161
}
168162

169-
/**
170-
* @return void
171-
*/
172-
public function delete(Key $key)
163+
public function delete(Key $key): void
173164
{
174165
$this->conn->delete($this->table, [
175166
$this->idCol => $this->getHashedKey($key),

Store/FlockStore.php

Lines changed: 6 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -50,34 +50,22 @@ public function __construct(string $lockPath = null)
5050
$this->lockPath = $lockPath;
5151
}
5252

53-
/**
54-
* @return void
55-
*/
56-
public function save(Key $key)
53+
public function save(Key $key): void
5754
{
5855
$this->lock($key, false, false);
5956
}
6057

61-
/**
62-
* @return void
63-
*/
64-
public function saveRead(Key $key)
58+
public function saveRead(Key $key): void
6559
{
6660
$this->lock($key, true, false);
6761
}
6862

69-
/**
70-
* @return void
71-
*/
72-
public function waitAndSave(Key $key)
63+
public function waitAndSave(Key $key): void
7364
{
7465
$this->lock($key, false, true);
7566
}
7667

77-
/**
78-
* @return void
79-
*/
80-
public function waitAndSaveRead(Key $key)
68+
public function waitAndSaveRead(Key $key): void
8169
{
8270
$this->lock($key, true, true);
8371
}
@@ -132,18 +120,12 @@ private function lock(Key $key, bool $read, bool $blocking): void
132120
$key->markUnserializable();
133121
}
134122

135-
/**
136-
* @return void
137-
*/
138-
public function putOffExpiration(Key $key, float $ttl)
123+
public function putOffExpiration(Key $key, float $ttl): void
139124
{
140125
// do nothing, the flock locks forever.
141126
}
142127

143-
/**
144-
* @return void
145-
*/
146-
public function delete(Key $key)
128+
public function delete(Key $key): void
147129
{
148130
// The lock is maybe not acquired.
149131
if (!$key->hasState(__CLASS__)) {

Store/InMemoryStore.php

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,7 @@ class InMemoryStore implements SharedLockStoreInterface
2626
private array $locks = [];
2727
private array $readLocks = [];
2828

29-
/**
30-
* @return void
31-
*/
32-
public function save(Key $key)
29+
public function save(Key $key): void
3330
{
3431
$hashKey = (string) $key;
3532
$token = $this->getUniqueToken($key);
@@ -57,10 +54,7 @@ public function save(Key $key)
5754
$this->locks[$hashKey] = $token;
5855
}
5956

60-
/**
61-
* @return void
62-
*/
63-
public function saveRead(Key $key)
57+
public function saveRead(Key $key): void
6458
{
6559
$hashKey = (string) $key;
6660
$token = $this->getUniqueToken($key);
@@ -84,18 +78,12 @@ public function saveRead(Key $key)
8478
$this->readLocks[$hashKey][$token] = true;
8579
}
8680

87-
/**
88-
* @return void
89-
*/
90-
public function putOffExpiration(Key $key, float $ttl)
81+
public function putOffExpiration(Key $key, float $ttl): void
9182
{
9283
// do nothing, memory locks forever.
9384
}
9485

95-
/**
96-
* @return void
97-
*/
98-
public function delete(Key $key)
86+
public function delete(Key $key): void
9987
{
10088
$hashKey = (string) $key;
10189
$token = $this->getUniqueToken($key);

0 commit comments

Comments
 (0)