Uri   A
last analyzed

Complexity

Total Complexity 11

Size/Duplication

Total Lines 60
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 11
lcom 1
cbo 1
dl 0
loc 60
rs 10
c 0
b 0
f 0
ccs 25
cts 25
cp 1

8 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A toAbsoluteUrl() 0 12 3
A isAbsolute() 0 4 1
A isImage() 0 4 1
A isRoot() 0 4 1
A getRootDomain() 0 6 1
A getLastDir() 0 10 2
A __toString() 0 4 1
1
<?php
2
3
namespace Fetcher;
4
5
class Uri
6
{
7
    private $uri;
8
9 26
    public function __construct($uri)
10
    {
11 26
        $this->uri = $uri;
12 26
    }
13
14 5
    public function toAbsoluteUrl(Url $url)
15
    {
16 5
        if ($this->isAbsolute()) {
17 1
            return $this;
18
        }
19
20 4
        if ($this->isRoot()) {
21 2
            return new Url($url->getRootDomain() . mb_substr((string) $this->uri, 1));
22
        }
23
24 2
        return new Url($url->getLastDir() . $this->uri);
25
    }
26
27 8
    public function isAbsolute()
28
    {
29 8
        return preg_match('/^http(s)?:\/\//', $this->uri);
30
    }
31
32 6
    public function isImage()
33
    {
34 6
        return preg_match('/\.(jpg|jpeg|png|gif)$/i', $this->uri);
35
    }
36
37 4
    public function isRoot()
38
    {
39 4
        return 0 === mb_strpos($this->uri, '/');
40
    }
41
42 8
    public function getRootDomain()
43
    {
44 8
        preg_match('/^http(?:s)?:\/\/([^\/]*)/', $this->uri, $matches);
45
46 8
        return $matches[0] . '/';
47
    }
48
49 7
    public function getLastDir()
50
    {
51 7
        preg_match('/^(http(?:s)?:\/\/.*\/)([^\/]*)$/', $this->uri, $matches);
52
53 7
        if (empty($matches)) {
54 1
            return $this->uri . '/';
55
        }
56
57 6
        return $matches[1];
58
    }
59
60 5
    public function __toString()
61
    {
62 5
        return $this->uri;
63
    }
64
}
65