Completed
Push — master ( 9ebe33 )
by Kaushik
28:24
created

CustomerPaymentProfileType::set()   C

Complexity

Conditions 15
Paths 9

Size

Total Lines 46

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 46
rs 5.9166
c 0
b 0
f 0
cc 15
nc 9
nop 1

How to fix   Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
namespace net\authorize\api\contract\v1;
4
5
/**
6
 * Class representing CustomerPaymentProfileType
7
 *
8
 * 
9
 * XSD Type: customerPaymentProfileType
10
 */
11
class CustomerPaymentProfileType extends CustomerPaymentProfileBaseType implements \JsonSerializable
12
{
13
14
    /**
15
     * @property \net\authorize\api\contract\v1\PaymentType $payment
16
     */
17
    private $payment = null;
18
19
    /**
20
     * @property \net\authorize\api\contract\v1\DriversLicenseType $driversLicense
21
     */
22
    private $driversLicense = null;
23
24
    /**
25
     * @property string $taxId
26
     */
27
    private $taxId = null;
28
29
    /**
30
     * @property boolean $defaultPaymentProfile
31
     */
32
    private $defaultPaymentProfile = null;
33
34
    /**
35
     * Gets as payment
36
     *
37
     * @return \net\authorize\api\contract\v1\PaymentType
38
     */
39
    public function getPayment()
40
    {
41
        return $this->payment;
42
    }
43
44
    /**
45
     * Sets a new payment
46
     *
47
     * @param \net\authorize\api\contract\v1\PaymentType $payment
48
     * @return self
49
     */
50
    public function setPayment(\net\authorize\api\contract\v1\PaymentType $payment)
51
    {
52
        $this->payment = $payment;
53
        return $this;
54
    }
55
56
    /**
57
     * Gets as driversLicense
58
     *
59
     * @return \net\authorize\api\contract\v1\DriversLicenseType
60
     */
61
    public function getDriversLicense()
62
    {
63
        return $this->driversLicense;
64
    }
65
66
    /**
67
     * Sets a new driversLicense
68
     *
69
     * @param \net\authorize\api\contract\v1\DriversLicenseType $driversLicense
70
     * @return self
71
     */
72
    public function setDriversLicense(\net\authorize\api\contract\v1\DriversLicenseType $driversLicense)
73
    {
74
        $this->driversLicense = $driversLicense;
75
        return $this;
76
    }
77
78
    /**
79
     * Gets as taxId
80
     *
81
     * @return string
82
     */
83
    public function getTaxId()
84
    {
85
        return $this->taxId;
86
    }
87
88
    /**
89
     * Sets a new taxId
90
     *
91
     * @param string $taxId
92
     * @return self
93
     */
94
    public function setTaxId($taxId)
95
    {
96
        $this->taxId = $taxId;
97
        return $this;
98
    }
99
100
    /**
101
     * Gets as defaultPaymentProfile
102
     *
103
     * @return boolean
104
     */
105
    public function getDefaultPaymentProfile()
106
    {
107
        return $this->defaultPaymentProfile;
108
    }
109
110
    /**
111
     * Sets a new defaultPaymentProfile
112
     *
113
     * @param boolean $defaultPaymentProfile
114
     * @return self
115
     */
116
    public function setDefaultPaymentProfile($defaultPaymentProfile)
117
    {
118
        $this->defaultPaymentProfile = $defaultPaymentProfile;
119
        return $this;
120
    }
121
122
123
    // Json Serialize Code
124
    public function jsonSerialize(){
125
        $values = array_filter((array)get_object_vars($this),
126
        function ($val){
127
            return !is_null($val);
128
        });
129
        $mapper = \net\authorize\util\Mapper::Instance();
130
        foreach($values as $key => $value){
131
            $classDetails = $mapper->getClass(get_class() , $key);
132
            if (isset($value)){
133
                if ($classDetails->className === 'Date'){
134
                    $dateTime = $value->format('Y-m-d');
135
                    $values[$key] = $dateTime;
136
                }
137
                else if ($classDetails->className === 'DateTime'){
138
                    $dateTime = $value->format('Y-m-d\TH:i:s\Z');
139
                    $values[$key] = $dateTime;
140
                }
141
                if (is_array($value)){
142
                    if (!$classDetails->isInlineArray){
143
                        $subKey = $classDetails->arrayEntryname;
144
                        $subArray = [$subKey => $value];
145
                        $values[$key] = $subArray;
146
                    }
147
                }
148
            }
149
        }
150
        if (get_parent_class() == ""){
151
            return $values;
152
        }
153
        else{
154
            return array_merge(parent::jsonSerialize(), $values);
155
        }
156
    }
157
    
158
    // Json Set Code
159
    public function set($data)
160
    {
161
        if(is_array($data) || is_object($data)) {
162
			$mapper = \net\authorize\util\Mapper::Instance();
163
			foreach($data AS $key => $value) {
164
				$classDetails = $mapper->getClass(get_class() , $key);
165
	 
166
				if($classDetails !== NULL ) {
167
					if ($classDetails->isArray) {
168
						if ($classDetails->isCustomDefined) {
169
							foreach($value AS $keyChild => $valueChild) {
170
								$type = new $classDetails->className;
171
								$type->set($valueChild);
172
								$this->{'addTo' . $key}($type);
173
							}
174
						}
175
						else if ($classDetails->className === 'DateTime' || $classDetails->className === 'Date' ) {
176
							foreach($value AS $keyChild => $valueChild) {
177
								$type = new \DateTime($valueChild);
178
								$this->{'addTo' . $key}($type);
179
							}
180
						}
181
						else {
182
							foreach($value AS $keyChild => $valueChild) {
183
								$this->{'addTo' . $key}($valueChild);
184
							}
185
						}
186
					}
187
					else {
188
						if ($classDetails->isCustomDefined){
189
							$type = new $classDetails->className;
190
							$type->set($value);
191
							$this->{'set' . $key}($type);
192
						}
193
						else if ($classDetails->className === 'DateTime' || $classDetails->className === 'Date' ) {
194
							$type = new \DateTime($value);
195
							$this->{'set' . $key}($type);
196
						}
197
						else {
198
							$this->{'set' . $key}($value);
199
						}
200
					}
201
				}
202
			}
203
		}
204
    }
205
    
206
}
207
208