Completed
Push — master ( 620307...8ff95d )
by Dominik
03:16
created

XmlAuthorizationRequest::getData()   B

Complexity

Conditions 3
Paths 3

Size

Total Lines 26
Code Lines 16

Duplication

Lines 7
Ratio 26.92 %

Importance

Changes 0
Metric Value
dl 7
loc 26
rs 8.8571
c 0
b 0
f 0
cc 3
eloc 16
nc 3
nop 0
1
<?php
2
/**
3
 * w-vision
4
 *
5
 * LICENSE
6
 *
7
 * This source file is subject to the GNU General Public License version 3 (GPLv3)
8
 * For the full copyright and license information, please view the LICENSE.md and gpl-3.0.txt
9
 * files that are distributed with this source code.
10
 *
11
 * @copyright  Copyright (c) 2016 Woche-Pass AG (http://www.w-vision.ch)
12
 * @license    GNU General Public License version 3 (GPLv3)
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 = [
28
        'reqtype',
29
        'uppCustomerIpAddress'
30
    ];
31
32
    /**
33
     * @var string
34
     */
35
    protected $apiEndpoint = 'XML_authorize.jsp';
36
37
    /**
38
     * @var string
39
     */
40
    protected $serviceName = 'authorizationService';
41
42
    /**
43
     * @var int
44
     */
45
    protected $serviceVersion = 3;
46
47
    /**
48
     * @return array
49
     */
50
    public function getData()
0 ignored issues
show
Coding Style introduced by
getData uses the super-global variable $_SERVER which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
51
    {
52
        $this->validate('merchantId', 'transactionId', 'sign', 'card');
53
54
        $data = array(
55
            'amount'     => $this->getAmountInteger(),
56
            'currency'   => $this->getCurrency(),
57
            'aliasCC'    => $this->getCard()->getNumber(),
58
            'expm'       => $this->getCard()->getExpiryMonth(),
59
            'expy'       => $this->getCard()->getExpiryDate('y'),
60
            'uppCustomerDetails' => [
61
                'uppCustomerIpAddress' => $_SERVER['REMOTE_ADDR']
62
            ],
63
            'useAlias' => 'no'
64
        );
65
66 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...
67
            $value = $this->getParameter($param);
68
69
            if ($value) {
70
                $data[$param] = $value;
71
            }
72
        }
73
74
        return $data;
75
    }
76
77
    /**
78
     * @param $data
79
     * @return XmlAuthorizationResponse
80
     */
81
    protected function createResponse($data)
82
    {
83
        return $this->response = new XmlAuthorizationResponse($this, $data);
84
    }
85
}
86