Completed
Push — master ( cd64b3...d9b048 )
by Claude
03:11
created

WebAuthorizeRequest::setDate()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 8
ccs 5
cts 5
cp 1
rs 9.4285
cc 2
eloc 4
nc 2
nop 1
crap 2
1
<?php
2
3
/*
4
 * WebMoney driver for the Omnipay PHP payment processing library
5
 *
6
 * @link      https://github.com/ck-developer/omnipay-payline
7
 * @package   omnipay-payline
8
 * @license   MIT
9
 * @copyright Copyright (c) 2016 Claude Khedhiri <[email protected]>
10
 */
11
12
namespace Omnipay\Payline\Message;
13
14
/**
15
 * Authorize Request.
16
 *
17
 * @method WebAuthorizeResponse send()
18
 */
19
class WebAuthorizeRequest extends AbstractRequest
20
{
21
    /**
22
     * @return bool
23
     */
24 6
    public function getMethod()
25
    {
26 6
        return 'doWebPayment';
27
    }
28
29
    /**
30
     * @return string
31
     */
32 3
    public function getDate()
33
    {
34 3
        return $this->getParameter('date');
35
    }
36
37
    /**
38
     * @param string $date
39
     *
40
     * @return $this
41
     */
42 3
    public function setDate($date)
43
    {
44 3
        if ($date instanceof \DateTime) {
45 3
            $date = $date->format('d/m/Y H:i');
46 3
        }
47
48 3
        return $this->setParameter('date', $date);
49
    }
50
51 3
    public function getData()
52
    {
53 3
        $data['payment'] = array(
0 ignored issues
show
Coding Style Comprehensibility introduced by
$data was never initialized. Although not strictly required by PHP, it is generally a good practice to add $data = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
54 3
            'amount' => $this->getAmountInteger(),
55 3
            'currency' => $this->getCurrencyNumeric(),
56 3
            'action' => 100,
57 3
            'mode' => 'CPT',
58
        );
59
60 3
        if ($this->getContractNumber()) {
61 3
            $data['payment']['contractNumber'] = $this->getContractNumber();
62 3
        }
63
64 3
        $data['order'] = array(
65 3
            'ref' => $this->getTransactionReference(),
66 3
            'amount' => $this->getAmountInteger(),
67 3
            'currency' => $this->getCurrencyNumeric(),
68
        );
69
70 3
        $data['order']['date'] = $this->getDate();
71
72 3
        $data['returnURL'] = $this->getReturnUrl();
73 3
        $data['cancelURL'] = $this->getCancelUrl();
74 3
        $data['notificationURL'] = $this->getNotifyUrl();
75
76 3
        return array_replace_recursive($this->getBaseData(), $data);
77
    }
78
79
    /**
80
     * @param \stdClass $data
81
     *
82
     * @return WebAuthorizeResponse
83
     */
84 3
    protected function createResponse($data)
85
    {
86 3
        return $this->response = new WebAuthorizeResponse($this, $data);
87
    }
88
}
89