Social::setUrl()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 3
c 1
b 0
f 0
nc 2
nop 1
dl 0
loc 6
rs 10
1
<?php namespace FlatPlan\Components;
2
3
class Social extends AbstractComponent {
4
5
    protected $url;
6
7
    protected $roles = ['instagram', 'facebook_post', 'tiktok', 'tweet'];
8
9
    /**
10
     * @param string $role
11
     * @param string $url
12
     * @return void
13
     */
14
    public function __construct($role, $url)
15
    {
16
        $this->setRole($role);
17
        $this->setUrl($url);
18
    }
19
20
    private function setUrl($url)
21
    {
22
        if (!filter_var($url, FILTER_VALIDATE_URL)) {
23
            throw new \ErrorException('Invalid url supplied.');
24
        }
25
        $this->url = $url;
26
    }
27
28
    private function getUrl()
29
    {
30
        return $this->url;
31
    }
32
33
    public function getComponent()
34
    {
35
        $component = new \stdClass();
36
        $component->role   = $this->getRole();
37
        $component->URL    = $this->getUrl();
38
        $component->layout    = $this->getLayout();
39
        $component->style     = $this->getStyle();
40
        if (!is_null($this->behaviour)) {
41
            $component->behaviour = $this->getBehaviour();
42
        }
43
        return $component;
44
    }
45
}
46