CodeHandler::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 11
ccs 7
cts 7
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 6
nc 1
nop 1
crap 1
1
<?php
2
3
namespace Kaloa\Renderer\Inigo\Handler;
4
5
use Kaloa\Renderer\Inigo\Handler\ProtoHandler;
6
use Kaloa\Renderer\Inigo\Parser;
7
use Kaloa\Renderer\SyntaxHighlighterInterface;
8
9
/**
10
 *
11
 */
12
final class CodeHandler extends ProtoHandler
13
{
14
    /**
15
     *
16
     * @var string
17
     */
18
    private $lang;
19
20
    /**
21
     *
22
     * @var SyntaxHighlighterInterface
23
     */
24
    private $syntaxHighlighter;
25
26
    /**
27
     *
28
     */
29 18
    public function __construct(SyntaxHighlighterInterface $syntaxHighlighter)
30
    {
31 18
        $this->name = 'code';
32
33 18
        $this->type = Parser::TAG_OUTLINE | Parser::TAG_PRE
34 18
                | Parser::TAG_CLEAR_CONTENT;
35
36 18
        $this->syntaxHighlighter = $syntaxHighlighter;
37
38 18
        $this->defaultParam = 'lang';
39 18
    }
40
41
    /**
42
     *
43
     * @param  array  $data
44
     * @return string
45
     */
46 1
    public function draw(array $data)
47
    {
48 1
        $ret = '';
49
50 1
        if ($data['front']) {
51 1
            $this->lang = $this->fillParam($data, 'lang', '');
52 1
        } else {
53 1
            $ret = $this->syntaxHighlighter->highlight($data['content'], $this->lang);
54 1
            $ret .= "\n\n";
55
        }
56
57 1
        return $ret;
58
    }
59
}
60