Completed
Pull Request — master (#7)
by
unknown
10:19
created

XmlAuthorizationRequest   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 71
Duplicated Lines 9.86 %

Coupling/Cohesion

Components 2
Dependencies 3

Test Coverage

Coverage 78.95%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
lcom 2
cbo 3
dl 7
loc 71
ccs 15
cts 19
cp 0.7895
rs 10
c 1
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A createResponse() 0 4 1
A getData() 7 23 3
A setUseAlias() 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
 * w-vision
4
 *
5
 * LICENSE
6
 *
7
 * This source file is subject to the MIT License
8
 * For the full copyright and license information, please view the LICENSE.md
9
 * file that are distributed with this source code.
10
 *
11
 * @copyright  Copyright (c) 2016 Woche-Pass AG (http://www.w-vision.ch)
12
 * @license    MIT License
13
 */
14
15
namespace Omnipay\Datatrans\Message;
16
17
/**
18
 * Class XmlSettlementRequest
19
 *
20
 * @package Omnipay\Datatrans\Message
21
 */
22
class XmlAuthorizationRequest extends XmlRequest
23
{
24
    /**
25
     * @var array
26
     */
27
    protected $optionalParameters = array(
28
        'reqtype',
29
        'uppCustomerIpAddress',
30
        'useAlias'
31
    );
32
33
    /**
34
     * @var string
35
     */
36
    protected $apiEndpoint = 'XML_authorize.jsp';
37
38
    /**
39
     * @var string
40
     */
41
    protected $serviceName = 'authorizationService';
42
43
    /**
44
     * @var int
45
     */
46
    protected $serviceVersion = 3;
47
48
    /**
49
     * @return array
50
     */
51 2
    public function getData()
52
    {
53 2
        $this->validate('merchantId', 'transactionId', 'sign', 'card');
54
55
        $data = array(
56 2
            'amount'     => $this->getAmountInteger(),
57 2
            'currency'   => $this->getCurrency(),
58 2
            'aliasCC'    => $this->getCard()->getNumber(),
59 2
            'expm'       => $this->getCard()->getExpiryMonth(),
60 2
            'expy'       => $this->getCard()->getExpiryDate('y'),
61
            'useAlias'   => 'no'
62 2
        );
63
64 2 View Code Duplication
        foreach ($this->optionalParameters as $param) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
65 2
            $value = $this->getParameter($param);
66
67 2
            if ($value) {
68
                $data[$param] = $value;
69
            }
70 2
        }
71
72 2
        return $data;
73
    }
74
75
    /**
76
     * @param $data
77
     * @return XmlAuthorizationResponse
78
     */
79 2
    protected function createResponse($data)
80
    {
81 2
        return $this->response = new XmlAuthorizationResponse($this, $data);
82
    }
83
84
    /**
85
     * @param $value
86
     * @return \Omnipay\Common\Message\AbstractRequest
87
     */
88
    public function setUseAlias($value)
89
    {
90
        return $this->setParameter('useAlias', $value);
91
    }
92
}
93