Passed
Push — master ( 62f043...679ba5 )
by devosc
03:11
created

Request::__construct()   B

Complexity

Conditions 5
Paths 12

Size

Total Lines 12
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 6.6

Importance

Changes 0
Metric Value
dl 0
loc 12
ccs 3
cts 5
cp 0.6
c 0
b 0
f 0
rs 8.8571
cc 5
eloc 7
nc 12
nop 1
crap 6.6
1
<?php
2
/**
3
 *
4
 */
5
6
namespace Mvc5\Http\Config;
7
8
use Mvc5\Arg;
9
use Mvc5\Http;
10
11
trait Request
12
{
13
    /**
14
     * @var array
15
     */
16 1
    protected $config = [];
17
18 1
    /**
19
     * @param array $config
20
     */
21
    function __construct($config = [])
22
    {
23
        !isset($config[Arg::HEADERS]) &&
24 3
            $config[Arg::HEADERS] = new Http\HttpHeaders;
25
26 3
        is_array($config[Arg::HEADERS]) &&
27
            $config[Arg::HEADERS] = new Http\HttpHeaders($config[Arg::HEADERS]);
28
29
        isset($config[Arg::URI]) && !($config[Arg::URI] instanceof Http\Uri) &&
30
            $config[Arg::URI] = new Http\HttpUri($config[Arg::URI]);
31
32 9
        $this->config = $config;
33
    }
34 9
35
    /**
36
     * @return mixed
37
     */
38
    function body()
1 ignored issue
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
39
    {
40 1
        return $this[Arg::BODY];
41
    }
42 1
43
    /**
44
     * @return Http\Headers
45
     */
46
    function headers() : Http\Headers
1 ignored issue
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
47
    {
48 4
        return $this[Arg::HEADERS];
49
    }
50 4
51
    /**
52
     * @return string|null
53
     */
54
    function method() : ?string
1 ignored issue
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
55
    {
56
        return $this[Arg::METHOD];
57
    }
58
59
    /**
60
     * @return Http\Uri|null
61
     */
62
    function uri() : ?Http\Uri
1 ignored issue
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
63
    {
64
        return $this[Arg::URI];
65
    }
66
67
    /**
68
     * @return string|null
69
     */
70
    function version() : ?string
1 ignored issue
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
71
    {
72
        return $this[Arg::VERSION];
73
    }
74
}
75