Passed
Push — master ( da73f3...744736 )
by
unknown
03:19 queued 12s
created

Customer::getCustomerGender()   B

Complexity

Conditions 8
Paths 15

Size

Total Lines 26
Code Lines 19

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 8
eloc 19
nc 15
nop 0
dl 0
loc 26
rs 8.4444
c 0
b 0
f 0
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\Helper;
28
29
use Magento\Quote\Model\Quote\Address as QuoteAddress;
0 ignored issues
show
Bug introduced by
The type Magento\Quote\Model\Quote\Address was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
30
use Magento\Sales\Model\Order\Address as OrderAddress;
0 ignored issues
show
Bug introduced by
The type Magento\Sales\Model\Order\Address was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
31
use Magento\Directory\Model\Region;
0 ignored issues
show
Bug introduced by
The type Magento\Directory\Model\Region was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
32
33
/**
34
 * Helper class for everything that has to do with customers
35
 */
36
class Customer extends \Payone\Core\Helper\Base
37
{
38
    /**
39
     * Checkout session
40
     *
41
     * @var \Magento\Checkout\Model\Session
0 ignored issues
show
Bug introduced by
The type Magento\Checkout\Model\Session was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
42
     */
43
    protected $checkoutSession;
44
45
    /**
46
     * Region factory
47
     *
48
     * @var \Magento\Directory\Model\RegionFactory
0 ignored issues
show
Bug introduced by
The type Magento\Directory\Model\RegionFactory was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
49
     */
50
    protected $regionFactory;
51
52
    /**
53
     * Constructor
54
     *
55
     * @param \Magento\Framework\App\Helper\Context      $context
56
     * @param \Magento\Store\Model\StoreManagerInterface $storeManager
57
     * @param \Payone\Core\Helper\Shop                   $shopHelper
58
     * @param \Magento\Checkout\Model\Session            $checkoutSession
59
     * @param \Magento\Directory\Model\RegionFactory     $regionFactory
60
     */
61
    public function __construct(
62
        \Magento\Framework\App\Helper\Context $context,
0 ignored issues
show
Bug introduced by
The type Magento\Framework\App\Helper\Context was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
63
        \Magento\Store\Model\StoreManagerInterface $storeManager,
0 ignored issues
show
Bug introduced by
The type Magento\Store\Model\StoreManagerInterface was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
64
        \Payone\Core\Helper\Shop $shopHelper,
65
        \Magento\Checkout\Model\Session $checkoutSession,
66
        \Magento\Directory\Model\RegionFactory $regionFactory
67
    ) {
68
        parent::__construct($context, $storeManager, $shopHelper);
69
        $this->checkoutSession = $checkoutSession;
70
        $this->regionFactory = $regionFactory;
71
    }
72
73
    /**
74
     * Get customer gender
75
     *
76
     * @return string|null
77
     */
78
    public function getCustomerGender()
79
    {
80
        $sGender = null;
81
        if (!empty($this->checkoutSession->getPayoneGuestGender())) {
82
            $sGender = $this->checkoutSession->getPayoneGuestGender();
83
        } else {
84
            $oCustomer = $this->checkoutSession->getQuote()->getCustomer();
85
            if ($oCustomer && $oCustomer->getGender()) {
86
                $sGender = $oCustomer->getGender();
87
            }
88
        }
89
90
        if (!empty($sGender)) {
91
            switch ($sGender) {
92
                case 1:
93
                    $sGender = "m";
94
                    break;
95
                case 2:
96
                    $sGender = "f";
97
                    break;
98
                case 3:
99
                    $sGender = "d";
100
                    break;
101
            }
102
        }
103
        return $sGender;
104
    }
105
106
    /**
107
     * Get customer birthday
108
     *
109
     * @return string|null
110
     */
111
    public function getCustomerBirthday()
112
    {
113
        $sBirthday = null;
114
        if (!empty($this->checkoutSession->getPayoneGuestDateofbirth())) {
115
            $sBirthday = $this->checkoutSession->getPayoneGuestDateofbirth();
116
        } else {
117
            $oCustomer = $this->checkoutSession->getQuote()->getCustomer();
118
            if ($oCustomer && $oCustomer->getDob()) {
119
                $sBirthday = $oCustomer->getDob();
120
            }
121
        }
122
123
        if (!empty($sBirthday)) {
124
            $sBirthday = date('Ymd', strtotime($sBirthday));
125
        }
126
        return $sBirthday;
127
    }
128
129
    /**
130
     * Get the region object for the state and country given by PayPal
131
     *
132
     * @param  string $sCountry
133
     * @param  string $sState
134
     * @return Region|bool
135
     */
136
    public function getRegion($sCountry, $sState)
137
    {
138
        $oRegion = false;
139
        if (!empty($sState) && $sState != 'Empty') {
140
            $oRegion = $this->regionFactory->create();
141
            $oRegion->loadByCode(
142
                $sState,
143
                $sCountry
144
            );
145
            if (!$oRegion->getId()) {// Region not found
146
                $oRegion = false;
147
            }
148
        }
149
        return $oRegion;
150
    }
151
152
    /**
153
     * Get region code by address
154
     *
155
     * @param  QuoteAddress|OrderAddress $oAddress
156
     * @return string
157
     */
158
    public function getRegionCode($oAddress)
159
    {
160
        $sRegionCode = $oAddress->getRegionCode();
161
        if (strlen($sRegionCode) != 2) {
162
            $oRegion = $this->regionFactory->create();
163
            $oRegion->loadByName($sRegionCode, $oAddress->getCountryId());
164
            if ($oRegion->getId()) {
165
                $sRegionCode = $oRegion->getCode();
166
            }
167
        }
168
        return $sRegionCode;
169
    }
170
171
    /**
172
     * Map magento gender to PAYONE gender parameter
173
     *
174
     * @param  int $iGender
175
     * @return string
176
     */
177
    public function getGenderParameter($iGender)
178
    {
179
        $sGender = '';
180
        if ($iGender == '1') {
181
            $sGender = 'm';
182
        } elseif ($iGender == '2') {
183
            $sGender = 'f';
184
        }
185
        return $sGender;
186
    }
187
188
    /**
189
     * Map magento gender to PAYONE salutation parameter
190
     *
191
     * @param  int $iGender
192
     * @return string
193
     */
194
    public function getSalutationParameter($iGender)
195
    {
196
        $sSalutation = '';
197
        if ($iGender == '1') {
198
            $sSalutation = (string)__('Mr');
0 ignored issues
show
Bug introduced by
The function __ was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

198
            $sSalutation = (string)/** @scrutinizer ignore-call */ __('Mr');
Loading history...
199
        } elseif ($iGender == '2') {
200
            $sSalutation = (string)__('Mrs');
201
        }
202
        return $sSalutation;
203
    }
204
}
205