Completed
Push — master ( c0eda5...1ea1f4 )
by Sergey
03:04
created

RequestsPool::rejectAllWith()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 3
nc 2
nop 1
dl 0
loc 5
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace seregazhuk\React\Memcached\Request;
4
5
use seregazhuk\React\Memcached\Exception\Exception;
6
7
class RequestsPool
8
{
9
    /**
10
     * @var Request[]
11
     */
12
    private $requests = [];
13
14
    /**
15
     * @param Request $request
16
     */
17
    public function add(Request $request)
18
    {
19
        $this->requests[] = $request;
20
    }
21
22
    /**
23
     * @return Request
24
     */
25
    public function shift()
26
    {
27
        return array_shift($this->requests);
28
    }
29
30
    /**
31
     * @param Exception $exception
32
     */
33
    public function rejectAllWith(Exception $exception)
34
    {
35
        while (!$this->isEmpty()) {
36
            $request = $this->shift();
37
            $request->reject($exception);
38
        }
39
    }
40
41
    /**
42
     * @return bool
43
     */
44
    public function isEmpty()
45
    {
46
        return empty($this->requests);
47
    }
48
}
49