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.

SibsService::checkout()   C
last analyzed

Complexity

Conditions 12
Paths 12

Size

Total Lines 49
Code Lines 42

Duplication

Lines 0
Ratio 0 %

Importance

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