Passed
Push — master ( 04cf7a...5cb2ae )
by Jon
03:42
created

Ad   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Importance

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

4 Methods

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