FormMethodHelper::process()   A
last analyzed

Complexity

Conditions 3
Paths 2

Size

Total Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 9
rs 9.9666
c 0
b 0
f 0
cc 3
nc 2
nop 1
1
<?php
2
3
namespace BeyondCode\TagHelper\Helpers;
4
5
use BeyondCode\TagHelper\Helper;
6
use BeyondCode\TagHelper\Html\HtmlElement;
7
8
class FormMethodHelper extends Helper
9
{
10
    protected $targetAttribute = 'method';
11
12
    protected $targetElement = 'form';
13
14
    public function process(HtmlElement $element)
15
    {
16
        $method = strtolower($element->getAttribute('method'));
17
18
        if ($method !== 'get' && $method !== 'post') {
19
            $element->setAttribute('method', 'post');
20
            $element->appendInnerText('<input type="hidden" name="_method" value="'.strtoupper($method).'" />');
21
        }
22
    }
23
}
24