Completed
Push — stable ( b83837...3c8749 )
by
unknown
08:20 queued 05:46
created

Preformatted::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 1
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace dokuwiki\Parsing\Handler;
4
5
class Preformatted extends AbstractRewriter
6
{
7
8
    protected $pos;
9
    protected $text ='';
10
11
    /** @inheritdoc */
12
    public function finalise()
13
    {
14
        $last_call = end($this->calls);
15
        $this->writeCall(array('preformatted_end',array(), $last_call[2]));
16
17
        $this->process();
18
        $this->callWriter->finalise();
19
        unset($this->callWriter);
20
    }
21
22
    /** @inheritdoc */
23
    public function process()
24
    {
25
        foreach ($this->calls as $call) {
26
            switch ($call[0]) {
27
                case 'preformatted_start':
28
                    $this->pos = $call[2];
29
                    break;
30
                case 'preformatted_newline':
31
                    $this->text .= "\n";
32
                    break;
33
                case 'preformatted_content':
34
                    $this->text .= $call[1][0];
35
                    break;
36
                case 'preformatted_end':
37
                    if (trim($this->text)) {
38
                        $this->callWriter->writeCall(array('preformatted', array($this->text), $this->pos));
39
                    }
40
                    // see FS#1699 & FS#1652, add 'eol' instructions to ensure proper triggering of following p_open
41
                    $this->callWriter->writeCall(array('eol', array(), $this->pos));
42
                    $this->callWriter->writeCall(array('eol', array(), $this->pos));
43
                    break;
44
            }
45
        }
46
47
        return $this->callWriter;
48
    }
49
}
50