Passed
Pull Request — master (#80)
by
unknown
02:22
created

Request::post()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 1 Features 0
Metric Value
cc 1
eloc 1
c 2
b 1
f 0
nc 1
nop 1
dl 0
loc 3
rs 10
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
     * Request constructor.
30
     */
31
    public function __construct()
32
    {
33
        $this->setData();
34
    }
35
36
    /**
37
     * Set requestData, postData, getData.
38
     *
39
     * @return null
40
     */
41
    public function setData()
42
    {
43
        if (config('payment.octane',false)) {
0 ignored issues
show
Bug introduced by
The function config was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

43
        if (/** @scrutinizer ignore-call */ config('payment.octane',false)) {
Loading history...
44
            $this->requestData = request()->all();
0 ignored issues
show
Bug introduced by
The function request was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

44
            $this->requestData = /** @scrutinizer ignore-call */ request()->all();
Loading history...
45
            $this->postData = null;
46
            $this->getData = null;
47
        } else {
48
            $this->requestData = $_REQUEST;
49
            $this->postData = $_POST;
50
            $this->getData = $_GET;
51
        }
52
    }
53
54
    /**
55
     * Retrieve HTTP request data.
56
     *
57
     * @param string $name
58
     *
59
     * @return mixed|null
60
     */
61
    public static function input(string $name)
62
    {
63
        return (new static)->requestData[$name] ?? null;
64
    }
65
66
    /**
67
     * Retrieve HTTP POST data.
68
     *
69
     * @param string $name
70
     *
71
     * @return void
72
     */
73
    public static function post(string $name)
74
    {
75
        return (new static)->postData[$name] ?? null;
76
    }
77
78
    /**
79
     * Retrieve HTTP GET data.
80
     *
81
     * @param string $name
82
     *
83
     * @return void
84
     */
85
    public static function get(string $name)
86
    {
87
        return (new static)->getData[$name] ?? null;
88
    }
89
}
90