CompletePurchaseRequestTest   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 85
Duplicated Lines 11.76 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 3
dl 10
loc 85
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 13 1
A testGetData() 10 10 1
A testSendData() 0 6 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
 * OKPAY driver for Omnipay PHP payment library.
4
 *
5
 * @link      https://github.com/hiqdev/omnipay-okpay
6
 * @package   omnipay-okpay
7
 * @license   MIT
8
 * @copyright Copyright (c) 2015-2017, HiQDev (http://hiqdev.com/)
9
 */
10
11
namespace Omnipay\OKPAY\Message;
12
13
use Omnipay\Tests\TestCase;
14
use Symfony\Component\HttpFoundation\Request as HttpRequest;
15
16
class CompletePurchaseRequestTest extends TestCase
17
{
18
    private $request;
19
20
    private $purse                  = 'OK426375940';
21
    private $description            = 'evo.ru-tld.ru: deposit valenp';
22
    private $transactionId          = 2705801;
23
    private $amount                 = 68.71;
24
    private $currency               = 'USD';
25
    private $timestamp              = '2014-03-22 19:54:58';
26
    private $testMode               = true;
27
28
    private $data = [
0 ignored issues
show
Comprehensibility introduced by
Consider using a different property name as you override a private property of the parent class.
Loading history...
29
        'ok_charset' => 'utf-8',
30
        'ok_receiver' => 'OK426375940',
31
        'ok_receiver_id' => '532844008',
32
        'ok_receiver_wallet' => 'OK426375940',
33
        'ok_receiver_email' => '[email protected]',
34
        'ok_txn_id' => 2705801,
35
        'ok_txn_kind' => 'payment_link',
36
        'ok_txn_payment_type' => 'instant',
37
        'ok_txn_payment_method' => 'OKB',
38
        'ok_txn_gross' => '68.71',
39
        'ok_txn_net' => '68.71',
40
        'ok_txn_fee' => '0.00',
41
        'ok_txn_currency' => 'USD',
42
        'ok_txn_datetime' => '2014-03-22 19:54:58',
43
        'ok_txn_status' => 'completed',
44
        'ok_invoice' => '',
45
        'ok_payer_status' => 'verified',
46
        'ok_payer_id' => '914126735',
47
        'ok_payer_reputation' => '0',
48
        'ok_payer_first_name' => 'Valentin',
49
        'ok_payer_last_name' => 'Perevalov',
50
        'ok_payer_email' => '[email protected]',
51
        'ok_payer_phone' => '7-9080858303',
52
        'ok_payer_country' => 'Russia',
53
        'ok_payer_city' => 'Chelyabinsk',
54
        'ok_payer_country_code' => 'RU',
55
        'ok_payer_state' => 'Chelyabinskaya obl.',
56
        'ok_payer_address_status' => 'confirmed',
57
        'ok_payer_street' => 'Truda 24-136',
58
        'ok_payer_zip' => '454006',
59
        'ok_payer_address_name' => 'Postal',
60
        'ok_items_count' => '1',
61
        'ok_item_1_name' => 'evo.ru-tld.ru: deposit valenp',
62
        'ok_item_1_type' => 'digital',
63
        'ok_item_1_quantity' => '1',
64
        'ok_item_1_gross' => '68.71',
65
        'ok_item_1_price' => '68.71',
66
        'ok_ipn_id' => '2011795',
67
    ];
68
69
    public function setUp()
70
    {
71
        parent::setUp();
72
73
        $httpRequest = new HttpRequest([], $this->data);
74
75
        $this->request = new NoVerificationCompletePurchaseRequest($this->getHttpClient(), $httpRequest);
76
        $this->request->initialize([
77
            'purse'     => $this->purse,
78
            'secret'    => $this->secret,
0 ignored issues
show
Bug introduced by
The property secret does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
79
            'testMode'  => $this->testMode,
80
        ]);
81
    }
82
83 View Code Duplication
    public function testGetData()
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...
84
    {
85
        $data = $this->request->getData();
86
87
        $this->assertSame($this->description,   $data['ok_item_1_name']);
88
        $this->assertSame($this->transactionId, $data['ok_txn_id']);
89
        $this->assertEquals($this->amount,      $data['ok_txn_gross']);
90
        $this->assertSame($this->timestamp,     $data['ok_txn_datetime']);
91
        $this->assertSame($this->purse,         $data['ok_receiver']);
92
    }
93
94
    public function testSendData()
95
    {
96
        //        $data = $this->request->getData();
97
        $response = $this->request->sendData($this->data);
98
        $this->assertInstanceOf('Omnipay\OKPAY\Message\CompletePurchaseResponse', $response);
99
    }
100
}
101
102
class NoVerificationCompletePurchaseRequest extends CompletePurchaseRequest
103
{
104
    public function getData()
105
    {
106
        return $this->httpRequest->request->all();
107
    }
108
}
109