SepaOneOffObtainBankAccountAction   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 46
Duplicated Lines 21.74 %

Coupling/Cohesion

Components 1
Dependencies 9

Importance

Changes 0
Metric Value
wmc 8
lcom 1
cbo 9
dl 10
loc 46
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A execute() 0 24 3
A supports() 10 10 5

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
declare(strict_types=1);
4
5
namespace PH\Bundle\PayumBundle\Action\Mollie\SepaDirectDebit;
6
7
use PayHelper\Payum\Mollie\Constants;
8
use PayHelper\Payum\Mollie\Request\Api\CreateSepaOneOffPayment;
9
use Payum\Core\Action\ActionInterface;
10
use Payum\Core\Bridge\Spl\ArrayObject;
11
use Payum\Core\Exception\LogicException;
12
use Payum\Core\Exception\RequestNotSupportedException;
13
use Payum\Core\GatewayAwareInterface;
14
use Payum\Core\GatewayAwareTrait;
15
use Payum\Core\Model\BankAccountInterface;
16
use Payum\Core\Security\SensitiveValue;
17
use PH\Bundle\PayumBundle\Request\ObtainBankAccount;
18
19
class SepaOneOffObtainBankAccountAction implements ActionInterface, GatewayAwareInterface
20
{
21
    use GatewayAwareTrait;
22
23
    /**
24
     * {@inheritdoc}
25
     */
26
    public function execute($request)
27
    {
28
        RequestNotSupportedException::assertSupports($this, $request);
29
30
        $model = ArrayObject::ensureArrayObject($request->getModel());
31
32
        if (!$model->validateNotEmpty(['sepaIban', 'sepaHolder'], false)) {
33
            try {
34
                $obtainBankAccount = new ObtainBankAccount($request->getToken());
35
                $obtainBankAccount->setModel($request->getModel());
36
                $this->gateway->execute($obtainBankAccount);
37
38
                /** @var BankAccountInterface $bankAccount */
39
                $bankAccount = $obtainBankAccount->obtain();
40
41
                $model['sepaIban'] = SensitiveValue::ensureSensitive($bankAccount->getIban());
42
                $model['sepaHolder'] = SensitiveValue::ensureSensitive($bankAccount->getHolder());
43
44
                $this->gateway->execute(new CreateSepaOneOffPayment($model));
45
            } catch (RequestNotSupportedException $e) {
46
                throw new LogicException('Bank account details has to be set explicitly or there has to be an action that supports ObtainBankAccount request.');
47
            }
48
        }
49
    }
50
51
    /**
52
     * {@inheritdoc}
53
     */
54 View Code Duplication
    public function supports($request)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
55
    {
56
        return
57
            $request instanceof CreateSepaOneOffPayment &&
58
            $request->getModel() instanceof \ArrayAccess &&
59
            Constants::METHOD_DIRECTDEBIT_ONEOFF === $request->getModel()['method'] &&
60
            !isset($request->getModel()['sepaIban']) &&
61
            !isset($request->getModel()['sepaHolder'])
62
        ;
63
    }
64
}
65