Completed
Push — master ( 3fcbeb...90dea4 )
by Alex
04:27 queued 02:03
created

getHttpRequestHeaders()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 2
c 1
b 0
f 0
dl 0
loc 5
rs 10
cc 2
nc 2
nop 0
1
<?php
2
namespace Mezon\Service;
3
4
/**
5
 * Class ServiceSimpleRequestParams
6
 *
7
 * @package Service
8
 * @subpackage ServiceSimpleRequestParams
9
 * @author Dodonov A.A.
10
 * @version v.1.0 (2019/10/31)
11
 * @copyright Copyright (c) 2019, aeon.org
12
 */
13
14
/**
15
 * Request params fetcher
16
 */
17
class ServiceSimpleRequestParams implements \Mezon\Service\ServiceRequestParamsInterface
18
{
19
20
    /**
21
     * Method returns list of the request's headers
22
     *
23
     * @return array[string] Array of headers
0 ignored issues
show
Documentation Bug introduced by
The doc comment array[string] at position 1 could not be parsed: Expected ']' at position 1, but found '['.
Loading history...
24
     */
25
    protected function getHttpRequestHeaders(): array
26
    {
27
        $headers = getallheaders();
28
29
        return $headers === false ? [] : $headers;
30
    }
31
32
    /**
33
     * Method returns request parameter
34
     *
35
     * @param string $param
36
     *            parameter name
37
     * @param mixed $default
38
     *            default value
39
     * @return mixed Parameter value
40
     */
41
    public function getParam($param, $default = false)
42
    {
43
        $headers = $this->getHttpRequestHeaders();
44
45
        $return = $default;
46
47
        if (isset($headers[$param])) {
48
            $return = $headers[$param];
49
        } elseif (isset($_POST[$param])) {
50
            $return = $_POST[$param];
51
        } elseif (isset($_GET[$param])) {
52
            $return = $_GET[$param];
53
        }
54
55
        return $return;
56
    }
57
}
58