Url::serialize()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 4
nc 1
nop 0
dl 0
loc 6
ccs 5
cts 5
cp 1
crap 1
rs 10
c 1
b 0
f 0
1
<?php
2
3
namespace LAG\SmokerBundle\Url;
4
5
use LAG\SmokerBundle\Exception\Exception;
6
7
class Url
8
{
9
    /**
10
     * @var string
11
     */
12
    protected $location;
13
14
    /**
15
     * @var string
16
     */
17
    protected $providerName;
18
19
    /**
20
     * @var array
21
     */
22
    protected $options;
23
24
    /**
25
     * Url constructor.
26
     */
27 5
    public function __construct(string $location, string $providerName, array $options = [])
28
    {
29 5
        $this->location = $location;
30 5
        $this->providerName = $providerName;
31 5
        $this->options = $options;
32 5
    }
33
34 1
    public function serialize(): string
35
    {
36 1
        return serialize([
37 1
            'location' => $this->location,
38 1
            'providerName' => $this->providerName,
39 1
            'options' => $this->options,
40
        ]);
41
    }
42
43 1
    public static function deserialize(string $serialized): Url
44
    {
45 1
        $data = unserialize($serialized);
46
47 1
        return new Url(
48 1
            $data['location'],
49 1
            $data['providerName'],
50 1
            $data['options']
51
        );
52
    }
53
54 2
    public function getLocation(): string
55
    {
56 2
        return $this->location;
57
    }
58
59 2
    public function getProviderName(): string
60
    {
61 2
        return $this->providerName;
62
    }
63
64
    public function getOptions(): array
65
    {
66
        return $this->options;
67
    }
68
69 1
    public function hasOption(string $name): bool
70
    {
71 1
        return key_exists($name, $this->options);
72
    }
73
74 1
    public function getOption(string $name)
75
    {
76 1
        if (!$this->hasOption($name)) {
77
            throw new Exception('Unknown options "'.$name.'"');
78
        }
79
80 1
        return $this->options[$name];
81
    }
82
}
83