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

Request   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 85
Duplicated Lines 0 %

Importance

Changes 4
Bugs 2 Features 0
Metric Value
eloc 16
c 4
b 2
f 0
dl 0
loc 85
rs 10
wmc 6

5 Methods

Rating   Name   Duplication   Size   Complexity  
A get() 0 3 1
A __construct() 0 3 1
A setData() 0 12 2
A input() 0 3 1
A post() 0 3 1
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
        {
45
            $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

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