FootnotesHandler   A
last analyzed

Coupling/Cohesion

Components 1
Dependencies 1

Complexity

Total Complexity 11

Size/Duplication

Total Lines 74
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 11
lcom 1
cbo 1
dl 0
loc 74
ccs 28
cts 28
cp 1
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
B draw() 0 13 5
A initialize() 0 5 1
A postProcess() 0 14 4
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