Completed
Push — master ( 260e13...281c81 )
by Sebastian
03:58
created

GetRequest::hasParameter()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
namespace Kartenmacherei\RestFramework\Request;
3
4
use Kartenmacherei\RestFramework\Request\Header\HeaderCollection;
5
use Kartenmacherei\RestFramework\Request\Method\GetRequestMethod;
6
use Kartenmacherei\RestFramework\Request\Method\RequestMethod;
7
8
class GetRequest extends Request
9
{
10
    /**
11
     * @var array
12
     */
13
    private $parameters;
14
15
    /**
16
     * @param Uri $uri
17
     * @param HeaderCollection $headers
18
     * @param array $parameters
19
     */
20
    public function __construct(Uri $uri, HeaderCollection $headers, array $parameters)
21
    {
22
        parent::__construct($uri, $headers);
23
        $this->parameters = $parameters;
24
    }
25
26
    /**
27
     * @param $name
28
     * @return bool
29
     */
30
    public function hasParameter($name): bool
31
    {
32
        return array_key_exists($name, $this->parameters);
33
    }
34
35
    /**
36
     * @param $name
37
     * @return mixed
38
     * @throws RequestParameterException
39
     */
40
    public function getParameter($name)
41
    {
42
        if (!$this->hasParameter($name)) {
43
            throw new RequestParameterException(sprintf('Parameter %s not found'));
44
        }
45
        return $this->parameters[$name];
46
    }
47
48
    /**
49
     * @return RequestMethod
50
     */
51
    public function getMethod(): RequestMethod
52
    {
53
        return new GetRequestMethod();
54
    }
55
56
57
}
58