Completed
Push — feature/controller ( 08e254...534c3a )
by René
09:48
created

Request::getPath()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2.032

Importance

Changes 3
Bugs 0 Features 0
Metric Value
c 3
b 0
f 0
dl 0
loc 10
ccs 4
cts 5
cp 0.8
rs 9.4285
cc 2
eloc 5
nc 2
nop 0
crap 2.032
1
<?php
2
3
namespace Zortje\MVC\Network;
4
5
/**
6
 * Class Request
7
 *
8
 * @package Zortje\MVC\Network
9
 */
10
class Request
11
{
12
13
    /**
14
     * @var string Full URL
15
     */
16
    protected $url;
17
18
    /**
19
     * @var array POST data
20
     */
21
    protected $post;
22
23
    /**
24
     * Get request URL path
25
     *
26
     * @return string URL path
27
     */
28 2
    public function getPath()
29
    {
30 2
        $path = parse_url($this->url, PHP_URL_PATH);
31
32 2
        if ($path === false) {
33
            $path = '';
34
        }
35
36 2
        return $path;
37
    }
38
39
    /**
40
     * @param string $url  URL of the request, trailing slash are removed automatically
41
     * @param array  $post URL post fields
42
     */
43 1
    public function __construct($url, array $post)
44
    {
45 1
        $this->url  = rtrim($url, '/');
46 1
        $this->post = $post;
47 1
    }
48
}
49