Ad::getComponent()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 8
c 1
b 0
f 0
nc 2
nop 0
dl 0
loc 11
rs 10
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
    public function getComponent()
37
    {
38
        $component = new \stdClass();
39
        $component->role       = $this->getRole();
40
        $component->bannerType = $this->getBannerType();
41
        $component->layout     = $this->getLayout();
42
        $component->style      = $this->getStyle();
43
        if (!is_null($this->behaviour)) {
44
            $component->behaviour = $this->getBehaviour();
45
        }
46
        return $component;
47
    }
48
}
49