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

FormToArrayTrait   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 0
dl 0
loc 24
ccs 12
cts 12
cp 1
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B formToArray() 0 15 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