Completed
Pull Request — master (#16)
by Rémi
04:19
created

AdUrlParser   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 60
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
c 0
b 0
f 0
lcom 0
cbo 3
dl 0
loc 60
ccs 16
cts 16
cp 1
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 15 1
A getCategory() 0 4 1
A getId() 0 4 1
A __toString() 0 4 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