Completed
Push — feature/controller ( 534c3a...e4e086 )
by René
02:20
created

Request::getPath()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 3
Bugs 0 Features 0
Metric Value
c 3
b 0
f 0
dl 0
loc 10
ccs 5
cts 5
cp 1
rs 9.4285
cc 2
eloc 5
nc 2
nop 0
crap 2
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