ResolveNextUrlAction   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A execute() 0 7 1
A supports() 0 7 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace PH\Bundle\PayumBundle\Action\Offline;
6
7
use Payum\Core\Action\ActionInterface;
8
use PH\Bundle\PayumBundle\Request\ResolveNextUrl;
9
use Sylius\Component\Payment\Model\PaymentInterface;
10
11
final class ResolveNextUrlAction implements ActionInterface
12
{
13
    /**
14
     * @var string
15
     */
16
    private $thankYouUrl;
17
18
    /**
19
     * ResolveNextUrlAction constructor.
20
     *
21
     * @param string $thankYouUrl
22
     */
23
    public function __construct(string $thankYouUrl)
24
    {
25
        $this->thankYouUrl = $thankYouUrl;
26
    }
27
28
    /**
29
     * {@inheritdoc}
30
     *
31
     * @param ResolveNextUrl $request
32
     */
33
    public function execute($request): void
34
    {
35
        /** @var PaymentInterface $payment */
36
        $payment = $request->getFirstModel();
37
        $request->setUrl($this->thankYouUrl);
38
        $request->setUrlQueryParams(['token' => $payment->getSubscription()->getTokenValue()]);
39
    }
40
41
    /**
42
     * {@inheritdoc}
43
     */
44
    public function supports($request): bool
45
    {
46
        return
47
            $request instanceof ResolveNextUrl &&
48
            $request->getFirstModel() instanceof PaymentInterface
49
        ;
50
    }
51
}
52