Completed
Push — fopcreatefop ( a94315...34e835 )
by Dieter
16:06
created

MopDescription::checkAndCreateMopInformation()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 6
c 0
b 0
f 0
ccs 5
cts 5
cp 1
rs 9.4285
cc 2
eloc 3
nc 2
nop 0
crap 2
1
<?php
2
/**
3
 * amadeus-ws-client
4
 *
5
 * Copyright 2015 Amadeus Benelux NV
6
 *
7
 * Licensed under the Apache License, Version 2.0 (the "License");
8
 * you may not use this file except in compliance with the License.
9
 * You may obtain a copy of the License at
10
 *
11
 * http://www.apache.org/licenses/LICENSE-2.0
12
 *
13
 * Unless required by applicable law or agreed to in writing, software
14
 * distributed under the License is distributed on an "AS IS" BASIS,
15
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
 * See the License for the specific language governing permissions and
17
 * limitations under the License.
18
 *
19
 * @package Amadeus
20
 * @license https://opensource.org/licenses/Apache-2.0 Apache 2.0
21
 */
22
23
namespace Amadeus\Client\Struct\Fop;
24
25
use Amadeus\Client\RequestOptions\Fop\MopInfo;
26
use Amadeus\Client\Struct\WsMessageUtility;
27
28
/**
29
 * MopDescription
30
 *
31
 * @package Amadeus\Client\Struct\Fop
32
 * @author Dieter Devlieghere <[email protected]>
33
 */
