Completed
Push — master ( 00c88c...56f5c3 )
by Rémi
13s
created

AdUrlParser::__toString()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 1
1
<?php
2
3
namespace Lbc\Parser;
4
5
use League\Uri\Modifiers\RemoveQueryKeys;
6
use League\Uri\Schemes\Http;
7
8
/**
9
 * Class AdUrlParser
10
 * @package Lbc\Parser
11
 */
12
class AdUrlParser
13
{
14
    /**
15
     * @var \League\Uri\Interfaces\Uri|\Psr\Http\Message\UriInterface
16
     */
17
    protected $url;
18
19
    /**
20
     * @var
21
     */
22
    protected $id;
23
    /**
24
     * @var
25
     */
26
    protected $category;
27
28
    /**
29
     * AdUrlParser constructor.
30
     * @param $url
31
     */
32 30
    public function __construct($url)
33
    {
34 30
        $this->url = Http::createFromString($url);
35
36 30
        $this->url = (new RemoveQueryKeys($this->url->query->keys()))->__invoke($this->url);
37
38 30
        preg_match(
39 30
            '/\/(.*)\/(.*)\.htm/',
40 30
            parse_url($this->url, PHP_URL_PATH),
41
            $matches
42 30
        );
43
44 30
        $this->category = $matches[1];
45 30
        $this->id = $matches[2];
46 30
    }
47
48
    /**
49
     * @return mixed
50
     */
51 8
    public function getCategory()
52
    {
53 8
        return $this->category;
54
    }
55
56
    /**
57
     * @return mixed
58
     */
59 18
    public function getId()
60
    {
61 18
        return $this->id;
62
    }
63
64
    /**
65
     * @return string
66
     */
67 12
    public function __toString()
68
    {
69 12
        return (string) $this->url;
70
    }
71
}
72