PaymentMessageTest   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 118
Duplicated Lines 11.86 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 2
lcom 1
cbo 2
dl 14
loc 118
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A test() 0 11 1
A testEmptyFields() 14 14 1

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
namespace Xsolla\SDK\Tests\Unit\Webhook\Message;
4
5
use PHPUnit\Framework\TestCase;
6
use Xsolla\SDK\Webhook\Message\PaymentMessage;
7
8
/**
9
 * @group unit
10
 */
11
class PaymentMessageTest extends TestCase
12
{
13
    protected $request = [
14
        'notification_type' => 'payment',
15
        'purchase' => [
16
                'virtual_currency' => [
17
                        'name' => 'Coins',
18
                        'quantity' => 10,
19
                        'currency' => 'USD',
20
                        'amount' => 100,
21
                    ],
22
                'subscription' => [
23
                        'plan_id' => 1,
24
                        'subscription_id' => '10',
25
                        'product_id' => 'Demo Product',
26
                        'date_create' => '2014-09-22T19:25:25+04:00',
27
                        'currency' => 'USD',
28
                        'amount' => 9.99,
29
                    ],
30
                'checkout' => [
31
                        'currency' => 'USD',
32
                        'amount' => 50,
33
                    ],
34
                'virtual_items' => [
35
                        'items' => [
36
                                0 => [
37
                                        'sku' => 'test_item1',
38
                                        'amount' => 1,
39
                                    ],
40
                            ],
41
                        'currency' => 'USD',
42
                        'amount' => 50,
43
                    ],
44
                'total' => [
45
                        'currency' => 'USD',
46
                        'amount' => 200,
47
                    ],
48
                'promotions[0]' => [
49
                        'technical_name' => 'Demo Promotion',
50
                        'id' => '853',
51
                    ],
52
                'coupon' => [
53
                        'coupon_code' => 'ICvj45S4FUOyy',
54
                        'campaign_code' => '1507',
55
                    ],
56
        ],
57
        'user' => [
58
                'ip' => '127.0.0.1',
59
                'phone' => '18777976552',
60
                'email' => '[email protected]',
61
                'id' => '1234567',
62
                'name' => 'Xsolla User',
63
                'country' => 'US',
64
        ],
65
        'transaction' => [
66
                'id' => 1,
67
                'external_id' => 1,
68
                'payment_date' => '2014-09-24T20:38:16+04:00',
69
                'payment_method' => 1,
70
                'dry_run' => 1,
71
                'agreement' => 1,
72
        ],
73
        'payment_details' => [
74
                'payment' => [
75
                        'currency' => 'USD',
76
                        'amount' => 230,
77
                    ],
78
                'vat' => [
79
                        'currency' => 'USD',
80
                        'amount' => 0,
81
                    ],
82
                'payout_currency_rate' => 1,
83
                'payout' => [
84
                        'currency' => 'USD',
85
                        'amount' => 200,
86
                    ],
87
                'xsolla_fee' => [
88
                        'currency' => 'USD',
89
                        'amount' => 10,
90
                    ],
91
                'payment_method_fee' => [
92
                        'currency' => 'USD',
93
                        'amount' => 20,
94
                    ],
95
        ],
96
        'custom_parameters' => [
97
                'parameter1' => 'value1',
98
                'parameter2' => 'value2',
99
        ],
100
    ];
101
102
    public function test()
103
    {
104
        $message = new PaymentMessage($this->request);
105
        static::assertSame($this->request['purchase'], $message->getPurchase());
106
        static::assertSame($this->request['transaction'], $message->getTransaction());
107
        static::assertSame($this->request['transaction']['id'], $message->getPaymentId());
108
        static::assertSame($this->request['transaction']['external_id'], $message->getExternalPaymentId());
109
        static::assertSame($this->request['payment_details'], $message->getPaymentDetails());
110
        static::assertSame($this->request['custom_parameters'], $message->getCustomParameters());
111
        static::assertTrue($message->isDryRun());
112
    }
113
114 View Code Duplication
    public function testEmptyFields()
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...
115
    {
116
        $requestCopy = $this->request;
117
        unset(
118
            $requestCopy['custom_parameters'],
119
            $requestCopy['transaction']['dry_run'],
120
            $requestCopy['transaction']['external_id']
121
        );
122
        $message = new PaymentMessage($requestCopy);
123
124
        static::assertNull($message->getExternalPaymentId());
125
        static::assertSame([], $message->getCustomParameters());
126
        static::assertFalse($message->isDryRun());
127
    }
128
}
129