Request   A
last analyzed

Complexity

Total Complexity 11

Size/Duplication

Total Lines 57
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 2
Metric Value
eloc 21
c 2
b 0
f 2
dl 0
loc 57
rs 10
wmc 11

6 Methods

Rating   Name   Duplication   Size   Complexity  
A target() 0 3 1
A __construct() 0 5 1
A submitted() 0 7 2
A name() 0 3 1
A params() 0 15 4
A payload() 0 4 2
1
<?php
2
3
namespace HexMakina\Hopper;
4
5
class Request
6
{
7
    private $alto_match;
8
    private $query_parameters;
9
    private $params;
10
11
    public function __construct(array $match)
12
    {
13
        $this->alto_match = $match;
14
        $this->query_parameters = $_GET;
15
        $this->params = array_merge($this->alto_match['params'], $this->query_parameters);
16
    }
17
18
    // DEPRECATED
19
    public function target()
20
    {
21
        return $this->alto_match['target'];
22
    }
23
24
    public function name()
25
    {
26
        return $this->alto_match['name'];
27
    }
28
29
    // @return array of all GET params if $name is null
30
    // @return null if $name is not an index
31
    // @return return urldecoded string
32
    public function params($name = null)
33
    {
34
        if(is_null($name)){
35
            return $this->params;
36
        }
37
38
        if (!isset($this->params[$name])) {
39
            return null;
40
        }
41
42
        if (is_string($this->params[$name])) {
43
            return urldecode($this->params[$name]);
44
        }
45
46
        return $this->params[$name];
47
    }
48
49
    public function submitted($name = null)
50
    {
51
        if(is_null($name)){
52
            return $_POST;
53
        }
54
        
55
        return $_POST[$name] ?? null;
56
    }
57
58
    public function payload(): ?string
59
    {
60
        $res = file_get_contents('php://input');
61
        return $res === false ? null : $res;
62
    }
63
    
64
}
65