Passed
Push — master ( 3bf788...763f00 )
by Jon
02:39 queued 10s
created

Ad   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 58
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 58
rs 10
c 0
b 0
f 0
wmc 10

7 Methods

Rating   Name   Duplication   Size   Complexity  
A getComponent() 0 6 1
A setRole() 0 6 2
A getRole() 0 3 1
A __construct() 0 5 2
A __toString() 0 3 1
A getBannerType() 0 3 1
A setBannerType() 0 6 2
1
<?php namespace FlatPlan\Components;
2
3
class Ad extends AbstractComponent {
4
5
    private $role;
6
    private $bannerType;
7
8
    protected $roles       = ['banner_advertisement', 'medium_rectangle_advertisement'];
9
    protected $bannerTypes = ['any', 'standard', 'double_height', 'large'];
10
11
    /**
12
     * @param string $role
13
     * @param string $bannerType
14
     * @return void
15
     */
16
    public function __construct($role, $bannerType = null)
17
    {
18
        $this->setRole($role);
19
        if ($role === 'banner_advertisement') {
20
            $this->setBannerType($bannerType);
21
        }
22
    }
23
24
    public function setRole($role)
25
    {
26
        if (!in_array($role, $this->roles)) {
27
            throw new \ErrorException('Invalid role supplied.');
28
        }
29
        $this->role = $role;
30
    }
31
32
    public function getRole()
33
    {
34
        return $this->role;
35
    }
36
37
    public function setBannerType($bannerType = null)
38
    {
39
        if (!in_array($bannerType, $this->bannerTypes)) {
40
            throw new \ErrorException('Invalid banner type supplied.');
41
        }
42
        $this->bannerTypes = $bannerType;
43
    }
44
45
    public function getBannerType()
46
    {
47
        return $this->bannerType;
48
    }
49
50
    public function getComponent()
51
    {
52
        $component = new \stdClass();
53
        $component->role       = $this->getRole();
54
        $component->bannerType = $this->getBannerType();
55
        return $component;
56
    }
57
58
    public function __toString()
59
    {
60
        return json_encode($this->getComponent());
61
    }
62
}
63