Failed Conditions
Pull Request — master (#3198)
by
unknown
03:16
created

PageView::show()   B

Complexity

Conditions 8
Paths 12

Size

Total Lines 41

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 8
nc 12
nop 1
dl 0
loc 41
rs 8.0195
c 0
b 0
f 0
1
<?php
2
3
namespace dokuwiki\Ui;
4
5
use dokuwiki\Extension\Event;
6
7
/**
8
 * DokuWiki Conflict Insterface
9
 *
10
 * @package dokuwiki\Ui
11
 */
12
class PageView extends Ui
13
{
14
    /**
15
     * Show a wiki page
16
     *
17
     * @author   Andreas Gohr <[email protected]>
18
     *
19
     * @triggers HTML_SHOWREV_OUTPUT
20
     * @param null|string $txt wiki text or null for showing $ID
21
     * @return void
22
     */
23
    public function show($txt = null)
24
    {
25
        global $ID;
26
        global $REV;
27
        global $HIGH;
28
        global $INFO;
29
        global $DATE_AT;
30
31
        //disable section editing for old revisions or in preview
32
        if ($txt || $REV) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $txt of type null|string is loosely compared to true; this is ambiguous if the string can be empty. You might want to explicitly use !== null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
33
            $secedit = false;
34
        } else {
35
            $secedit = true;
36
        }
37
38
        if (!is_null($txt)) {
39
            //PreviewHeader
40
            echo '<br id="scroll__here" />';
41
42
            // print intro for preview
43
            echo p_locale_xhtml('preview');
44
            echo '<div class="preview"><div class="pad">';
45
            $html = html_secedit(p_render('xhtml', p_get_instructions($txt), $info), $secedit);
46
            if ($INFO['prependTOC']) $html = tpl_toc(true) . $html;
47
            echo $html;
48
            echo '<div class="clearer"></div>';
49
            echo '</div></div>';
50
51
        } else {
52
            if ($REV || $DATE_AT) {
53
                // print intro for old revisions
54
                $data = array('rev' => &$REV, 'date_at' => &$DATE_AT);
55
                Event::createAndTrigger('HTML_SHOWREV_OUTPUT', $data, [$this, 'showrev']);
56
            }
57
            $html = p_wiki_xhtml($ID, $REV, true, $DATE_AT);
58
            $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...
59
            if ($INFO['prependTOC']) $html = tpl_toc(true) . $html;
60
            $html = html_hilight($html, $HIGH);
61
            echo $html;
62
        }
63
    }
64
65
    /**
66
     * Show a revision warning
67
     *
68
     * @author Szymon Olewniczak <[email protected]>
69
     */
70
    public function showrev()
71
    {
72
        print p_locale_xhtml('showrev');
73
    }
74
75
76
}
77