Completed
Push — master ( c76d1a...b80522 )
by Dmitry
13:01
created

PurchaseRequest   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 51
Duplicated Lines 52.94 %

Coupling/Cohesion

Components 2
Dependencies 2

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 5
lcom 2
cbo 2
dl 27
loc 51
ccs 0
cts 40
cp 0
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getData() 0 14 1
A generateSignature() 15 15 2
A getCustomFields() 12 12 1
A sendData() 0 4 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
 * RoboKassa driver for Omnipay PHP payment library.
4
 *
5
 * @link      https://github.com/hiqdev/omnipay-robokassa
6
 * @package   omnipay-robokassa
7
 * @license   MIT
8
 * @copyright Copyright (c) 2015-2017, HiQDev (http://hiqdev.com/)
9
 */
10
11
namespace Omnipay\RoboKassa\Message;
12
13
class PurchaseRequest extends AbstractRequest
14
{
15
    public function getData()
16
    {
17
        $this->validate(
18
            'purse', 'amount', 'currency', 'description'
19
        );
20
21
        return [
22
            'MrchLogin' => $this->getPurse(),
23
            'OutSum' => $this->getAmount(),
24
            'Desc' => $this->getDescription(),
25
            'IncCurrLabel' => $this->getCurrency(),
26
            'SignatureValue' => $this->generateSignature(),
27
        ] + $this->getCustomFields();
28
    }
29
30 View Code Duplication
    public function generateSignature()
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...
31
    {
32
        $params = [
33
            $this->getPurse(),
34
            $this->getAmount(),
35
            '',
36
            $this->getSecretKey()
37
        ];
38
39
        foreach ($this->getCustomFields() as $field => $value) {
40
            $params[] = "$field=$value";
41
        }
42
43
        return md5(implode(':', $params));
44
    }
45
46 View Code Duplication
    public function getCustomFields()
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...
47
    {
48
        $fields = array_filter([
49
            'Shp_TransactionId' => $this->getTransactionId(),
50
            'Shp_Client' => $this->getClient(),
51
            'Shp_Currency' => $this->getCurrency()
52
        ]);
53
54
        ksort($fields);
55
56
        return $fields;
57
    }
58
59
    public function sendData($data)
60
    {
61
        return $this->response = new PurchaseResponse($this, $data);
62
    }
63
}
64