GrowingTextarea::setValue()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 4
c 1
b 0
f 0
nc 2
nop 2
dl 0
loc 7
rs 10
1
<?php
2
3
namespace LeKoala\FormElements;
4
5
use SilverStripe\Forms\TextareaField;
6
use SilverStripe\View\Requirements;
7
8
/**
9
 */
10
class GrowingTextarea extends TextareaField
11
{
12
    use BaseElement;
0 ignored issues
show
Bug introduced by
The trait LeKoala\FormElements\BaseElement requires the property $default_config which is not provided by LeKoala\FormElements\GrowingTextarea.
Loading history...
13
14
    /**
15
     * @config
16
     * @var boolean
17
     */
18
    private static $enable_requirements = true;
0 ignored issues
show
introduced by
The private property $enable_requirements is not used, and could be removed.
Loading history...
19
20
    /**
21
     * @var boolean
22
     */
23
    protected $trim = false;
24
25
    public function __construct($name, $title = null, $value = '', $config = null)
0 ignored issues
show
Unused Code introduced by
The parameter $config is not used and could be removed. ( Ignorable by Annotation )

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

25
    public function __construct($name, $title = null, $value = '', /** @scrutinizer ignore-unused */ $config = null)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
26
    {
27
        parent::__construct($name, $title, $value);
28
        $this->setRows(1);
29
    }
30
31
    public function Field($properties = array())
32
    {
33
        return $this->wrapInElement('growing-textarea', $properties);
34
    }
35
36
    public function setValue($value, $data = null)
37
    {
38
        parent::setValue($value, $data);
39
        if ($this->value) {
40
            $this->setRows(substr_count($this->value, "\n") + 1);
41
        }
42
        return $this;
43
    }
44
45
    public static function requirements()
46
    {
47
        Requirements::javascript("lekoala/silverstripe-form-elements: client/custom-elements/growing-textarea.min.js");
48
    }
49
50
    /**
51
     * Get the value of trim
52
     */
53
    public function getTrim()
54
    {
55
        return $this->getElementAttribute('data-trim');
56
    }
57
58
    /**
59
     * Set the value of trim
60
     *
61
     * @param bool $trim
62
     */
63
    public function setTrim($trim)
64
    {
65
        return $this->setElementAttribute('data-trim', $trim);
66
    }
67
}
68