Request   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 94
Duplicated Lines 0 %

Importance

Changes 5
Bugs 2 Features 0
Metric Value
wmc 8
eloc 18
c 5
b 2
f 0
dl 0
loc 94
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A get() 0 7 2
A overwrite() 0 3 1
A __construct() 0 5 1
A input() 0 7 2
A post() 0 7 2
1
<?php
2
3
namespace Shetabit\Multipay;
4
5
class Request
6
{
7
    /**
8
     * HTTP request's data.
9
     *
10
     * @var array
11
     */
12
    protected $requestData = [];
13
14
    /**
15
     * HTTP POST data.
16
     *
17
     * @var array
18
     */
19
    protected $postData = [];
20
21
    /**
22
     * HTTP GET data.
23
     *
24
     * @var array
25
     */
26
    protected $getData = [];
27
28
    /**
29
     * Overwritten methods
30
     * @var array
31
     */
32
    protected static $overwrittenMethods = [];
33
34
    /**
35
     * Request constructor.
36
     */
37
    public function __construct()
38
    {
39
        $this->requestData = $_REQUEST;
40
        $this->postData = $_POST;
41
        $this->getData = $_GET;
42
    }
43
44
    /**
45
     * Retrieve HTTP request data.
46
     *
47
     * @param string $name
48
     *
49
     * @return mixed|null
50
     */
51
    public static function input(string $name)
52
    {
53
        if (isset(static::$overwrittenMethods['input'])) {
54
            return (static::$overwrittenMethods['input'])($name);
55
        }
56
57
        return (new static)->requestData[$name] ?? null;
58
    }
59
60
    /**
61
     * Retrieve HTTP POST data.
62
     *
63
     * @param string $name
64
     *
65
     * @return mixed|null
66
     */
67
    public static function post(string $name)
68
    {
69
        if (isset(static::$overwrittenMethods['post'])) {
70
            return (static::$overwrittenMethods['post'])($name);
71
        }
72
73
        return (new static)->postData[$name] ?? null;
74
    }
75
76
    /**
77
     * Retrieve HTTP GET data.
78
     *
79
     * @param string $name
80
     *
81
     * @return mixed|null
82
     */
83
    public static function get(string $name)
84
    {
85
        if (isset(static::$overwrittenMethods['get'])) {
86
            return (static::$overwrittenMethods['get'])($name);
87
        }
88
89
        return (new static)->getData[$name] ?? null;
90
    }
91
92
    /**
93
     * @param string $method
94
     * @param $callback
95
     */
96
    public static function overwrite($method, $callback)
97
    {
98
        static::$overwrittenMethods[$method] = $callback;
99
    }
100
}
101