Completed
Push — sidebaracl ( 7a112d...7c3e4a )
by Andreas
04:38
created

inc/Form/FieldsetOpenElement.php (1 issue)

Labels
Severity

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
namespace dokuwiki\Form;
3
4
/**
5
 * Class FieldsetOpenElement
6
 *
7
 * Opens a Fieldset with an optional legend
8
 *
9
 * @package dokuwiki\Form
10
 */
11
class FieldsetOpenElement extends TagOpenElement {
12
13
    /**
14
     * @param string $legend
15
     * @param array $attributes
16
     */
17
    public function __construct($legend='', $attributes = array()) {
18
        // this is a bit messy and we just do it for the nicer class hierarchy
19
        // the parent would expect the tag in $value but we're storing the
20
        // legend there, so we have to set the type manually
21
        parent::__construct($legend, $attributes);
22
        $this->type = 'fieldsetopen';
23
    }
24
25
    /**
26
     * The HTML representation of this element
27
     *
28
     * @return string
29
     */
30
    public function toHTML() {
31
        $html = '<fieldset '.buildAttributes($this->attrs()).'>';
32
        $legend = $this->val();
33
        if($legend) $html .= DOKU_LF.'<legend>'.hsc($legend).'</legend>';
0 ignored issues
show
It seems like $legend defined by $this->val() on line 32 can also be of type this<dokuwiki\Form\FieldsetOpenElement>; however, hsc() 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...
34
        return $html;
35
    }
36
}
37