TextareaElement   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
dl 0
loc 47
rs 10
c 0
b 0
f 0
wmc 5
lcom 1
cbo 1

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A val() 0 8 2
A mainElementHTML() 0 6 2
1
<?php
2
3
namespace dokuwiki\Form;
4
5
/**
6
 * Class TextareaElement
7
 * @package dokuwiki\Form
8
 */
9
class TextareaElement extends InputElement
10
{
11
    /**
12
     * @var string the actual text within the area
13
     */
14
    protected $text;
15
16
    /**
17
     * @param string $name The name of this form element
18
     * @param string $label The label text for this element
19
     */
20
    public function __construct($name, $label)
21
    {
22
        parent::__construct('textarea', $name, $label);
23
        $this->attr('dir', 'auto');
24
    }
25
26
    /**
27
     * Get or set the element's value
28
     *
29
     * This is the preferred way of setting the element's value
30
     *
31
     * @param null|string $value
32
     * @return string|$this
33
     */
34
    public function val($value = null)
35
    {
36
        if ($value !== null) {
37
            $this->text = cleanText($value);
38
            return $this;
39
        }
40
        return $this->text;
41
    }
42
43
    /**
44
     * The HTML representation of this element
45
     *
46
     * @return string
47
     */
48
    protected function mainElementHTML()
49
    {
50
        if ($this->useInput) $this->prefillInput();
51
        return '<textarea ' . 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\TextareaElement>; 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...
52
            formText($this->val()) . '</textarea>';
0 ignored issues
show
Bug introduced by
It seems like $this->val() targeting dokuwiki\Form\TextareaElement::val() can also be of type this<dokuwiki\Form\TextareaElement>; however, formText() does only seem to accept string, 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...
53
    }
54
55
}
56