Url   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 6
c 2
b 0
f 0
lcom 1
cbo 0
dl 0
loc 48
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 11 3
A getWebUrl() 0 4 1
A getHost() 0 4 1
A getSchema() 0 4 1
1
<?php
2
/**
3
 * This file is part of sitemap-common.
4
 *
5
 * (c) 2016 Daniele Moraschi
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
11
namespace SiteMap\Http;
12
13
14
class Url
15
{
16
    /**
17
     * @var string
18
     */
19
    private $url;
20
21
    /**
22
     * Url constructor.
23
     * @param $url
24
     */
25
    public function __construct($url)
26
    {
27
        $parts = parse_url($url);
28
29
        if ($parts === false || !$parts) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $parts of type array<string,string> is implicitly converted to a boolean; are you sure this is intended? If so, consider using empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
30
            throw new \InvalidArgumentException(sprintf('Unable to parse URL: "%s"'), $url);
31
        }
32
33
34
        $this->url = $url;
35
    }
36
37
    /**
38
     * @return string
39
     */
40
    public function getWebUrl()
41
    {
42
        return $this->url;
43
    }
44
45
    /**
46
     * @return mixed
47
     */
48
    public function getHost()
49
    {
50
        return parse_url($this->getWebUrl(), PHP_URL_HOST);
51
    }
52
53
    /**
54
     * @return mixed
55
     */
56
    public function getSchema()
57
    {
58
        return parse_url($this->getWebUrl(), PHP_URL_SCHEME);
59
    }
60
61
}