HTMLGenerator::setTemplate()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 6
ccs 3
cts 3
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 1
crap 1
1
<?php
2
3
namespace CSSPrites\Generator;
4
5
class HTMLGenerator extends AbstractGenerator
6
{
7
    protected $cssGenerator;
8
9
    protected $tag      = '';
10
    protected $template = '';
11
12
    protected $cssgenerator;
13
14 30
    public function setTag($value)
15
    {
16 30
        $this->tag = $value;
17
18 30
        return $this;
19
    }
20
21 21
    public function setTemplate($value)
22
    {
23 21
        $this->template = $value;
24
25 21
        return $this;
26
    }
27
28 21
    public function setCSSGenerator(CSSGenerator $cssGenerator)
29
    {
30 21
        $this->cssgenerator = $cssGenerator;
31
32 21
        return $this;
33
    }
34
35 18
    public function addLine($filename)
36
    {
37 18
        $this->content .= "\t".'<'.$this->tag.' class="{{selector}} {{prefix}}-'.$this->slugifier->slugify($filename).'"></'.$this->tag.'>'."\n";
38
39 18
        return $this;
40
    }
41
42 21
    public function process()
43
    {
44 21
        if (!($this->cssgenerator instanceof CSSGenerator)) {
45 3
            throw new \Exception('CSSGenerator not set');
46
        }
47
48 18
        $this->content = str_replace(
49 18
            ['{{selector}}', '{{prefix}}'],
50 18
            [$this->cssgenerator->getSelector(), $this->cssgenerator->getPrefix()],
51 18
            $this->content
52 18
        );
53 18
        $this->content = str_replace(
54 18
            ['{{stylesheet}}', '{{content}}'],
55 18
            [pathinfo($this->cssgenerator->getFilePath(), PATHINFO_BASENAME), rtrim($this->content)],
56 18
            $this->template
57 18
        );
58
59 18
        return $this->content;
60
    }
61
62 6
    public function save()
63
    {
64 6
        if (!($this->cssgenerator instanceof CSSGenerator)) {
65 3
            throw new \Exception('CSSGenerator not set');
66
        }
67
68 3
        return parent::save();
69
    }
70
}
71