Passed
Branch main (7d5b4b)
by Sammy
16:06 queued 06:48
created

Request::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 4
rs 10
1
<?php
2
3
/**
4
* huppel konijntje huppel and wiebel
5
* Hommage to Grace Hopper, programmer & expert in *litteral* duck taping
6
***/
7
8
namespace HexMakina\Hopper;
9
10
class Request
11
{
12
    private $alto_match;
13
    private Response $target;
14
15
    public function __construct(array $match)
16
    {
17
        $this->alto_match = $match;
18
        $this->target = new Response($this);
19
    }
20
21
    // DEPRECATED
22
    public function target()
23
    {
24
        return $this->alto_match['target'];
25
    }
26
27
    public function name()
28
    {
29
        return $this->alto_match['name'];
30
    }
31
32
    // @return array of all GET params if $name is null
33
    // @return null if $name is not an index
34
    // @return return urldecoded string
35
    public function params($name = null)
36
    {
37
        $params = $this->alto_match['params'] ?? [];
38
39
        if(is_null($name)){
40
            return $params;
41
        }
42
43
        if (!isset($params[$name])) {
44
            return null;
45
        }
46
47
        if (is_string($params[$name])) {
48
            return urldecode($params[$name]);
49
        }
50
        return $params[$name];
51
    }
52
53
    public function submitted($name = null)
54
    {
55
        if(is_null($name)){
56
            return $_POST;
57
        }
58
        
59
        return $_POST[$name] ?? null;
60
    }
61
}
62