AbstractResponse   A
last analyzed

Complexity

Total Complexity 11

Size/Duplication

Total Lines 73
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 1

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 11
lcom 2
cbo 1
dl 0
loc 73
ccs 0
cts 36
cp 0
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A getTransactionReference() 0 6 2
A isSuccessful() 0 4 1
A getStatus() 0 6 2
A getMessage() 0 14 4
A getCode() 0 4 1
1
<?php
2
3
namespace Omnipay\PaypalRest\Message;
4
5
use Omnipay\Common\Message\RequestInterface;
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 AbstractResponse extends \Omnipay\Common\Message\AbstractResponse
13
{
14
    /**
15
     * @var integer
16
     */
17
    protected $code;
18
19
    /**
20
     * @param RequestInterface $request
21
     * @param array            $data
22
     * @param integer          $code
23
     */
24
    public function __construct(RequestInterface $request, $data, $code = 200)
25
    {
26
        parent::__construct($request, $data);
27
28
        $this->code = (int) $code;
29
    }
30
31
    /**
32
     * @return string|null
33
     */
34
    public function getTransactionReference()
35
    {
36
        if (isset($this->data['id'])) {
37
            return $this->data['id'];
38
        }
39
    }
40
41
    /**
42
     * @return boolean
43
     */
44
    public function isSuccessful()
45
    {
46
        return $this->getCode() < 400;
47
    }
48
49
    /**
50
     * @return string|null
51
     */
52
    public function getStatus()
53
    {
54
        if (isset($this->data['status'])) {
55
            return $this->data['status'];
56
        }
57
    }
58
59
    /**
60
     * @return string|null
61
     */
62
    public function getMessage()
63
    {
64
        $message = null;
65
66
        if (isset($this->data['name']) and isset($this->data['message'])) {
67
            $message = $this->data['name'].': '.$this->data['message'];
68
        }
69
70
        if (isset($this->data['details'])) {
71
            $message .= ' ['.json_encode($this->data['details']).']';
72
        }
73
74
        return $message;
75
    }
76
77
    /**
78
     * @return integer
79
     */
80
    public function getCode()
81
    {
82
        return $this->code;
83
    }
84
}
85