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

Request   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 18
c 1
b 0
f 0
dl 0
loc 50
rs 10
wmc 9

5 Methods

Rating   Name   Duplication   Size   Complexity  
A target() 0 3 1
A __construct() 0 4 1
A submitted() 0 7 2
A name() 0 3 1
A params() 0 16 4
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