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 ( 507517...41c136 )
by
unknown
05:24
created

StatusAction   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Importance

Changes 5
Bugs 1 Features 0
Metric Value
wmc 9
eloc 24
c 5
b 1
f 0
dl 0
loc 51
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A supports() 0 5 2
B execute() 0 33 7
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 $payment */
28
        $payment = $request->getModel();
29
        $paymentDetails = $payment->toUnsafeArray();
30
31
        if (empty($paymentDetails) || !$paymentDetails['preference']) {
32
            $request->markNew();
33
34
            return;
35
        }
36
37
        $this->gateway->execute($httpRequest = new GetHttpRequest());
38
39
        if (!isset($httpRequest->query['collection_status'])) {
40
            $request->markNew();
41
42
            return;
43
        }
44
45
        $status = $httpRequest->query['collection_status'];
46
47
        if ($status === 'approved') {
48
            $request->markCaptured();
49
        } elseif ($status === 'rejected') {
50
            $request->markFailed();
51
        } elseif ($status === 'pending') {
52
            $request->markPending();
53
        } else {
54
            $request->markCanceled();
55
        }
56
    }
57
58
    /**
59
     * {@inheritdoc}
60
     */
61
    public function supports($request): bool
62
    {
63
        return
64
            $request instanceof GetStatusInterface &&
65
            $request->getModel() instanceof \ArrayAccess
66
        ;
67
    }
68
}
69