RequestUtility::getPost()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 8
ccs 4
cts 4
cp 1
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 0
crap 2
1
<?php
2
3
namespace Botonomous\utility;
4
5
/**
6
 * Class RequestUtility.
7
 */
8
class RequestUtility
9
{
10
    private $content;
11
    private $post;
12
    private $get;
13
14
    /**
15
     * @return string
16
     */
17 18
    public function getContent(): string
18
    {
19 18
        if (isset($this->content)) {
20 11
            return $this->content;
21
        }
22
23 8
        return file_get_contents('php://input');
24
    }
25
26
    /**
27
     * @param $content
28
     */
29 12
    public function setContent(string $content)
30
    {
31 12
        $this->content = $content;
32 12
    }
33
34
    /**
35
     * @return mixed
36
     */
37 10
    public function getPost()
38
    {
39 10
        if (isset($this->post)) {
40 5
            return $this->post;
41
        }
42
43 5
        return filter_input_array(INPUT_POST);
44
    }
45
46
    /**
47
     * @return mixed
48
     */
49 18
    public function getPostedBody()
50
    {
51 18
        $body = $this->getContent();
52
53 18
        if (empty($body)) {
54
            /* @noinspection PhpInconsistentReturnPointsInspection */
55 8
            return;
56
        }
57
58 11
        return json_decode($body, true);
59
    }
60
61
    /**
62
     * @param array $post
63
     */
64 5
    public function setPost(array $post)
65
    {
66 5
        $this->post = $post;
67 5
    }
68
69
    /**
70
     * @return mixed
71
     */
72 11
    public function getGet()
73
    {
74 11
        if (isset($this->get)) {
75 5
            return $this->get;
76
        }
77
78 6
        return filter_input_array(INPUT_GET);
79
    }
80
81
    /**
82
     * @param array $get
83
     */
84 5
    public function setGet(array $get)
85
    {
86 5
        $this->get = $get;
87 5
    }
88
89
    /**
90
     * @return mixed
91
     */
92 11
    public function getServerProtocol()
93
    {
94 11
        return filter_input(INPUT_SERVER, 'SERVER_PROTOCOL', FILTER_SANITIZE_STRING);
95
    }
96
}
97