FormElementTextarea::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 2
dl 0
loc 5
ccs 0
cts 4
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Anax\HTMLForm;
4
5
/**
6
 * Form element
7
 */
8
class FormElementTextarea extends FormElement
9
{
10
11
    /**
12
     * Constructor
13
     *
14
     * @param string $name       of the element.
15
     * @param array  $attributes to set to the element. Default is an empty
16
     *                           array.
17
     */
18
    public function __construct($name, $attributes = [])
19
    {
20
        parent::__construct($name, $attributes);
21
        $this['type'] = 'textarea';
22
        $this->UseNameAsDefaultLabel();
23
    }
24
25
26
27
    /**
28
     * Get HTML code for a element.
29
     *
30
     * @return string HTML code for the element.
31
     *
32
     * @SuppressWarnings(PHPMD.UnusedLocalVariable)
33
     */
34
    public function getHTML()
35
    {
36
        $details = $this->getHTMLDetails();
37
        extract($details);
0 ignored issues
show
Bug introduced by
$details of type Anax\HTMLForm\HTML is incompatible with the type array expected by parameter $var_array of extract(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

37
        extract(/** @scrutinizer ignore-type */ $details);
Loading history...
38
39
        return <<<EOD
0 ignored issues
show
Bug Best Practice introduced by
The expression return '<'.$wrapperEleme...'>'.$description.'</p>' returns the type string which is incompatible with the return type mandated by Anax\HTMLForm\FormElement::getHTML() of Anax\HTMLForm\HTML.

In the issue above, the returned value is violating the contract defined by the mentioned interface.

Let's take a look at an example:

interface HasName {
    /** @return string */
    public function getName();
}

class Name {
    public $name;
}

class User implements HasName {
    /** @return string|Name */
    public function getName() {
        return new Name('foo'); // This is a violation of the ``HasName`` interface
                                // which only allows a string value to be returned.
    }
}
Loading history...
40
<{$wrapperElement}{$wrapperClass}>
41
<label for='$id'>$label</label>$brAfterLabel
42
<textarea id='$id'{$class}{$name}{$autofocus}{$required}{$readonly}{$placeholder}{$title}>{$onlyValue}</textarea>
43
</{$wrapperElement}>
44
<p class='cf-desc'>{$description}</p>
45
EOD;
46
    }
47
}
48