RequestsPool   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 8
dl 0
loc 28
rs 10
c 0
b 0
f 0
wmc 5

4 Methods

Rating   Name   Duplication   Size   Complexity  
A isEmpty() 0 3 1
A add() 0 3 1
A shift() 0 3 1
A rejectAll() 0 5 2
1
<?php
2
3
namespace seregazhuk\React\Memcached\Request;
4
5
use seregazhuk\React\Memcached\Exception\Exception;
6
7
final class RequestsPool
8
{
9
    /**
10
     * @var Request[]
11
     */
12
    private $requests = [];
13
14
    public function add(Request $request): void
15
    {
16
        $this->requests[] = $request;
17
    }
18
19
    public function shift(): Request
20
    {
21
        return array_shift($this->requests);
22
    }
23
24
    public function rejectAll(Exception $exception): void
25
    {
26
        while (!$this->isEmpty()) {
27
            $request = $this->shift();
28
            $request->reject($exception);
29
        }
30
    }
31
32
    public function isEmpty(): bool
33
    {
34
        return empty($this->requests);
35
    }
36
}
37