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

GetCustomerPaymentProfileResponse::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 GetCustomerPaymentProfileResponse
7
 */
8
class GetCustomerPaymentProfileResponse extends ANetApiResponseType
9
{
10
11
    /**
12
     * @property \net\authorize\api\contract\v1\CustomerPaymentProfileMaskedType
13
     * $paymentProfile
14
     */
15
    private $paymentProfile = null;
16
17
    /**
18
     * Gets as paymentProfile
19
     *
20
     * @return \net\authorize\api\contract\v1\CustomerPaymentProfileMaskedType
21
     */
22
    public function getPaymentProfile()
23
    {
24
        return $this->paymentProfile;
25
    }
26
27
    /**
28
     * Sets a new paymentProfile
29
     *
30
     * @param \net\authorize\api\contract\v1\CustomerPaymentProfileMaskedType
31
     * $paymentProfile
32
     * @return self
33
     */
34
    public function setPaymentProfile(\net\authorize\api\contract\v1\CustomerPaymentProfileMaskedType $paymentProfile)
35
    {
36
        $this->paymentProfile = $paymentProfile;
37
        return $this;
38
    }
39
40
41
    // Json Set Code
42
    public function set($data)
43
    {
44
        if(is_array($data) || is_object($data)) {
45
			$mapper = \net\authorize\util\Mapper::Instance();
46
			foreach($data AS $key => $value) {
47
				$classDetails = $mapper->getClass(get_class() , $key);
48
	 
49
				if($classDetails !== NULL ) {
50
					if ($classDetails->isArray) {
51
						if ($classDetails->isCustomDefined) {
52
							foreach($value AS $keyChild => $valueChild) {
53
								$type = new $classDetails->className;
54
								$type->set($valueChild);
55
								$this->{'addTo' . $key}($type);
56
							}
57
						}
58
						else if ($classDetails->className === 'DateTime' || $classDetails->className === 'Date' ) {
59
							foreach($value AS $keyChild => $valueChild) {
60
								$type = new \DateTime($valueChild);
61
								$this->{'addTo' . $key}($type);
62
							}
63
						}
64
						else {
65
							foreach($value AS $keyChild => $valueChild) {
66
								$this->{'addTo' . $key}($valueChild);
67
							}
68
						}
69
					}
70
					else {
71
						if ($classDetails->isCustomDefined){
72
							$type = new $classDetails->className;
73
							$type->set($value);
74
							$this->{'set' . $key}($type);
75
						}
76
						else if ($classDetails->className === 'DateTime' || $classDetails->className === 'Date' ) {
77
							$type = new \DateTime($value);
78
							$this->{'set' . $key}($type);
79
						}
80
						else {
81
							$this->{'set' . $key}($value);
82
						}
83
					}
84
				}
85
			}
86
		}
87
    }
88
    
89
}
90
91