Completed
Push — master ( 9d1e2d...087d19 )
by Joao
02:29
created

WSConfPreAuthResponse   A

Complexity

Total Complexity 15

Size/Duplication

Total Lines 57
Duplicated Lines 14.04 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 3
Bugs 0 Features 1
Metric Value
wmc 15
c 3
b 0
f 1
lcom 1
cbo 1
dl 8
loc 57
rs 10

8 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 8 8 2
A isSuccessful() 0 4 1
A getCode() 0 4 2
A getMessage() 0 4 2
A getTransactionReference() 0 6 2
A getNumAutor() 0 6 2
A getCard() 0 6 2
A getAmount() 0 6 2

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 Omnipay\Komerci\Message;
4
5
use Omnipay\Common\Message\AbstractResponse;
6
use Omnipay\Common\Message\RequestInterface;
7
8
/**
9
 * Komerci Authorize Response
10
 */
11
class WSConfPreAuthResponse extends AbstractResponse
12
{
13
14 View Code Duplication
    public function __construct(RequestInterface $request, $data)
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...
15
    {
16
        $this->request = $request;
17
18
        foreach ($data->root->children() as $childName => $childValue) {
19
            $this->data[strtoupper($childName)] = (string) $childValue;
20
        }
21
    }
22
23
    public function isSuccessful()
24
    {
25
        return ($this->getCode() == '0');
26
    }
27
28
    public function getCode()
29
    {
30
        return isset($this->data['CODRET']) ? $this->data['CODRET'] : '99';
31
    }
32
33
    public function getMessage()
34
    {
35
        return isset($this->data['MSGRET']) ? $this->data['MSGRET'] : 'Unknown';
36
    }
37
38
    public function getTransactionReference()
39
    {
40
        $result = [];
41
        preg_match('/@COMPR:(?<res>\d*?)\+*?V/', $this->getMessage(), $result);
42
        return isset($result['res']) ? $result['res'] : '';
43
    }
44
45
    public function getNumAutor()
46
    {
47
        $result = [];
48
        preg_match('/@AUTORIZACAO\+EMISSOR:\+(?<res>\d*?)\+*?@/', $this->getMessage(), $result);
49
        return isset($result['res']) ? $result['res'] : '';
50
    }
51
52
    public function getCard()
53
    {
54
        $result = [];
55
        preg_match('/@CARTAO:\+(?<res>\w*?)\+*?@/', $this->getMessage(), $result);
56
        return isset($result['res']) ? $result['res'] : '';
57
    }
58
59
    public function getAmount()
60
    {
61
        $result = [];
62
        preg_match('/\+VALOR:\+*?(?<int>[\d\.]*?),(?<dec>\d*?)@/', $this->getMessage(), $result);
63
        return isset($result['int']) ? floatval(str_replace('.', '', $result['int']) . '.' . $result['dec']) : null;
64
    }
65
66
67
}
68