FieldsetOpenElement::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 2
dl 0
loc 8
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace dokuwiki\Form;
4
5
/**
6
 * Class FieldsetOpenElement
7
 *
8
 * Opens a Fieldset with an optional legend
9
 *
10
 * @package dokuwiki\Form
11
 */
12
class FieldsetOpenElement extends TagOpenElement
13
{
14
15
    /**
16
     * @param string $legend
17
     * @param array $attributes
18
     */
19
    public function __construct($legend='', $attributes = array())
20
    {
21
        // this is a bit messy and we just do it for the nicer class hierarchy
22
        // the parent would expect the tag in $value but we're storing the
23
        // legend there, so we have to set the type manually
24
        parent::__construct($legend, $attributes);
25
        $this->type = 'fieldsetopen';
26
    }
27
28
    /**
29
     * The HTML representation of this element
30
     *
31
     * @return string
32
     */
33
    public function toHTML()
34
    {
35
        $html = '<fieldset '.buildAttributes($this->attrs()).'>';
0 ignored issues
show
Bug introduced by
It seems like $this->attrs() targeting dokuwiki\Form\Element::attrs() can also be of type this<dokuwiki\Form\FieldsetOpenElement>; however, buildAttributes() does only seem to accept array, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
36
        $legend = $this->val();
37
        if ($legend) $html .= DOKU_LF.'<legend>'.hsc($legend).'</legend>';
0 ignored issues
show
Bug introduced by
It seems like $legend defined by $this->val() on line 36 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...
38
        return $html;
39
    }
40
}
41