RequestManager::hasRequest()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 1
crap 1
1
<?php
2
/*
3
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
4
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
5
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
6
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
7
 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
8
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
9
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
10
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
11
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
12
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
13
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
14
 *
15
 * This software consists of voluntary contributions made by many individuals
16
 * and is licensed under the MIT license.
17
 */
18
namespace Elastification\Client\Request;
19
20
use Elastification\Client\Exception\RequestManagerException;
21
22
/**
23
 * Class RequestManager
24
 *
25
 * @package Elastification\Client\Request
26
 * @author  Daniel Wendlandt
27
 */
28
class RequestManager implements RequestManagerInterface
29
{
30
31
    /**
32
     * @var array
33
     */
34
    private $requests = array();
35
36
    /**
37
     * @inheritdoc
38
     */
39 2
    public function getRequest($name)
40
    {
41 2
        if ($this->requestExists($name)) {
42 1
            return $this->requests[$name];
43
        }
44
45 1
        return null;
46
    }
47
48
    /**
49
     * @inheritdoc
50
     */
51 5
    public function hasRequest($name)
52
    {
53 5
        return $this->requestExists($name);
54
    }
55
56
    /**
57
     * @inheritdoc
58
     */
59 2
    public function removeRequest($name)
60
    {
61 2
        if ($this->requestExists($name)) {
62 1
            unset($this->requests[$name]);
63
64 1
            return true;
65
        }
66
67 1
        return false;
68
    }
69
70
    /**
71
     * @inheritdoc
72
     */
73 1
    public function reset()
74
    {
75 1
        $this->requests = array();
76 1
    }
77
78
    /**
79
     * @inheritdoc
80
     */
81 6
    public function setRequest($name, RequestInterface $request)
82
    {
83 6
        if ($this->requestExists($name)) {
84 1
            throw new RequestManagerException('a request for "' . $name . '" is already registered');
85
        }
86
87 6
        $this->requests[$name] = $request;
88 6
    }
89
90
    /**
91
     * checks if a request is registered for given name
92
     *
93
     * @param string $name
94
     *
95
     * @return bool
96
     * @author Daniel Wendlandt
97
     */
98 9
    private function requestExists($name)
99
    {
100 9
        return isset($this->requests[$name]);
101
    }
102
}
103