GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

PurchaseRequest::validateCurrency()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 13
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 13
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 7
nc 3
nop 1
1
<?php
2
3
namespace Omnipay\Tithely\Message;
4
5
use Omnipay\Common\Exception\InvalidRequestException;
6
7
/**
8
 * Purchase Request
9
 *
10
 * @method Response send()
11
 */
12
class PurchaseRequest extends AbstractRequest
13
{
14
    /**
15
     * Validate the currency.
16
     *
17
     * This method checks a currency against the Tithe.ly organization's
18
     * bank account configuration.
19
     *
20
     * @param string $currency
21
     * @throws InvalidRequestException
22
     */
23
    private function validateCurrency($currency)
24
    {
25
        $organization = $this->getOrganization();
26
        $data = $organization->getData();
27
28
        if (!isset($data['object']['bank']['currency'])) {
29
            throw new InvalidRequestException('Could not fetch organization.');
30
        }
31
32
        if ($data['object']['bank']['currency'] != $currency) {
33
            throw new InvalidRequestException('The organization does not support payments made in ' . $currency . '.');
34
        }
35
    }
36
37
    public function getData()
38
    {
39
        $this->validate('token', 'amount', 'currency', 'card');
40
        $this->validateCurrency($this->getCurrency());
41
42
        $data = array(
43
            'first_name' => $this->getCard()->getFirstName(),
44
            'last_name' => $this->getCard()->getLastName(),
45
            'email' => $this->getCard()->getEmail(),
46
            'token' => $this->getParameter('token'),
47
            'organization_id' => $this->getOrganizationId(),
48
            'amount' => $this->getAmountInteger(),
49
            'giving_type' => $this->getGivingType()
50
        );
51
52
        return $data;
53
    }
54
55
    public function getEndpoint()
56
    {
57
        return parent::getEndpoint() . '/charge-once';
58
    }
59
}
60