34
class MopDescription extends WsMessageUtility
35
{
36
    /**
37
     * @var FopSequenceNumber
38
     */
39
    public $fopSequenceNumber;
40
    /**
41
     * @var FopMasterElementReference
42
     */
43
    public $fopMasterElementReference;
44
    /**
45
     * @var StakeholderPayerReference
46
     */
47
    public $stakeholderPayerReference;
48
    /**
49
     * @var MopDetails
50
     */
51
    public $mopDetails;
52
    /**
53
     * @var PaymentModule
54
     */
55
    public $paymentModule;
56
57
    /**
58
     * MopDescription constructor.
59
     *
60
     * @param MopInfo $options
61
     */
62 15
    public function __construct(MopInfo $options)
63
    {
64 15
        if (!empty($options->sequenceNr)) {
65 15
            $this->fopSequenceNumber = new FopSequenceNumber($options->sequenceNr);
66 15
        }
67
68 15
        $this->loadMopDetails($options);
69
70 15
        $this->loadPaymentModule($options);
71 15
    }
72
73
    /**
74
     * load Method of Payment Details
75
     *
76
     * @param MopInfo $options
77
     */
78 15
    protected function loadMopDetails(MopInfo $options)
79
    {
80 15
        $this->mopDetails = new MopDetails();
81
82 15
        if ($this->checkAnyNotEmpty($options->fopCode, $options->fopStatus)) {
83 15
            $this->mopDetails->fopPNRDetails = new FopPNRDetails(
84 15
                $options->fopCode,
85 15
                $options->fopStatus
86 15
            );
87 15
        }
88
89 15
        if (!empty($options->freeFlowText)) {
90 3
            $this->mopDetails->oldFopFreeflow = new OldFopFreeflow(
91 2
                $options->freeFlowText,
92 2
                $options->freeFlowEncoding
93 2
            );
94 2
        }
95
96 15 View Code Duplication
        if (!empty($options->supplementaryData)) {
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...
97 2
            $this->mopDetails->pnrSupplementaryData[] = new PnrSupplementaryData(
98 2
                DataAndSwitchMap::TYPE_DATA_INFORMATION,
99 2
                $options->supplementaryData
100 2
            );
101 2
        }
102 15 View Code Duplication
        if (!empty($options->supplementarySwitches)) {
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...
103 1
            $this->mopDetails->pnrSupplementaryData[] = new PnrSupplementaryData(
104 1
                DataAndSwitchMap::TYPE_SWITCH_INFORMATION,
105 1
                $options->supplementarySwitches
106 1
            );
107 1
        }
108 15
    }
109
110
    /**
111
     * Payment Module information
112
     *
113
     * @param MopInfo $options
114
     */
115 15
    protected function loadPaymentModule(MopInfo $options)
116
    {
117 15
        if ($this->checkAnyNotEmpty(
118 15
            $options->fopType,
119 15
            $options->payMerchant,
120 15
            $options->payments,
121 15
            $options->installmentsInfo,
122 15
            $options->mopPaymentType,
123 15
            $options->creditCardInfo,
124 15
            $options->fraudScreening,
125 15
            $options->payIds,
126 15
            $options->paySupData
127 15
        )) {
128 13
            $this->paymentModule = new PaymentModule($options->fopType);
129 13
            $this->paymentModule->loadPaymentData($options);
130
131 13
            $this->loadMopInformation($options);
132
133 13
            $this->loadPaymentSupplementaryData($options);
134 13
        }
135 15
    }
136
137
    /**
138
     * Load Supplementary data
139
     *
140
     * @param MopInfo $options
141
     */
142 13
    protected function loadPaymentSupplementaryData(MopInfo $options)
143
    {
144 13
        foreach ($options->paySupData as $paySupData) {
145 1
            $this->paymentModule->paymentSupplementaryData[] = new PaymentSupplementaryData(
146 1
                $paySupData->function,
147 1
                $paySupData->data
148 1
            );
149 13
        }
150 13
    }
151
152
    /**
153
     * Load MopInformation
154
     *
155
     * @param MopInfo $options
156
     */
157 13
    protected function loadMopInformation(MopInfo $options)
158
    {
159 13
        if (!empty($options->mopPaymentType)) {
160 10
            $this->checkAndCreateMopInformation();
161 10
            $this->paymentModule->mopInformation->fopInformation = new FopInformation($options->mopPaymentType);
162 10
        }
163
164 13
        if (!empty($options->creditCardInfo)) {
165 9
            $this->checkAndCreateMopInformation();
166 9
            $this->paymentModule->mopInformation->creditCardData = new CreditCardData($options->creditCardInfo);
167 9
            if ($this->checkAnyNotEmpty(
168 9
                $options->creditCardInfo->approvalCode,
169 9
                $options->creditCardInfo->threeDSecure
170 9
            )
171 9
            ) {
172 2
                $this->checkAndCreateMopDetailedData($options->fopType);
173 2
                $this->paymentModule->mopDetailedData->creditCardDetailedData = new CreditCardDetailedData(
174 2
                    $options->creditCardInfo->approvalCode,
175 2
                    $options->creditCardInfo->sourceOfApproval,
176 2
                    $options->creditCardInfo->threeDSecure
177 2
                );
178 2
            }
179 9
        }
180
181 13
        if (!empty($options->invoiceInfo)) {
182 1
            $this->checkAndCreateMopInformation();
183 1
            $this->paymentModule->mopInformation->invoiceDataGroup = new InvoiceDataGroup($options->invoiceInfo);
184 1
        }
185 13
    }
186
187
188
    /**
189
     * Create MopInformation node if needed
190
     */
191 10
    private function checkAndCreateMopInformation()
192
    {
193 10
        if (is_null($this->paymentModule->mopInformation)) {
194 10
            $this->paymentModule->mopInformation = new MopInformation();
195 10
        }
196 10
    }
197
198
    /**
199
     * Create MopDetailedData node if needed
200
     *
201
     * @param string $fopType
202
     */
203 2
    private function checkAndCreateMopDetailedData($fopType)
204
    {
205 2
        if (is_null($this->paymentModule->mopDetailedData)) {
206 2
            $this->paymentModule->mopDetailedData = new MopDetailedData($fopType);
207 2
        }
208 2
    }
209
}
210