Completed
Push — fopcreatefop ( 43117b...97f2d4 )
by Dieter
06:06
created

MopDescription::loadPaymentModule()   C

Complexity

Conditions 8
Paths 65

Size

Total Lines 38
Code Lines 22

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 38
c 0
b 0
f 0
rs 5.3846
cc 8
eloc 22
nc 65
nop 1
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
    public function __construct(MopInfo $options)
63
    {
64
        if (!empty($options->sequenceNr)) {
65
            $this->fopSequenceNumber = new FopSequenceNumber($options->sequenceNr);
66
        }
67
68
        $this->loadMopDetails($options);
69
70
        $this->loadPaymentModule($options);
71
    }
72
73
    /**
74
     * load Method of Payment Details
75
     *
76
     * @param MopInfo $options
77
     */
78
    protected function loadMopDetails(MopInfo $options)
79
    {
80
        $this->mopDetails = new MopDetails();
81
82
        if ($this->checkAnyNotEmpty($options->fopCode, $options->fopStatus)) {
83
            $this->mopDetails->fopPNRDetails = new FopPNRDetails(
84
                $options->fopCode,
85
                $options->fopStatus
86
            );
87
        }
88
89
        if (!empty($options->freeFlowText)) {
90
            $this->mopDetails->oldFopFreeflow = new OldFopFreeflow(
91
                $options->freeFlowText,
92
                $options->freeFlowEncoding
93
            );
94
        }
95
96
        if (!empty($options->supplementaryData)) {
97
            $this->mopDetails->pnrSupplementaryData = new PnrSupplementaryData(
0 ignored issues
show
Documentation Bug introduced by
It seems like new \Amadeus\Client\Stru...ons->supplementaryData) of type object<Amadeus\Client\St...p\PnrSupplementaryData> is incompatible with the declared type array<integer,object<Ama...\PnrSupplementaryData>> of property $pnrSupplementaryData.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
98
                DataAndSwitchMap::TYPE_DATA_INFORMATION,
99
                $options->supplementaryData
100
            );
101
        }
102
        if (!empty($options->supplementarySwitches)) {
103
            $this->mopDetails->pnrSupplementaryData = new PnrSupplementaryData(
0 ignored issues
show
Documentation Bug introduced by
It seems like new \Amadeus\Client\Stru...>supplementarySwitches) of type object<Amadeus\Client\St...p\PnrSupplementaryData> is incompatible with the declared type array<integer,object<Ama...\PnrSupplementaryData>> of property $pnrSupplementaryData.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
104
                DataAndSwitchMap::TYPE_SWITCH_INFORMATION,
105
                $options->supplementarySwitches
106
            );
107
        }
108
    }
109
110
    /**
111
     * Payment Module information
112
     *
113
     * @param MopInfo $options
114
     */
115
    protected function loadPaymentModule(MopInfo $options)
116
    {
117
        if ($this->checkAnyNotEmpty($options->fopType, $options->payMerchant, $options->payments, $options->installmentsInfo, $options->mopPaymentType, $options->creditCardInfo, $options->fraudScreening)) {
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 206 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
118
            $this->paymentModule = new PaymentModule($options->fopType);
119
120
            if (!empty($options->payMerchant)) {
121
                $this->checkAndCreatePaymentData();
122
                $this->paymentModule->paymentData->merchantInformation = new MerchantInformation($options->payMerchant);
123
            }
124
125
            if (!empty($options->payments)) {
126
                $this->checkAndCreatePaymentData();
127
                $this->paymentModule->paymentData->monetaryInformation[] = new MonetaryInformation($options->payments);
128
            }
129
130
            if (!empty($options->installmentsInfo)) {
131
                $this->checkAndCreatePaymentData();
132
                $this->paymentModule->paymentData->extendedPaymentInfo = new ExtendedPaymentInfo(
133
                    $options->installmentsInfo
134
                );
135
            }
136
137
            if (!empty($options->fraudScreening)) {
138
                $this->checkAndCreatePaymentData();
139
                $this->paymentModule->paymentData->fraudScreeningData = new FraudScreeningData($options->fraudScreening);
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 121 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
140
            }
141
142
            if (!empty($options->mopPaymentType)) {
143
                $this->checkAndCreateMopInformation();
144
                $this->paymentModule->mopInformation->fopInformation = new FopInformation($options->mopPaymentType);
145
            }
146
147
            if (!empty($options->creditCardInfo)) {
148
                $this->checkAndCreateMopInformation();
149
                $this->paymentModule->mopInformation->creditCardData = new CreditCardData($options->creditCardInfo);
150
            }
151
        }
152
    }
153
154
    /**
155
     * Create Payment Data node if needed
156
     */
157
    private function checkAndCreatePaymentData()
158
    {
159
        if (is_null($this->paymentModule->paymentData)) {
160
            $this->paymentModule->paymentData = new PaymentData();
161
        }
162
    }
163
164
    /**
165
     * Create MopInformation node if needed
166
     */
167
    private function checkAndCreateMopInformation()
168
    {
169
        if (is_null($this->paymentModule->mopInformation)) {
170
            $this->paymentModule->mopInformation = new MopInformation();
171
        }
172
    }
173
}
174