Url::getHost()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
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
}