FootnotesHandler::draw()   B
last analyzed

Complexity

Conditions 5
Paths 3

Size

Total Lines 13
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 5

Importance

Changes 0
Metric Value
dl 0
loc 13
ccs 9
cts 9
cp 1
rs 8.8571
c 0
b 0
f 0
cc 5
eloc 8
nc 3
nop 1
crap 5
1
<?php
2
3
namespace Kaloa\Renderer\Inigo\Handler;
4
5
use Kaloa\Renderer\Inigo\Handler\ProtoHandler;
6
use Kaloa\Renderer\Inigo\Parser;
7
8
/**
9
 *
10
 */
11
final class FootnotesHandler extends ProtoHandler
12
{
13
    /**
14
     *
15
     * @var int
16
     */
17
    private $cnt;
18
19
    /**
20
     *
21
     * @var array
22
     */
23
    private $footnotes;
24
25
    /**
26
     *
27
     */
28 18
    public function __construct()
29
    {
30 18
        $this->name = 'fn|fnt';
31
32 18
        $this->type[0] = (Parser::TAG_INLINE | Parser::TAG_SINGLE);
33 18
        $this->type[1] = (Parser::TAG_OUTLINE | Parser::TAG_CLEAR_CONTENT);
34 18
    }
35
36
    /**
37
     *
38
     * @param  array  $data
39
     * @return string
40
     */
41 1
    public function draw(array $data)
42
    {
43 1
        $ret = '';
44
45 1
        if ($data['tag'] === 'fn' && $data['front']) {
46 1
            $this->cnt++;
47 1
            $ret = '[' . $this->cnt . ']';
48 1
        } elseif ($data['tag'] === 'fnt' && !$data['front']) {
49 1
            $this->footnotes[] = $data['content'];
50 1
        }
51
52 1
        return $ret;
53
    }
54
55
    /**
56
     *
57
     */
58 17
    public function initialize()
59
    {
60 17
        $this->cnt = 0;
61 17
        $this->footnotes = array();
62 17
    }
63
64
    /**
65
     *
66
     * @param  string $s
67
     * @param  array  $data
68
     * @return string
69
     */
70 16
    public function postProcess($s, array $data)
71
    {
72 16
        $ret = '';
73
74 16
        if (($data['tag'] === 'fnt') && ($this->cnt > 0)) {
75 1
            $ret .= '<ol>' . "\n";
76 1
            foreach ($this->footnotes as $f) {
77 1
                $ret .= '<li>' . $f . '</li>' . "\n";
78 1
            }
79 1
            $ret .= '</ol>';
80 1
        }
81
82 16
        return $s . $ret;
83
    }
84
}
85