CaptureActionSpec::it_executes()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 56
Code Lines 42

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 42
dl 0
loc 56
rs 9.248
c 0
b 0
f 0
cc 1
nc 1
nop 10

How to fix   Long Method    Many Parameters   

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:

Many Parameters

Methods with many parameters are not only hard to understand, but their parameters also often become inconsistent when you need more, or different data.

There are several approaches to avoid long parameter lists:

1
<?php
2
3
/*
4
 * This file has been created by developers from BitBag.
5
 * Feel free to contact us once you face any issues or want to start
6
 * another great project.
7
 * You can find more information about us on https://bitbag.shop and write us
8
 * an email on [email protected].
9
 */
10
11
declare(strict_types=1);
12
13
namespace spec\BitBag\SyliusMolliePlugin\Action;
14
15
use BitBag\SyliusMolliePlugin\Action\CaptureAction;
16
use BitBag\SyliusMolliePlugin\Client\MollieApiClient;
17
use Mollie\Api\Endpoints\PaymentEndpoint;
18
use Payum\Core\Action\ActionInterface;
19
use Payum\Core\ApiAwareInterface;
20
use Payum\Core\Bridge\Spl\ArrayObject;
21
use Payum\Core\GatewayAwareInterface;
22
use Payum\Core\GatewayInterface;
23
use Payum\Core\Payum;
24
use Payum\Core\Reply\HttpRedirect;
25
use Payum\Core\Request\Capture;
26
use Payum\Core\Security\GenericTokenFactory;
27
use Payum\Core\Security\GenericTokenFactoryAwareInterface;
28
use Payum\Core\Security\TokenInterface;
29
use PhpSpec\ObjectBehavior;
30
use Sylius\Component\Core\Model\PaymentInterface;
31
32
final class CaptureActionSpec extends ObjectBehavior
33
{
34
    function it_is_initializable(): void
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
35
    {
36
        $this->shouldHaveType(CaptureAction::class);
37
    }
38
39
    function it_implements_action_interface(): void
40
    {
41
        $this->shouldHaveType(ActionInterface::class);
42
    }
43
44
    function it_implements_generic_token_factory_aware(): void
45
    {
46
        $this->shouldHaveType(GenericTokenFactoryAwareInterface::class);
47
    }
48
49
    function it_implements_api_aware_interface(): void
50
    {
51
        $this->shouldHaveType(ApiAwareInterface::class);
52
    }
53
54
    function it_implements_gateway_aware_interface(): void
55
    {
56
        $this->shouldHaveType(GatewayAwareInterface::class);
57
    }
58
59
    function it_executes(
60
        Capture $request,
61
        ArrayObject $arrayObject,
62
        PaymentInterface $payment,
63
        TokenInterface $token,
64
        TokenInterface $notifyToken,
65
        Payum $payum,
66
        GenericTokenFactory $genericTokenFactory,
67
        GatewayInterface $gateway,
68
        MollieApiClient $mollieApiClient,
69
        PaymentEndpoint $paymentEndpoint
70
    ): void {
71
        $this->setGateway($gateway);
0 ignored issues
show
Bug introduced by
The method setGateway() does not exist on spec\BitBag\SyliusMollie...ction\CaptureActionSpec. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

71
        $this->/** @scrutinizer ignore-call */ 
72
               setGateway($gateway);
Loading history...
72
        $mollieApiClient->isRecurringSubscription()->willReturn(false);
73
        $this->setApi($mollieApiClient);
0 ignored issues
show
Bug introduced by
The method setApi() does not exist on spec\BitBag\SyliusMollie...ction\CaptureActionSpec. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

73
        $this->/** @scrutinizer ignore-call */ 
74
               setApi($mollieApiClient);
Loading history...
74
        $notifyToken->getTargetUrl()->willReturn('url');
75
        $notifyToken->getHash()->willReturn('test');
76
        $token->getTargetUrl()->willReturn('url');
77
        $token->getAfterUrl()->willReturn('url');
78
        $token->getGatewayName()->willReturn('test');
79
        $token->getDetails()->willReturn([]);
80
        $token->getHash()->willReturn('test');
81
        $genericTokenFactory->createNotifyToken('test', [])->willReturn($notifyToken);
0 ignored issues
show
Bug introduced by
The method willReturn() does not exist on Payum\Core\Security\TokenInterface. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

81
        $genericTokenFactory->createNotifyToken('test', [])->/** @scrutinizer ignore-call */ willReturn($notifyToken);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
82
        $genericTokenFactory->createRefundToken('test', [])->willReturn($notifyToken);
83
        $this->setGenericTokenFactory($genericTokenFactory);
0 ignored issues
show
Bug introduced by
The method setGenericTokenFactory() does not exist on spec\BitBag\SyliusMollie...ction\CaptureActionSpec. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

83
        $this->/** @scrutinizer ignore-call */ 
84
               setGenericTokenFactory($genericTokenFactory);
Loading history...
84
        $payum->getTokenFactory()->willReturn($genericTokenFactory);
0 ignored issues
show
Bug introduced by
The method willReturn() does not exist on Payum\Core\Security\GenericTokenFactoryInterface. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

84
        $payum->getTokenFactory()->/** @scrutinizer ignore-call */ willReturn($genericTokenFactory);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
85
        $arrayObject->toUnsafeArray()->willReturn([]);
86
        $request->getModel()->willReturn($arrayObject);
87
        $request->getFirstModel()->willReturn($payment);
88
        $request->getToken()->willReturn($token);
89
        $payment = \Mockery::mock('payment');
90
        $payment->id = 1;
0 ignored issues
show
Bug introduced by
Accessing id on the interface Mockery\MockInterface suggest that you code against a concrete implementation. How about adding an instanceof check?
Loading history...
Bug introduced by
Accessing id on the interface Mockery\LegacyMockInterface suggest that you code against a concrete implementation. How about adding an instanceof check?
Loading history...
91
        $payment->shouldReceive('getCheckoutUrl')->andReturn('https://thisisnotanemptyurl.com');
92
        $paymentEndpoint->create([
93
            'amount' => null,
94
            'description' => null,
95
            'redirectUrl' => 'url',
96
            'webhookUrl' => null,
97
            'metadata' => null,
98
        ])->willReturn($payment);
0 ignored issues
show
Bug introduced by
The method willReturn() does not exist on Mollie\Api\Resources\Payment. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

98
        ])->/** @scrutinizer ignore-call */ willReturn($payment);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
