ConcurrentProofFunctionCaller   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 1
dl 0
loc 28
ccs 10
cts 10
cp 1
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B executeFunction() 0 25 4
1
<?php
2
/******************************************************************************
3
 * Copyright (c) 2016 Constantin Galbenu <[email protected]>             *
4
 ******************************************************************************/
5
6
namespace Gica\Cqrs\Command\CommandDispatcher;
7
8
9
use Gica\Cqrs\Command\Exception\TooManyCommandExecutionRetries;
10
use Gica\Cqrs\EventStore\Exception\ConcurrentModificationException;
11
12
class ConcurrentProofFunctionCaller
13
{
14 8
    public function executeFunction($pureFunction, $maxRetries, array $arguments = [])
15
    {
16 8
        $retries = -1;
17
        do {
18
            try {
19
20
                /**
21
                 * The real function call
22
                 */
23 8
                return call_user_func_array($pureFunction, $arguments);
24
25 3
            } catch (ConcurrentModificationException $e) {
26
27 2
                $retries++;
28 2
                if ($retries >= $maxRetries) {
29 1
                    break;
30
                }
31
32 2
                continue;//retry
33
            }
34
35 2
        } while (true);
36
37 1
        throw new TooManyCommandExecutionRetries(sprintf("TooManyCommandExecutionRetries: %d (%s)", $retries, $e->getMessage()));
38
    }
39
}