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 ( 41c136...25e61d )
by Odiseo
09:14
created

StatusAction::execute()   C

Complexity

Conditions 12
Paths 21

Size

Total Lines 40
Code Lines 22

Duplication

Lines 0
Ratio 0 %

Importance

Changes 4
Bugs 1 Features 0
Metric Value
eloc 22
c 4
b 1
f 0
dl 0
loc 40
rs 6.9666
cc 12
nc 21
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 Odiseo\SyliusMercadoPagoPlugin\Payum\Action;
6
7
use Payum\Core\Action\ActionInterface;
8
use Payum\Core\Bridge\Spl\ArrayObject;
9
use Payum\Core\Exception\RequestNotSupportedException;
10
use Payum\Core\GatewayAwareInterface;
11
use Payum\Core\GatewayAwareTrait;
12
use Payum\Core\Request\GetHttpRequest;
13
use Payum\Core\Request\GetStatusInterface;
14
15
final class StatusAction implements ActionInterface, GatewayAwareInterface
16
{
17
    use GatewayAwareTrait;
18
19
    /**
20
     * {@inheritdoc}
21
     */
22
    public function execute($request): void
23
    {
24
        /** @var GetStatusInterface $request */
25
        RequestNotSupportedException::assertSupports($this, $request);
26
27
        /** @var ArrayObject $details */
28
        $details = ArrayObject::ensureArrayObject($request->getModel());
29
30
        if (empty($details) || !isset($details['preference'])) {
31
            $request->markNew();
32
33
            return;
34
        }
35
36
        $status = null;
37
38
        $this->gateway->execute($httpRequest = new GetHttpRequest());
39
40
        if (isset($httpRequest->query['collection_status'])) {
41
            $status = $httpRequest->query['collection_status'];
42
        }
43
44
        if (!$status && isset($details['payment']) && isset($details['payment']['status'])) {
45
            $status = $details['payment']['status'];
46
        }
47
48
        if (!$status) {
49
            $request->markNew();
50
51
            return;
52
        }
53
54
        if ('approved' === $status) {
55
            $request->markCaptured();
56
        } elseif ('rejected' === $status) {
57
            $request->markFailed();
58
        } elseif ('pending' === $status || 'in_process' === $status) {
59
            $request->markPending();
60
        } else {
61
            $request->markCanceled();
62
        }
63
    }
64
65
    /**
66
     * {@inheritdoc}
67
     */
68
    public function supports($request): bool
69
    {
70
        return
71
            $request instanceof GetStatusInterface &&
72
            $request->getModel() instanceof \ArrayAccess
73
        ;
74
    }
75
}
76