Submit::setTitle()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace kalanis\kw_forms\Controls;
4
5
6
/**
7
 * Class Submit
8
 * @package kalanis\kw_forms\Controls
9
 * Form element for submit button
10
 */
11
class Submit extends Button
12
{
13
    protected string $templateInput = '<input type="submit" value="%1$s"%2$s />';
14
    protected $originalValue = 'submit';
15
16
    /**
17
     * Check if form was sent by this button
18
     * @var boolean
19
     */
20
    protected bool $submitted = false;
21
22 2
    public function setValue($value): void
23
    {
24 2
        $this->submitted = !empty($value);
25 2
    }
26
27 2
    public function getValue()
28
    {
29 2
        return $this->submitted ? $this->originalValue : '' ;
30
    }
31
32 1
    public function setTitle(string $title): void
33
    {
34 1
        $this->originalValue = $title;
35 1
    }
36
37 2
    public function renderInput($attributes = null): string
38
    {
39 2
        $this->addAttributes($attributes);
40 2
        $this->setAttribute('name', $this->getKey());
41 2
        return $this->wrapIt(sprintf($this->templateInput, strval($this->originalValue), $this->renderAttributes(), $this->renderChildren()), $this->wrappersInput);
42
    }
43
}
44