Completed
Push — allow-no-default-tax-zone-in-c... ( 67cea0 )
by Kamil
06:23
created

AuthorizePaymentAction   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 60
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 4
dl 0
loc 60
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A execute() 0 34 3
A supports() 0 6 2
1
<?php
2
3
/*
4
 * This file is part of the Sylius package.
5
 *
6
 * (c) Paweł Jędrzejewski
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
declare(strict_types=1);
13
14
namespace Sylius\Bundle\PayumBundle\Action;
15
16
use Payum\Core\Action\GatewayAwareAction;
17
use Payum\Core\Bridge\Spl\ArrayObject;
18
use Payum\Core\Exception\RequestNotSupportedException;
19
use Payum\Core\Model\Payment as PayumPayment;
20
use Payum\Core\Request\Authorize;
21
use Payum\Core\Request\Convert;
22
use Sylius\Bundle\PayumBundle\Provider\PaymentDescriptionProviderInterface;
23
use Sylius\Bundle\PayumBundle\Request\GetStatus;
24
use Sylius\Component\Core\Model\OrderInterface;
25
use Sylius\Component\Core\Model\PaymentInterface as SyliusPaymentInterface;
26
27
final class AuthorizePaymentAction extends GatewayAwareAction
28
{
29
    /** @var PaymentDescriptionProviderInterface */
30
    private $paymentDescriptionProvider;
31
32
    public function __construct(PaymentDescriptionProviderInterface $paymentDescriptionProvider)
33
    {
34
        $this->paymentDescriptionProvider = $paymentDescriptionProvider;
35
    }
36
37
    /**
38
     * {@inheritdoc}
39
     *
40
     * @param Authorize $request
41
     */
42
    public function execute($request): void
43
    {
44
        RequestNotSupportedException::assertSupports($this, $request);
45
        /** @var SyliusPaymentInterface $payment */
46
        $payment = $request->getModel();
47
        /** @var OrderInterface $order */
48
        $order = $payment->getOrder();
49
        $this->gateway->execute($status = new GetStatus($payment));
50
        if ($status->isNew()) {
51
            try {
52
                $this->gateway->execute($convert = new Convert($payment, 'array', $request->getToken()));
53
                $payment->setDetails($convert->getResult());
54
            } catch (RequestNotSupportedException $e) {
0 ignored issues
show
Bug introduced by
The class Payum\Core\Exception\RequestNotSupportedException does not exist. Did you forget a USE statement, or did you not list all dependencies?

Scrutinizer analyzes your composer.json/composer.lock file if available to determine the classes, and functions that are defined by your dependencies.

It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis.

Loading history...
55
                $payumPayment = new PayumPayment();
56
                $payumPayment->setNumber($order->getNumber());
57
                $payumPayment->setTotalAmount($payment->getAmount());
58
                $payumPayment->setCurrencyCode($order->getCurrencyCode());
59
                $payumPayment->setClientEmail($order->getCustomer()->getEmail());
60
                $payumPayment->setClientId($order->getCustomer()->getId());
61
                $payumPayment->setDescription($this->paymentDescriptionProvider->getPaymentDescription($payment));
62
                $payumPayment->setDetails($payment->getDetails());
63
                $this->gateway->execute($convert = new Convert($payumPayment, 'array', $request->getToken()));
64
                $payment->setDetails($convert->getResult());
65
            }
66
        }
67
        $details = ArrayObject::ensureArrayObject($payment->getDetails());
68
69
        try {
70
            $request->setModel($details);
71
            $this->gateway->execute($request);
72
        } finally {
73
            $payment->setDetails((array) $details);
74
        }
75
    }
76
77
    /**
78
     * {@inheritdoc}
79
     */
80
    public function supports($request): bool
81
    {
82
        return
83
            $request instanceof Authorize &&
0 ignored issues
show
Bug introduced by
The class Payum\Core\Request\Authorize does not exist. Did you forget a USE statement, or did you not list all dependencies?

This error could be the result of:

1. Missing dependencies

PHP Analyzer uses your composer.json file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects the composer.json to be in the root folder of your repository.

Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the require or require-dev section?

2. Missing use statement

PHP does not complain about undefined classes in ìnstanceof checks. For example, the following PHP code will work perfectly fine:

if ($x instanceof DoesNotExist) {
    // Do something.
}

If you have not tested against this specific condition, such errors might go unnoticed.

Loading history...
84
            $request->getModel() instanceof SyliusPaymentInterface;
85
    }
86
}
87