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.

StatusAction::execute()   B
last analyzed

Complexity

Conditions 10
Paths 11

Size

Total Lines 48
Code Lines 30

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 30
dl 0
loc 48
rs 7.6666
c 0
b 0
f 0
cc 10
nc 11
nop 1

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
declare(strict_types=1);
4
5
namespace BitBag\SyliusBraintreePlugin\Action;
6
7
use BitBag\SyliusBraintreePlugin\ApiClient\BraintreeApiClientInterface;
8
use Payum\Core\Action\ActionInterface;
9
use Payum\Core\Bridge\Spl\ArrayObject;
10
use Payum\Core\Exception\RequestNotSupportedException;
11
use Payum\Core\Request\GetStatusInterface;
12
13
final class StatusAction implements ActionInterface
14
{
15
    public function execute($request): void
16
    {
17
        RequestNotSupportedException::assertSupports($this, $request);
18
19
        $details = ArrayObject::ensureArrayObject($request->getModel());
20
21
        $status = $details['status'];
22
23
        if (null != $status) {
24
            switch ($status) {
25
                case BraintreeApiClientInterface::FAILED:
26
                    $request->markFailed();
27
28
                    return;
29
                case BraintreeApiClientInterface::AUTHORIZED:
30
                    if ($this->hasSuccessfulTransaction($details)) {
31
                        $request->markAuthorized();
32
                    } else {
33
                        $request->markUnknown();
34
                    }
35
36
                    return;
37
                case BraintreeApiClientInterface::CAPTURED:
38
                    if ($this->hasSuccessfulTransaction($details)) {
39
                        $request->markCaptured();
40
                    } else {
41
                        $request->markUnknown();
42
                    }
43
44
                    return;
45
                case BraintreeApiClientInterface::REFUNDED:
46
                    if ($this->hasSuccessfulTransaction($details)) {
47
                        $request->markRefunded();
48
                    } else {
49
                        $request->markUnknown();
50
                    }
51
52
                    return;
53
            }
54
        }
55
56
        if ($details['paymentMethodNonce']) {
57
            $request->markPending();
58
59
            return;
60
        }
61
62
        $request->markNew();
63
    }
64
65
    public function supports($request): bool
66
    {
67
        return
68
            $request instanceof GetStatusInterface &&
69
            $request->getModel() instanceof \ArrayAccess
70
        ;
71
    }
72
73
    private function hasSuccessfulTransaction($details): bool
74
    {
75
        return $details['sale'] && $details['sale']['success'];
76
    }
77
}
78