Completed
Push — master ( d751a6...b3a1d7 )
by Sebastian
03:55
created

FormDataBody::has()   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\Body;
3
4
class FormDataBody extends Body
5
{
6
    /**
7
     * @var array
8
     */
9
    private $data = [];
10
11
    /**
12
     * @param array $data
13
     */
14
    public function __construct(array $data)
15
    {
16
        $this->data = $data;
17
    }
18
19
    /**
20
     * @param string $name
21
     * @return bool
22
     */
23
    public function has(string $name): bool
24
    {
25
        return array_key_exists($name, $this->data);
26
    }
27
28
    /**
29
     * @param string $name
30
     * @return mixed
31
     * @throws BodyException
32
     */
33
    public function get(string $name)
34
    {
35
        if (!$this->has($name)) {
36
            throw new BodyException(sprintf('Form field %s not found', $name));
37
        }
38
        return $this->data[$name];
39
    }
40
41
    /**
42
     * @return bool
43
     */
44
    public function isJson(): bool
45
    {
46
        return false;
47
    }
48
49
}
50