Passed
Push — master ( 2bdea1...160902 )
by Mikołaj
05:53
created

CaptureActionSpec::it_executes()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 56
Code Lines 42

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 56
rs 9.7251
c 0
b 0
f 0
cc 1
eloc 42
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 Payum\Core\Action\ActionInterface;
18
use Payum\Core\ApiAwareInterface;
19
use Payum\Core\Bridge\Spl\ArrayObject;
20
use Payum\Core\GatewayAwareInterface;
21
use Payum\Core\GatewayInterface;
22
use Payum\Core\Payum;
23
use Payum\Core\Reply\HttpPostRedirect;
24
use Payum\Core\Request\Capture;
25
use Payum\Core\Security\GenericTokenFactory;
26
use Payum\Core\Security\GenericTokenFactoryAwareInterface;
27
use Payum\Core\Security\TokenInterface;
28
use PhpSpec\ObjectBehavior;
29
use Sylius\Component\Core\Model\PaymentInterface;
30
31
final class CaptureActionSpec extends ObjectBehavior
32
{
33
    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...
34
    {
35
        $this->shouldHaveType(CaptureAction::class);
36
    }
37
38
    function it_implements_action_interface(): void
39
    {
40
        $this->shouldHaveType(ActionInterface::class);
41
    }
42
43
    function it_implements_generic_token_factory_aware(): void
44
    {
45
        $this->shouldHaveType(GenericTokenFactoryAwareInterface::class);
46
    }
47
48
    function it_implements_api_aware_interface(): void
49
    {
50
        $this->shouldHaveType(ApiAwareInterface::class);
51
    }
52
53
    function it_implements_gateway_aware_interface(): void
54
    {
55
        $this->shouldHaveType(GatewayAwareInterface::class);
56
    }
57
58
    function it_executes(
59
        Capture $request,
60
        ArrayObject $arrayObject,
61
        PaymentInterface $payment,
62
        TokenInterface $token,
63
        TokenInterface $notifyToken,
64
        Payum $payum,
65
        GenericTokenFactory $genericTokenFactory,
66
        GatewayInterface $gateway,
67
        MollieApiClient $mollieApiClient,
68
        \Mollie_API_Resource_Base $mollieApiResourceBase
69
    ): void {
70
        $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

70
        $this->/** @scrutinizer ignore-call */ 
71
               setGateway($gateway);
Loading history...
71
        $mollieApiClient->isRecurringSubscription()->willReturn(false);
72
        $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

72
        $this->/** @scrutinizer ignore-call */ 
73
               setApi($mollieApiClient);
Loading history...
73
        $notifyToken->getTargetUrl()->willReturn('url');
74
        $notifyToken->getHash()->willReturn('test');
75
        $token->getTargetUrl()->willReturn('url');
76
        $token->getAfterUrl()->willReturn('url');
77
        $token->getGatewayName()->willReturn('test');
78
        $token->getDetails()->willReturn([]);
79
        $token->getHash()->willReturn('test');
80
        $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

80
        $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...
81
        $genericTokenFactory->createRefundToken('test', [])->willReturn($notifyToken);
82
        $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

82
        $this->/** @scrutinizer ignore-call */ 
83
               setGenericTokenFactory($genericTokenFactory);
Loading history...
83
        $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

83
        $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...
84
        $arrayObject->toUnsafeArray()->willReturn([]);
85
        $request->getModel()->willReturn($arrayObject);
86
        $request->getFirstModel()->willReturn($payment);
87
        $request->getToken()->willReturn($token);
88
        $payment = \Mockery::mock('payment');
89
        $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...
90
        $payment->shouldReceive('getPaymentUrl')->andReturn('');
91
        $mollieApiResourceBase->create([
92
            'amount' => null,
93
            'description' => null,
94
            'redirectUrl' => 'url',
95
            'webhookUrl' => null,
96
            'metadata' => null,
97
        ])->willReturn($payment);
98
        $mollieApiClient->payments = $mollieApiResourceBase;
0 ignored issues
show
Documentation Bug introduced by
$mollieApiResourceBase is of type Mollie_API_Resource_Base, but the property $payments was declared to be of type Mollie_API_Resource_Payments. Are you sure that you always receive this specific sub-class here, or does it make sense to add an instanceof check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a given class or a super-class is assigned to a property that is type hinted more strictly.

Either this assignment is in error or an instanceof check should be added for that assignment.

class Alien {}

class Dalek extends Alien {}

class Plot
{
    /** @var  Dalek */
    public $villain;
}

$alien = new Alien();
$plot = new Plot();
if ($alien instanceof Dalek) {
    $plot->villain = $alien;
}
Loading history...
99
100
        $arrayObject->offsetGet('description')->shouldBeCalled();
101
        $arrayObject->offsetGet('webhookUrl')->shouldBeCalled();
102
        $arrayObject->offsetGet('amount')->shouldBeCalled();
103
        $arrayObject->offsetExists('subscription_mollie_id')->shouldBeCalled();
104
        $arrayObject->offsetExists('payment_mollie_id')->shouldBeCalled();
105
        $arrayObject->offsetExists('payment_mollie_id')->shouldBeCalled();
106
        $arrayObject->offsetGet('metadata')->shouldBeCalled();
107
        $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...
108
        $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...
109
        $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...
110
111
        $this
112
            ->shouldThrow(HttpPostRedirect::class)
113
            ->during('execute', [$request])
114
        ;
115
    }
116
117
    function it_supports_only_capture_request_and_array_access(
118
        Capture $request,
119
        \ArrayAccess $arrayAccess
120
    ): void {
121
        $request->getModel()->willReturn($arrayAccess);
122
123
        $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

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