Completed
Push — fopcreatefop ( 97f2d4...a66afc )
by Dieter
07:35
created

ExtendedPaymentDetails   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 153
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 7
lcom 0
cbo 1
dl 0
loc 153
c 1
b 0
f 0
ccs 26
cts 26
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
B convertDate() 0 25 6
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\InstallmentsInfo;
26
27
/**
28
 * ExtendedPaymentDetails
29
 *
30
 * @package Amadeus\Client\Struct\Fop
31
 * @author Dieter Devlieghere <[email protected]>
32
 */
33
class ExtendedPaymentDetails
34
{
35
    const FORMAT_YYMMDD = 101;
36
    const FORMAT_YYDDD = 105;
37
    const FORMAT_MMDD = 106;
38
39
    /**
40
     * @var int|string
41
     */
42
    public $instalmentsNumber;
43
44
    /**
45
     * @var string
46
     */
47
    public $instalmentsFrequency;
48
49
    /**
50
     * @var string
51
     */
52
    public $instalmentsStartDate;
53
54
    /**
55
     * 10 CCYYMMDDTHHMM
56
     * 101 YYMMDD
57
     * 102 CCYYMMDD
58
     * 103 YYWWD
59
     * 105 YYDDD
60
     * 106 MMDD
61
     * 107 DDD
62
     * 108 WW
63
     * 109 MM
64
     * 110 DD
65
     * 2 DDMMYY
66
     * 201 YYMMDDHHMM
67
     * 202 YYMMDDHHMMSS
68
     * 203 CCYYMMDDHHMM
69
     * 204 CCYYMMDDHHMMSS
70
     * 205 CCYYMMDDHHMMZHHMM
71
     * 3 MMDDYY
72
     * 301 YYMMDDHHMMZZZ
73
     * 302 YYMMDDHHMMSSZZZ
74
     * 303 CCYYMMDDHHMMZZZ
75
     * 304 CCYYMMDDHHMMSSZZZ
76
     * 305 MMDDHHMM
77
     * 306 DDHHMM
78
     * 4 DDMMCCYY
79
     * 401 HHMM
80
     * 402 HHMMSS
81
     * 404 HHMMSSZZZ
82
     * 405 MMMMSS
83
     * 406 ZHHMM
84
     * 5 DDMMCCYYHHMM
85
     * 501 HHMMHHMM
86
     * 502 HHMMSS-HHMMSS
87
     * 503 HHMMSSZZZ-HHMMSSZZZ
88
     * 6 CCYYMMB
89
     * 600 CC
90
     * 601 YY
91
     * 602 CCYY
92
     * 603 YYS
93
     * 604 CCYYS
94
     * 608 CCYYQ
95
     * 609 YYMM
96
     * 610 CCYYMM
97
     * 613 YYMMA
98
     * 614 CCYYMMA
99
     * 615 YYWW
100
     * 616 CCYYWW
101
     * 7 CCYYMMW
102
     * 701 YY-YY
103
     * 702 CCYY-CCYY
104
     * 703 YYS-YYS
105
     * 704 CCYYS-CCYYS
106
     * 705 YYPYYP
107
     * 706 CCYYP-CCYYP
108
     * 707 YYQ-YYQ
109
     * 708 CCYYQ-CCYYQ
110
     * 709 YYMM-YYMM
111
     * 710 CCYYMM-CCYYMM
112
     * 711 CCYYMMDD-CCYYMMDD
113
     * 713 YYMMDDHHMM-YYMMDDHHMM
114
     * 715 YYWW-YYWW
115
     * 716 CCYYWW-CCYYWW
116
     * 717 YYMMDD-YYMMDD
117
     * 718 CCYYMMDD-CCYYMMDD
118
     * 719 CCYYMMDDHHMM-CCYYMMDDHHMM
119
     * 720 DHHMM-DHHMM
120
     * 8 CCYYMMDDS
121
     * 801 Year
122
     * 802 Month
123
     * 803 Week
124
     * 804 Day
125
     * 805 Hour
126
     * 806 Minute
127
     * 807 Second
128
     * 808 Semester
129
     * 809 Four months period
130
     * 810 Trimester
131
     * 811 Half month
132
     * 812 Ten days
133
     * 813 Day of the week
134
     * 814 Working days
135
     * 9 CCYYMMDDPP
136
     *
137
     * @var string
138
     */
139
    public $instalmentsDatrDateFormat;
140
141
    /**
142
     * ExtendedPaymentDetails constructor.
143
     *
144
     * @param InstallmentsInfo $info
145
     */
146 5
    public function __construct(InstallmentsInfo $info)
147
    {
148 5
        $this->instalmentsNumber = $info->nrOfInstallments;
149 5
        $this->instalmentsFrequency = $info->frequency;
150 5
        $this->instalmentsDatrDateFormat = $info->format;
0 ignored issues
show
Documentation Bug introduced by
It seems like $info->format can also be of type integer. However, the property $instalmentsDatrDateFormat is declared as type string. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
151 5
        $this->instalmentsStartDate = $this->convertDate($info->startDate, $info->format);
152 4
    }
153
154
    /**
155
     * @param \DateTime $startDate
156
     * @param string|int $format
157
     * @return string
158
     * @throws \RuntimeException
159
     */
160 5
    protected function convertDate($startDate, $format)
161
    {
162 5
        $date = "";
163
164 5
        if ($startDate instanceof \DateTime) {
165
            switch ($format) {
166 4
                case self::FORMAT_YYMMDD:
167 1
                    $date = $startDate->format('ymd');
168 1
                    break;
169 3
                case self::FORMAT_MMDD:
170 1
                    $date = $startDate->format('md');
171 1
                    break;
172 2
                case self::FORMAT_YYDDD:
173 1
                    $date = $startDate->format('yz');
174 1
                    if (strlen($date) === 4) {
175 1
                        $date = substr($date, 0, 2) . "0" . substr($date, 2);
176 1
                    }
177 1
                    break;
178 1
                default:
179 1
                    throw new \RuntimeException("Installments Format '" . $format . "' is not implemented!");
180 1
            }
181 3
        }
182
183 4
        return $date;
184
    }
185
}
186