Passed
Push — master ( 9a31c8...63c7d9 )
by Jon
02:01
created

Text::getComponent()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 5
nc 1
nop 0
dl 0
loc 7
rs 9.4285
c 0
b 0
f 0
1
<?php namespace FlatPlan\Components;
2
3
class Text extends AbstractComponent {
4
5
    protected $text;
6
    protected $format;
7
    protected $textStyle;
8
9
    protected $formats = ['html', 'markdown', 'none'];
10
    protected $roles   = ['body', 'title', 'heading', 'intro', 'caption', 'author', 'byline', 'illustrator', 'photographer', 'quote', 'pullquote'];
11
12
    /**
13
     * @param string $role
14
     * @param string $text
15
     * @param string $format
16
     * @return void
17
     */
18
    public function __construct($role, $text, $format = 'none')
19
    {
20
        $this->setRole($role);
21
        $this->setText($text);
22
        $this->setFormat($format);
23
    }
24
25
    private function setText($text)
26
    {
27
        $this->text = $text;
28
    }
29
30
    private function getText()
31
    {
32
        return $this->text;
33
    }
34
35
    private function setFormat($format = null)
36
    {
37
        if (!in_array($format, $this->formats)) {
38
            throw new \ErrorException('Invalid format supplied.');
39
        }
40
        $this->format = $format;
41
    }
42
43
    private function getFormat()
44
    {
45
        return $this->format;
46
    }
47
48
    protected function getComponent()
49
    {
50
        $component = new \stdClass();
51
        $component->text   = $this->getText();
52
        $component->role   = $this->getRole();
53
        $component->format = $this->getFormat();
54
        return $component;
55
    }
56
}
57