1 | <?php declare(strict_types = 1); |
||
9 | class CircuitBreakerService |
||
10 | { |
||
11 | use PsrLoggerTrait; |
||
12 | |||
13 | const OPEN = 'open'; |
||
|
|||
14 | const CLOSED = 'closed'; |
||
15 | const HALFOPEN = 'half-open'; |
||
16 | |||
17 | /** |
||
18 | * @var AbstractAdapter |
||
19 | */ |
||
20 | private $cacheApp; |
||
21 | |||
22 | /** |
||
23 | * @var array |
||
24 | */ |
||
25 | private $status; |
||
26 | |||
27 | /** |
||
28 | * @var int |
||
29 | */ |
||
30 | private $threshold; |
||
31 | |||
32 | /** |
||
33 | * @var int |
||
34 | */ |
||
35 | private $timeout; |
||
36 | |||
37 | /** |
||
38 | * @param AbstractAdapter $cacheApp |
||
39 | * @param int $threshold |
||
40 | * @param int $timeout |
||
41 | */ |
||
42 | public function __construct(AbstractAdapter $cacheApp, int $threshold, int $timeout) |
||
48 | |||
49 | /** |
||
50 | * @param string $key The service key |
||
51 | * @param bool $status The service status (true: up, false: down) |
||
52 | */ |
||
53 | public function save(string $key, bool $status) |
||
69 | |||
70 | /** |
||
71 | * Verify if service is open. |
||
72 | * |
||
73 | * @param string $service |
||
74 | * |
||
75 | * @return bool |
||
76 | */ |
||
77 | public function isOpen(string $service): bool |
||
87 | |||
88 | /** |
||
89 | * Increment number of fail to one service |
||
90 | * |
||
91 | * @param string $service |
||
92 | */ |
||
93 | private function countFailure(string $service) |
||
112 | |||
113 | /** |
||
114 | * Open circuit breaker. |
||
115 | * |
||
116 | * @param string $service |
||
117 | */ |
||
118 | private function tripBreaker(string $service) |
||
123 | |||
124 | /** |
||
125 | * CLose circuit breaker, and reset value to fail service. |
||
126 | * |
||
127 | * @param string $service |
||
128 | */ |
||
129 | private function resetCount(string $service) |
||
138 | |||
139 | /** |
||
140 | * HalfOpen circuit breaker. |
||
141 | * |
||
142 | * @param string $service |
||
143 | */ |
||
144 | private function attemptReset(string $service) |
||
149 | |||
150 | /** |
||
151 | * @var LoggerInterface |
||
152 | */ |
||
153 | private $logger; |
||
154 | |||
155 | /** |
||
156 | * @param LoggerInterface $logger |
||
157 | */ |
||
158 | public function setLogger(LoggerInterface $logger) |
||
162 | |||
163 | /** |
||
164 | * @param string $level |
||
165 | * @param string $message |
||
166 | * @param array $context |
||
167 | */ |
||
168 | public function log($level, $message, array $context = array()) |
||
172 | } |
||
173 |
This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.
To visualize
will produce issues in the first and second line, while this second example
will produce no issues.