CircuitBreaker::isAvailable()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 4
cp 0
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
crap 2
1
<?php declare(strict_types=1);
2
3
namespace Aguimaraes\Bureaucrat;
4
5
class CircuitBreaker implements PolicyInterface
6
{
7
    private $failureThreshold;
8
    private $failureAttempts;
9
10
    private $successThreshold;
11
    private $successAttempts;
12
13
    private $delay;
14
15
    private $on = [];
16
17
    private $timeout;
18
19
    public function isAvailable() : bool
20
    {
21
        return true;
22
    }
23
24
    public function withFailureThreshold(int $threshold, int $attempts = null) : CircuitBreaker
25
    {
26
        $this->failureThreshold = $threshold;
27
        $this->failureAttempts = $attempts;
28
29
        return $this;
30
    }
31
32
    public function withSuccessThreshold(int $threshold, int $attempts = null) : CircuitBreaker
33
    {
34
        $this->successThreshold = $threshold;
35
        $this->successAttempts = $attempts;
36
37
        return $this;
38
    }
39
40
    public function withDelay(int $delay, int $unit) : CircuitBreaker
41
    {
42
        $this->delay = $delay * $unit;
43
44
        return $this;
45
    }
46
47
    public function failOnException(string $exception) : CircuitBreaker
48
    {
49
        $this->on = \array_merge($this->on, [$exception]);
50
51
        return $this;
52
    }
53
54
    public function failOnTimeOut(int $timeout, int $unit) : CircuitBreaker
55
    {
56
        $this->timeout = $timeout * $unit;
57
58
        return $this;
59
    }
60
61
    public function run(callable $operation, $args = [])
62
    {
63
        // TODO: Implement run() method.
64
    }
65
}
66