FormTrait   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
dl 0
loc 28
ccs 0
cts 8
cp 0
rs 10
c 0
b 0
f 0
wmc 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A buildRequestForm() 0 18 2
1
<?php
2
3
namespace Nilnice\Payment\Alipay\Traits;
4
5
trait FormTrait
6
{
7
    /**
8
     * Build request form.
9
     *
10
     * @param string $gateway
11
     * @param array  $payload
12
     *
13
     * @return string
14
     */
15
    public function buildRequestForm(string $gateway, array $payload) : string
16
    {
17
        $format
18
            = <<<HTML
19
<form id="alipaysubmit" name="alipaysubmit" action="%s" method="post">
20
    %s
21
    <input type="submit" value="ok" style="display: none">
22
    <script>document.forms['alipaysubmit'].submit()</script>
23
</form>
24
HTML;
25
        $input = '';
26
        foreach ($payload as $key => $val) {
27
            $val = str_replace("'", '&apos;', $val);
28
            $input .= "<input type='hidden' name='{$key}' value='{$val}'>";
29
        }
30
        $html = sprintf($format, $gateway, $input);
31
32
        return $html;
33
    }
34
}
35