Code Duplication    Length = 44-44 lines in 2 locations

OptionsBuilder/Behavior/AutocompleteTrait.php 1 location

@@ 7-50 (lines=44) @@
4
5
use steevanb\SymfonyFormOptionsBuilder\Behavior\OptionAccessorsTrait;
6
7
trait AutocompleteTrait
8
{
9
    use OptionAccessorsTrait;
10
11
    /**
12
     * @param string $name
13
     * @param mixed $value
14
     * @return $this
15
     */
16
    abstract public function addAttr($name, $value);
17
18
    /**
19
     * @param string $name
20
     * @return array|mixed
21
     */
22
    abstract public function getAttr($name = null);
23
24
    /**
25
     * @param string $name
26
     * @return $this
27
     */
28
    abstract public function removeAttr($name);
29
30
    /**
31
     * @param bool $autocomplete
32
     * @return $this
33
     */
34
    public function setAutocomplete($autocomplete = true)
35
    {
36
        if ($autocomplete) {
37
            return $this->removeAttr('autocomplete');
38
        } else {
39
            return $this->addAttr('autocomplete', 'off');
40
        }
41
    }
42
43
    /**
44
     * @return bool
45
     */
46
    public function getAutocomplete()
47
    {
48
        return $this->getAttr('autocomplete') !== 'off';
49
    }
50
}
51

OptionsBuilder/Behavior/AutofocusTrait.php 1 location

@@ 7-50 (lines=44) @@
4
5
use steevanb\SymfonyFormOptionsBuilder\Behavior\OptionAccessorsTrait;
6
7
trait AutofocusTrait
8
{
9
    use OptionAccessorsTrait;
10
11
    /**
12
     * @param string $name
13
     * @param mixed $value
14
     * @return $this
15
     */
16
    abstract public function addAttr($name, $value);
17
18
    /**
19
     * @param string $name
20
     * @return array|mixed
21
     */
22
    abstract public function getAttr($name = null);
23
24
    /**
25
     * @param string $name
26
     * @return $this
27
     */
28
    abstract public function removeAttr($name);
29
30
    /**
31
     * @param bool $autofocus
32
     * @return $this
33
     */
34
    public function setAutofocus($autofocus = true)
35
    {
36
        if ($autofocus) {
37
            return $this->addAttr('autofocus', '');
38
        } else {
39
            return $this->removeAttr('autofocus');
40
        }
41
    }
42
43
    /**
44
     * @return bool
45
     */
46
    public function getAutofocus()
47
    {
48
        return $this->getAttr('autofocus') !== null;
49
    }
50
}
51