SafeInvoice::getFormattedBirthday()   B
last analyzed

Complexity

Conditions 5
Paths 3

Size

Total Lines 16
Code Lines 11

Duplication

Lines 16
Ratio 100 %

Importance

Changes 0
Metric Value
dl 16
loc 16
c 0
b 0
f 0
rs 8.8571
cc 5
eloc 11
nc 3
nop 1
1
<?php
2
3
/**
4
 * PAYONE Magento 2 Connector is free software: you can redistribute it and/or modify
5
 * it under the terms of the GNU Lesser General Public License as published by
6
 * the Free Software Foundation, either version 3 of the License, or
7
 * (at your option) any later version.
8
 *
9
 * PAYONE Magento 2 Connector is distributed in the hope that it will be useful,
10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
 * GNU Lesser General Public License for more details.
13
 *
14
 * You should have received a copy of the GNU Lesser General Public License
15
 * along with PAYONE Magento 2 Connector. If not, see <http://www.gnu.org/licenses/>.
16
 *
17
 * PHP version 5
18
 *
19
 * @category  Payone
20
 * @package   Payone_Magento2_Plugin
21
 * @author    FATCHIP GmbH <[email protected]>
22
 * @copyright 2003 - 2016 Payone GmbH
23
 * @license   <http://www.gnu.org/licenses/> GNU Lesser General Public License
24
 * @link      http://www.payone.de
25
 */
26
27
namespace Payone\Core\Model\Methods;
28
29
use Payone\Core\Model\PayoneConfig;
30
use Magento\Sales\Model\Order;
31
use Magento\Framework\DataObject;
32
33
/**
34
 * Model for safe invoice payment method
35
 */
36
class SafeInvoice extends PayoneMethod
37
{
38
    /**
39
     * Payment method code
40
     *
41
     * @var string
42
     */
43
    protected $_code = PayoneConfig::METHOD_SAFE_INVOICE;
44
45
    /**
46
     * Clearingtype for PAYONE authorization request
47
     *
48
     * @var string
49
     */
50
    protected $sClearingtype = 'rec';
51
52
    /**
53
     * Determines if the invoice information has to be added
54
     * to the authorization-request
55
     *
56
     * @var bool
57
     */
58
    protected $blNeedsProductInfo = true;
59
60
    /**
61
     * Return parameters specific to this payment type
62
     *
63
     * @param  Order $oOrder
64
     * @return array
65
     */
66
    public function getPaymentSpecificParameters(Order $oOrder)
67
    {
68
        $aParams = ['clearingsubtype' => 'POV'];
69
70
        $sDob = $this->getInfoInstance()->getAdditionalInformation('dob');
71
        if ($sDob) {
72
            $aParams['birthday'] = $sDob;
73
        }
74
        return $aParams;
75
    }
76
77
    /**
78
     * Returns formatted birthday if possible
79
     *
80
     * @param  DataObject $data
81
     * @return string|false
82
     */
83 View Code Duplication
    protected function getFormattedBirthday(DataObject $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...
84
    {
85
        $sFormattedDob = false;
86
87
        $sBirthday = $this->toolkitHelper->getAdditionalDataEntry($data, 'birthday');
88
        $sBirthmonth = $this->toolkitHelper->getAdditionalDataEntry($data, 'birthmonth');
89
        $sBirthyear = $this->toolkitHelper->getAdditionalDataEntry($data, 'birthyear');
90
        if ($sBirthday && $sBirthmonth && $sBirthyear) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $sBirthday of type string|null is loosely compared to true; this is ambiguous if the string can be empty. You might want to explicitly use !== null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
Bug Best Practice introduced by
The expression $sBirthmonth of type string|null is loosely compared to true; this is ambiguous if the string can be empty. You might want to explicitly use !== null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
Bug Best Practice introduced by
The expression $sBirthyear of type string|null is loosely compared to true; this is ambiguous if the string can be empty. You might want to explicitly use !== null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
91
            $sDob = $sBirthyear.'-'.$sBirthmonth.'-'.$sBirthday;
92
            $iDobTime = strtotime($sDob);
93
            if ($iDobTime !== false) {
94
                $sFormattedDob = date('Ymd', $iDobTime);
95
            }
96
        }
97
        return $sFormattedDob;
98
    }
99
100
    /**
101
     * Add the checkout-form-data to the checkout session
102
     *
103
     * @param  DataObject $data
104
     * @return $this
105
     */
106
    public function assignData(DataObject $data)
107
    {
108
        parent::assignData($data);
109
110
        $sFormattedDob = $this->getFormattedBirthday($data);
111
        if ($sFormattedDob !== false) {
112
            $oInfoInstance = $this->getInfoInstance();
113
            $oInfoInstance->setAdditionalInformation('dob', $sFormattedDob);
114
        }
115
116
        return $this;
117
    }
118
}
119