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.
Passed
Push — master ( 68460a...213420 )
by Miguel
42s queued 11s
created

SibsService::checkout()   C

Complexity

Conditions 12
Paths 12

Size

Total Lines 41
Code Lines 35

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 12
eloc 35
nc 12
nop 1
dl 0
loc 41
rs 6.9666
c 0
b 0
f 0

How to fix   Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
namespace Apoca\Sibs\Services;
4
5
use Apoca\Sibs\Brands\Card;
6
use Apoca\Sibs\Brands\Checkout;
7
use Apoca\Sibs\Brands\PaymentWithCard;
8
use Apoca\Sibs\Brands\Transaction;
9
use Apoca\Sibs\Contracts\PaymentInterface;
10
use Exception;
11
12
/**
13
 * Class SibsService
14
 *
15
 * @package Apoca\Sibs\Services
16
 */
17
class SibsService
18
{
19
    /**
20
     * @param array $request
21
     *
22
     * @return PaymentInterface
23
     * @throws Exception
24
     */
25
    public function checkout(array $request): PaymentInterface
26
    {
27
        switch (strtoupper($request['brand'])) {
28
            case 'MASTER':
29
            case 'AMEX':
30
            case 'VPAY':
31
            case 'MAESTRO':
32
            case 'VISADEBIT':
33
            case 'VISAELECTRON':
34
            case 'VISA':
35
                $payment = new PaymentWithCard(
36
                    $request['amount'],
37
                    strtoupper($request['currency']),
38
                    strtoupper($request['brand']),
39
                    strtoupper($request['type']),
40
                    new Card(
41
                        $request['number'],
42
                        $request['holder'],
43
                        $request['expiry_month'],
44
                        $request['expiry_year'],
45
                        $request['cvv']
46
                    )
47
                );
48
                break;
49
            case 'CHECKOUT':
50
                $payment = new Checkout($request['amount'], $request['currency'], $request['type']);
51
                break;
52
            case 'SIBS_MULTIBANCO':
53
                throw new \RuntimeException('SIBS_MULTIBANCO Service Payment not found.', 404);
54
                break;
55
            case 'DIRECTDEBIT_SEPA':
56
                throw new \RuntimeException('DIRECTDEBIT_SEPA Service Payment not found.', 404);
57
                break;
58
            case 'MBWAY':
59
                throw new \RuntimeException('MBWAY Service Payment not found.', 404);
60
                break;
61
            default:
62
                throw new \RuntimeException('Sibs Service Payment not found.', 404);
63
        }
64
65
        return $payment;
66
    }
67
68
    /**
69
     * Get payment status
70
     *
71
     * @param string $checkoutId
72
     *
73
     * @return object
74
     */
75
    public function status(string $checkoutId): object
76
    {
77
        return (new Transaction($checkoutId))->status();
78
    }
79
}
80