Completed
Push — master ( 32f9a3...71c606 )
by recca
02:39
created

FormToArrayTrait::formToArray()   B

Complexity

Conditions 5
Paths 2

Size

Total Lines 15
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 12
CRAP Score 5

Importance

Changes 0
Metric Value
dl 0
loc 15
ccs 12
cts 12
cp 1
rs 8.8571
c 0
b 0
f 0
cc 5
eloc 8
nc 2
nop 1
crap 5
1
<?php
2
3
namespace PayumTW\Ecpay\Sdk;
4
5
trait FormToArrayTrait
6
{
7
    /**
8
     * formTOArray.
9
     *
10
     * @param string $form
11
     * @return array
12
     */
13 2
    public function formToArray($form)
14
    {
15 2
        $result = [];
16 2
        if (preg_match_all('/<input[^>]*>/sm', $form, $inputs) !== false) {
17 2
            foreach ($inputs[0] as $input) {
18 2
                if (preg_match('/name=["\']([^"\']*)["\']\s+value=["\']([^"\']*)["\']/', $input, $match) !== false) {
19 2
                    if (count($match) === 3) {
20 2
                        $result[$match[1]] = $match[2];
21 2
                    }
22 2
                }
23 2
            }
24 2
        }
25
26 2
        return $result;
27
    }
28
}
29