PurchaseResponse::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 5
ccs 4
cts 4
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 2
crap 1
1
<?php
2
3
namespace Omnipay\AllPay\Message;
4
5
use Omnipay\Common\Message\RedirectResponseInterface;
6
use Omnipay\Common\Message\RequestInterface;
7
8
class PurchaseResponse extends Response implements RedirectResponseInterface
9
{
10 12
    public function __construct(RequestInterface $request, $data)
11
    {
12 12
        $this->request = $request;
13 12
        $this->data = $data;
14 12
    }
15
16 12
    public function isRedirect()
17
    {
18 12
        return !!$this->getFormAction();
19
    }
20
21 9
    public function isSuccessful()
22
    {
23 9
        return false;
24
    }
25
26 3
    public function getRedirectMethod()
27
    {
28 3
        return 'POST';
29
    }
30
31 6
    public function getRedirectUrl()
32
    {
33 6
        return $this->getFormAction();
34
    }
35
36 3
    public function getRedirectData()
37
    {
38 3
        return $this->getFormFields();
39
    }
40
41 3
    public function getCode()
42
    {
43 3
        return $this->isSuccessful() ? '00' : '01';
44
    }
45
46 3
    public function getMessage()
47
    {
48 3
        return $this->getData();
49
    }
50
51 12
    protected function getFormAction()
52
    {
53 12
        preg_match("/action=\'(.*?)\'/", $this->data, $matches);
54
55 12
        return $matches[1] ?? null;
56
    }
57
58 3
    protected function getFormFields()
59
    {
60 3
        preg_match_all("/type=\'hidden\' name=\'(.*?)\' value=\'(.*?)\'/", $this->data, $matches);
61
62 3
        $fields = [];
63
64 3
        foreach ($matches[0] as $i => $match) {
65 3
            $fields[$matches[1][$i]] = $matches[2][$i];
66
        }
67
68 3
        return $fields;
69
    }
70
}
71