Completed
Push — master ( e43f1a...57db71 )
by Arman
26s queued 12s
created

Params::postParams()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 4
c 1
b 0
f 0
dl 0
loc 9
rs 10
cc 2
nc 2
nop 0
1
<?php
2
3
/**
4
 * Quantum PHP Framework
5
 *
6
 * An open source software development framework for PHP
7
 *
8
 * @package Quantum
9
 * @author Arman Ag. <[email protected]>
10
 * @copyright Copyright (c) 2018 Softberg LLC (https://softberg.org)
11
 * @link http://quantum.softberg.org/
12
 * @since 2.4.0
13
 */
14
15
namespace Quantum\Http\Request;
16
17
/**
18
 * Trait Params
19
 * @package Quantum\Http\Request
20
 */
21
trait Params
22
{
23
24
    /**
25
     * Gets the GET params
26
     * @return array|null
27
     */
28
    private static function getParams(): ?array
29
    {
30
        $getParams = [];
31
32
        if (!empty($_GET)) {
33
            $getParams = filter_input_array(INPUT_GET, FILTER_DEFAULT);
34
        }
35
36
        return $getParams;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $getParams could return the type null which is incompatible with the type-hinted return array|null. Consider adding an additional type-check to rule them out.
Loading history...
37
    }
38
39
    /**
40
     * Gets the POST params
41
     * @return array|null
42
     */
43
    private static function postParams(): ?array
44
    {
45
        $postParams = [];
46
47
        if (!empty($_POST)) {
48
            $postParams = filter_input_array(INPUT_POST, FILTER_DEFAULT);
49
        }
50
51
        return $postParams;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $postParams could return the type null which is incompatible with the type-hinted return array|null. Consider adding an additional type-check to rule them out.
Loading history...
52
    }
53
54
    /**
55
     * Get Input parameters sent via PUT, PATCH or DELETE methods
56
     * @return array
57
     */
58
    private static function getRawInputs(): array
59
    {
60
        $inputParams = [];
61
62
        if (in_array(self::$__method, ['PUT', 'PATCH', 'DELETE'])) {
63
64
            $input = file_get_contents('php://input');
65
66
            if (self::$server->contentType()) {
67
                switch (self::$server->contentType()) {
68
                    case 'application/x-www-form-urlencoded':
69
                        parse_str($input, $inputParams);
70
                        break;
71
                    case 'application/json':
72
                        $inputParams = json_decode($input);
73
                        break;
74
                    default :
75
                        $inputParams = parse_raw_http_request($input);
76
                        break;
77
                }
78
            }
79
        }
80
81
        return (array)$inputParams;
82
    }
83
84
}