Completed
Push — feature/controller ( 4da62c...5a6415 )
by René
04:10
created

Request   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 81.82%

Importance

Changes 5
Bugs 0 Features 0
Metric Value
wmc 4
c 5
b 0
f 0
lcom 1
cbo 0
dl 0
loc 49
ccs 9
cts 11
cp 0.8182
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A getPath() 0 10 2
A getPost() 0 4 1
1
<?php
2
declare(strict_types = 1);
3
4
namespace Zortje\MVC\Network;
5
6
/**
7
 * Class Request
8
 *
9
 * @package Zortje\MVC\Network
10
 */
11
class Request
12
{
13
14
    /**
15
     * @var string Full URL
16
     */
17
    protected $url;
18
19
    /**
20
     * @var array POST data
21
     */
22
    protected $post;
23
24
    /**
25
     * @param string $url  URL of the request, trailing slash are removed automatically
26
     * @param array  $post URL post fields
27
     */
28 1
    public function __construct(string $url, array $post)
29
    {
30 1
        $this->url  = rtrim($url, '/');
31 1
        $this->post = $post;
32 1
    }
33
34
    /**
35
     * Get request URL path
36
     *
37
     * @return string URL path
38
     */
39 2
    public function getPath(): string
40
    {
41 2
        $path = parse_url($this->url, PHP_URL_PATH);
42
43 2
        if (is_string($path) === false) {
44 1
            $path = '';
45
        }
46
47 2
        return $path;
48
    }
49
50
    /**
51
     * Get request POST data
52
     *
53
     * @return array POST data
54
     */
55
    public function getPost(): array
56
    {
57
        return $this->post;
58
    }
59
}
60