99
        $mollieApiClient->payments = $paymentEndpoint;
100
101
        $arrayObject->offsetGet('description')->shouldBeCalled();
102
        $arrayObject->offsetGet('webhookUrl')->shouldBeCalled();
103
        $arrayObject->offsetGet('amount')->shouldBeCalled();
104
        $arrayObject->offsetExists('subscription_mollie_id')->shouldBeCalled();
105
        $arrayObject->offsetExists('payment_mollie_id')->shouldBeCalled();
106
        $arrayObject->offsetExists('payment_mollie_id')->shouldBeCalled();
107
        $arrayObject->offsetGet('metadata')->shouldBeCalled();
108
        $arrayObject->offsetSet('metadata', ['refund_token' => 'test'])->shouldBeCalled();
0 ignored issues
show
Bug introduced by
Are you sure the usage of $arrayObject->offsetSet(...fund_token' => 'test')) targeting Payum\Core\Bridge\Spl\ArrayObject::offsetSet() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
109
        $arrayObject->offsetSet('payment_mollie_id', 1)->shouldBeCalled();
0 ignored issues
show
Bug introduced by
Are you sure the usage of $arrayObject->offsetSet('payment_mollie_id', 1) targeting Payum\Core\Bridge\Spl\ArrayObject::offsetSet() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
110
        $arrayObject->offsetSet('webhookUrl', 'url')->shouldBeCalled();
0 ignored issues
show
Bug introduced by
Are you sure the usage of $arrayObject->offsetSet('webhookUrl', 'url') targeting Payum\Core\Bridge\Spl\ArrayObject::offsetSet() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
111
112
        $this
113
            ->shouldThrow(HttpRedirect::class)
114
            ->during('execute', [$request])
115
        ;
116
    }
117
118
    function it_supports_only_capture_request_and_array_access(
119
        Capture $request,
120
        \ArrayAccess $arrayAccess
121
    ): void {
122
        $request->getModel()->willReturn($arrayAccess);
123
124
        $this->supports($request)->shouldReturn(true);
0 ignored issues
show
Bug introduced by
The method supports() does not exist on spec\BitBag\SyliusMollie...ction\CaptureActionSpec. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

124
        $this->/** @scrutinizer ignore-call */ 
125
               supports($request)->shouldReturn(true);
Loading history...
125
    }
126
}
127