Completed
Push — master ( 27c102...e85ee7 )
by Haralan
03:23 queued 01:27
created

PaymentApproveResponse::isRedirect()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 4
cp 0
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
crap 2
1
<?php
2
3
namespace Omnipay\PaypalRest\Message;
4
5
use Omnipay\Common\Message\RedirectResponseInterface;
6
7
/**
8
 * @author    Ivan Kerin <[email protected]>
9
 * @copyright 2014, Clippings Ltd.
10
 * @license   http://spdx.org/licenses/BSD-3-Clause
11
 */
12
class PaymentApproveResponse extends AbstractResponse implements RedirectResponseInterface
13
{
14
    /**
15
     * @param  string     $rel
16
     * @return array|null
17
     */
18
    public function getLink($rel)
19
    {
20
        if (isset($this->data['links'])) {
21
            foreach ($this->data['links'] as $link) {
22
                if ($link['rel'] === $rel) {
23
                    return $link;
24
                }
25
            }
26
        }
27
28
        return null;
29
    }
30
31
    /**
32
     * Return false, because this is a redirect response
33
     *
34
     * @return boolean
35
     */
36
    public function isSuccessful()
37
    {
38
        return false;
39
    }
40
41
    public function isRedirect()
42
    {
43
        return $this->getLink('approval_url') !== null;
44
    }
45
46
    /**
47
     * Gets the redirect target url.
48
     *
49
     * @return string
50
     */
51
    public function getRedirectUrl()
52
    {
53
        $link = $this->getLink('approval_url');
54
55
        return $link['href'];
56
    }
57
58
    /**
59
     * Get the required redirect method (either GET or POST).
60
     *
61
     * @return string
62
     */
63
    public function getRedirectMethod()
64
    {
65
        return 'GET';
66
    }
67
68
    /**
69
     * @return array
70
     */
71
    public function getRedirectData()
72
    {
73
        return array();
74
    }
75
}
76