Skip to content

Commit afa6143

Browse files
committed
template return callable types
1 parent fbefa48 commit afa6143

File tree

6 files changed

+21
-15
lines changed

6 files changed

+21
-15
lines changed

src/mutex/CASMutex.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,11 @@ public function notify(): void
6868
* });
6969
* </code>
7070
*
71-
* @param callable $code The synchronized execution block.
71+
* @template T
72+
* @param callable(): T $code The synchronized execution block.
7273
* @throws \Exception The execution block threw an exception.
7374
* @throws TimeoutException The timeout was reached.
74-
* @return mixed The return value of the execution block.
75+
* @return T The return value of the execution block.
7576
*
7677
*/
7778
public function synchronized(callable $code)

src/mutex/Mutex.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,16 @@ abstract class Mutex
2121
* The code block may throw an exception. In this case the lock will be
2222
* released as well.
2323
*
24-
* @param callable $code The synchronized execution callback.
24+
* @template T
25+
* @param callable(): T $code The synchronized execution callback.
2526
* @throws \Exception The execution callback threw an exception.
2627
* @throws \malkusch\lock\exception\LockAcquireException The mutex could not
2728
* be acquired, no further side effects.
2829
* @throws \malkusch\lock\exception\LockReleaseException The mutex could not
2930
* be released, the code was already executed.
3031
* @throws \malkusch\lock\exception\ExecutionOutsideLockException Some code
3132
* has been executed outside of the lock.
32-
* @return mixed The return value of the execution callback.
33+
* @return T The return value of the execution callback.
3334
*/
3435
abstract public function synchronized(callable $code);
3536

@@ -48,7 +49,7 @@ abstract public function synchronized(callable $code);
4849
* });
4950
* </code>
5051
*
51-
* @param callable $check Callback that decides if the lock should be
52+
* @param callable(): bool $check Callback that decides if the lock should be
5253
* acquired and if the synchronized callback should be executed after
5354
* acquiring the lock.
5455
* @return \malkusch\lock\util\DoubleCheckedLocking The double-checked

src/mutex/TransactionalMutex.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,10 +97,11 @@ private static function checkAutocommit(\PDO $pdo): void
9797
* If the code throws any other exception, the transaction is rolled back
9898
* and won't be replayed.
9999
*
100-
* @param callable $code The synchronized execution block.
100+
* @template T
101+
* @param callable(): T $code The synchronized execution block.
101102
* @throws \Exception The execution block threw an exception.
102103
* @throws LockAcquireException The transaction was not commited.
103-
* @return mixed The return value of the execution block.
104+
* @return T The return value of the execution block.
104105
* @SuppressWarnings(PHPMD)
105106
*/
106107
public function synchronized(callable $code)

src/util/DoubleCheckedLocking.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class DoubleCheckedLocking
2020
private $mutex;
2121

2222
/**
23-
* @var callable The check.
23+
* @var callable(): bool The check.
2424
*/
2525
private $check;
2626

@@ -29,7 +29,7 @@ class DoubleCheckedLocking
2929
*
3030
* @param \malkusch\lock\mutex\Mutex $mutex Provides methods for exclusive
3131
* code execution.
32-
* @param callable $check Callback that decides if the lock should be
32+
* @param callable(): bool $check Callback that decides if the lock should be
3333
* acquired and if the critical code callback should be executed after
3434
* acquiring the lock.
3535
*/
@@ -48,7 +48,8 @@ public function __construct(Mutex $mutex, callable $check)
4848
* critical code callback to indicate that processing did not occure or has
4949
* failed. It is up to the user to decide the last point.
5050
*
51-
* @param callable $code The critical code callback.
51+
* @template T
52+
* @param callable(): T $code The critical code callback.
5253
* @throws \Exception The execution callback or the check threw an
5354
* exception.
5455
* @throws \malkusch\lock\exception\LockAcquireException The mutex could not
@@ -57,7 +58,7 @@ public function __construct(Mutex $mutex, callable $check)
5758
* be released.
5859
* @throws \malkusch\lock\exception\ExecutionOutsideLockException Some code
5960
* has been executed outside of the lock.
60-
* @return mixed Boolean false if check did not pass or mixed for what ever
61+
* @return T|false Boolean false if check did not pass or mixed for what ever
6162
* the critical code callback returns.
6263
*/
6364
public function then(callable $code)

src/util/Loop.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,11 +76,12 @@ public function end(): void
7676
*
7777
* If the code throws an exception it will stop repeating the execution.
7878
*
79-
* @param callable $code The to be executed code callback.
79+
* @template T
80+
* @param callable(): T $code The to be executed code callback.
8081
* @throws \Exception The execution callback threw an exception.
8182
* @throws \malkusch\lock\exception\TimeoutException The timeout has been
8283
* reached.
83-
* @return mixed The return value of the executed code callback.
84+
* @return T The return value of the executed code callback.
8485
*
8586
*/
8687
public function execute(callable $code)

src/util/PcntlTimeout.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,13 @@ public function __construct(int $timeout)
5555
* method. It will interfer with your application and lead to unexpected
5656
* behaviour.
5757
*
58-
* @param callable $code Executed code block
58+
* @template T
59+
* @param callable(): T $code Executed code block
5960
* @throws \malkusch\lock\exception\DeadlineException Running the code hit
6061
* the deadline.
6162
* @throws \malkusch\lock\exception\LockAcquireException Installing the
6263
* timeout failed.
63-
* @return mixed Return value of the executed block
64+
* @return T Return value of the executed block
6465
*/
6566
public function timeBoxed(callable $code)
6667
{

0 commit comments

Comments
 (0)