RefundRequest   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 71
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 4

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 8
lcom 2
cbo 4
dl 0
loc 71
ccs 0
cts 43
cp 0
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A getEndpoint() 0 10 2
A getHttpMethod() 0 4 1
A getType() 0 4 1
A setType() 0 4 1
A sendData() 0 10 1
A getData() 0 15 2
1
<?php
2
3
namespace Omnipay\PaypalRest\Message;
4
5
use Omnipay\Common\Exception\InvalidRequestException;
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 RefundRequest extends AbstractPaypalRequest
13
{
14
    /**
15
     * @return string
16
     */
17
    public function getEndpoint()
18
    {
19
        $this->validate('transactionReference', 'type');
20
21
        if (false === in_array($this->getType(), array('sale', 'authorization', 'capture'))) {
22
            throw new InvalidRequestException('Type can only be "sale", "authorization" or "capture"');
23
        }
24
25
        return "/payments/{$this->getType()}/{$this->getTransactionReference()}/refund";
26
    }
27
28
    public function getHttpMethod()
29
    {
30
        return 'POST';
31
    }
32
33
    /**
34
     * @return string
35
     */
36
    public function getType()
37
    {
38
        return $this->getParameter('type');
39
    }
40
41
    /**
42
     * @param string $value
43
     */
44
    public function setType($value)
45
    {
46
        return $this->setParameter('type', $value);
47
    }
48
49
    /**
50
     * @param  mixed          $data
51
     * @return RefundResponse
52
     */
53
    public function sendData($data)
54
    {
55
        $httpResponse = $this->sendHttpRequest($data);
56
57
        return $this->response = new RefundResponse(
58
            $this,
59
            $httpResponse->json(),
60
            $httpResponse->getStatusCode()
61
        );
62
    }
63
64
    /**
65
     * @return array
66
     */
67
    public function getData()
68
    {
69
        if ($this->getAmount()) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $this->getAmount() of type string|null is loosely compared to true; this is ambiguous if the string can be empty. You might want to explicitly use !== null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
70
            $this->validate('currency');
71
72
            return array(
73
                'amount' => array(
74
                    'total' => $this->getAmount(),
75
                    'currency' => $this->getCurrency(),
76
                )
77
            );
78
        } else {
79
            return array();
80
        }
81
    }
82
}
83