Completed
Push — master ( 0ddd8c...f7a79f )
by Felix
01:47
created

Url::getPart()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
cc 2
eloc 2
nc 2
nop 1
crap 2
1
<?php
2
3
namespace Felix\Scraper;
4
5
class Url
6
{
7
    protected $parts;
8
9
    public function __construct($url)
10
    {
11
        $this->parts = parse_url($url);
12
    }
13
14
    /**
15
     * Obtener una parte de la URL.
16
     * 
17
     * @param $part string Parte de la URL (Ej: host).
18
     * 
19
     * @return string|null
20
     */
21 4
    public function getPart($part)
22
    {
23 4
        return array_key_exists($part, $this->parts) ? $this->parts[$part] : null;
24
    }
25
26
    /**
27
     * Url tiene un esquema.
28
     * 
29
     * @return boolean true|false
30
     */
31 1
    public function hasScheme()
32
    {
33 1
        return $this->getPart('scheme') !== null;
34
    }
35
36
    /**
37
     * Url tiene un dominio.
38
     * 
39
     * @return boolean true|false
40
     */
41 1
    public function hasHost()
42
    {
43 1
        return $this->getPart('host') !== null;
44
    }
45
}