FailSafe::with()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 16
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 0
Metric Value
dl 0
loc 16
ccs 0
cts 12
cp 0
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 8
nc 3
nop 1
crap 12
1
<?php declare(strict_types=1);
2
3
namespace Aguimaraes\Bureaucrat;
4
5
class FailSafe
6
{
7
    /**
8
     * @var CircuitBreaker
9
     */
10
    private $circuitBreaker;
11
12
    /**
13
     * @var Retry
14
     */
15
    private $retry;
16
17
    /**
18
     * @param $policy
19
     *
20
     * @return FailSafe
21
     * @throws \InvalidArgumentException
22
     */
23
    public function with($policy) : FailSafe
24
    {
25
        if ($policy instanceof CircuitBreaker) {
26
            $this->circuitBreaker = $policy;
27
28
            return $this;
29
        }
30
31
        if ($policy instanceof Retry) {
32
            $this->retry = $policy;
33
34
            return $this;
35
        }
36
37
        throw new \InvalidArgumentException('Argument is an invalid policy');
38
    }
39
40
    /**
41
     * @param $policy
42
     *
43
     * @return FailSafe
44
     * @throws \InvalidArgumentException
45
     */
46
    public function and($policy) : FailSafe
47
    {
48
        return $this->with($policy);
49
    }
50
51
    public function run(callable $operation, array $args = [])
0 ignored issues
show
Unused Code introduced by
The parameter $operation is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $args is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
52
    {
53
        // TODO
54
    }
55
}
56