PageView   A
last analyzed

Complexity

Total Complexity 10

Size/Duplication

Total Lines 76
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
dl 0
loc 76
rs 10
c 0
b 0
f 0
wmc 10
lcom 1
cbo 2

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
B show() 0 41 8
A showrev() 0 4 1
1
<?php
2
3
namespace dokuwiki\Ui;
4
5
use dokuwiki\Extension\Event;
6
7
/**
8
 * DokuWiki PageView Interface
9
 *
10
 * @package dokuwiki\Ui
11
 */
12
class PageView extends Ui
13
{
14
    protected $text;
15
16
    /** 
17
     * PageView Ui constructor
18
     *
19
     * @param null|string $text  wiki text or null for showing $ID
20
     */
21
    public function __construct($text = null)
22
    {
23
        $this->text = $text;
24
    }
25
26
    /**
27
     * Show a wiki page
28
     *
29
     * @author   Andreas Gohr <[email protected]>
30
     *
31
     * @triggers HTML_SHOWREV_OUTPUT
32
     * @return void
33
     */
34
    public function show()
35
    {
36
        global $ID;
37
        global $REV;
38
        global $HIGH;
39
        global $INFO;
40
        global $DATE_AT;
41
42
        //disable section editing for old revisions or in preview
43
        if ($this->text !== null || $REV) {
44
            $secedit = false;
45
        } else {
46
            $secedit = true;
47
        }
48
49
        if ($this->text !== null) {
50
            //PreviewHeader
51
            echo '<br id="scroll__here" />';
52
53
            // print intro for preview
54
            echo p_locale_xhtml('preview');
55
            echo '<div class="preview"><div class="pad">';
56
            $html = html_secedit(p_render('xhtml', p_get_instructions($this->text), $info), $secedit);
57
            if ($INFO['prependTOC']) $html = tpl_toc(true) . $html;
58
            echo $html;
59
            echo '<div class="clearer"></div>';
60
            echo '</div></div>';
61
62
        } else {
63
            if ($REV || $DATE_AT) {
64
                // print intro for old revisions
65
                $data = array('rev' => &$REV, 'date_at' => &$DATE_AT);
66
                Event::createAndTrigger('HTML_SHOWREV_OUTPUT', $data, [$this, 'showrev']);
67
            }
68
            $html = p_wiki_xhtml($ID, $REV, true, $DATE_AT);
69
            $html = html_secedit($html, $secedit);
0 ignored issues
show
Bug introduced by
It seems like $html can also be of type boolean or null; however, html_secedit() does only seem to accept string, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
70
            if ($INFO['prependTOC']) $html = tpl_toc(true) . $html;
71
            $html = html_hilight($html, $HIGH);
72
            echo $html;
73
        }
74
    }
75
76
    /**
77
     * Show a revision warning
78
     *
79
     * @author Szymon Olewniczak <[email protected]>
80
     */
81
    public function showrev()
82
    {
83
        print p_locale_xhtml('showrev');
84
    }
85
86
87
}
88