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

GetSettledBatchListResponse::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 GetSettledBatchListResponse
7
 */
8
class GetSettledBatchListResponse extends ANetApiResponseType
9
{
10
11
    /**
12
     * @property \net\authorize\api\contract\v1\BatchDetailsType[] $batchList
13
     */
14
    private $batchList = null;
15
16
    /**
17
     * Adds as batch
18
     *
19
     * @return self
20
     * @param \net\authorize\api\contract\v1\BatchDetailsType $batch
21
     */
22
    public function addToBatchList(\net\authorize\api\contract\v1\BatchDetailsType $batch)
23
    {
24
        $this->batchList[] = $batch;
25
        return $this;
26
    }
27
28
    /**
29
     * isset batchList
30
     *
31
     * @param scalar $index
32
     * @return boolean
33
     */
34
    public function issetBatchList($index)
35
    {
36
        return isset($this->batchList[$index]);
37
    }
38
39
    /**
40
     * unset batchList
41
     *
42
     * @param scalar $index
43
     * @return void
44
     */
45
    public function unsetBatchList($index)
46
    {
47
        unset($this->batchList[$index]);
48
    }
49
50
    /**
51
     * Gets as batchList
52
     *
53
     * @return \net\authorize\api\contract\v1\BatchDetailsType[]
54
     */
55
    public function getBatchList()
56
    {
57
        return $this->batchList;
58
    }
59
60
    /**
61
     * Sets a new batchList
62
     *
63
     * @param \net\authorize\api\contract\v1\BatchDetailsType[] $batchList
64
     * @return self
65
     */
66
    public function setBatchList(array $batchList)
67
    {
68
        $this->batchList = $batchList;
69
        return $this;
70
    }
71
72
73
    // Json Set Code
74
    public function set($data)
75
    {
76
        if(is_array($data) || is_object($data)) {
77
			$mapper = \net\authorize\util\Mapper::Instance();
78
			foreach($data AS $key => $value) {
79
				$classDetails = $mapper->getClass(get_class() , $key);
80
	 
81
				if($classDetails !== NULL ) {
82
					if ($classDetails->isArray) {
83
						if ($classDetails->isCustomDefined) {
84
							foreach($value AS $keyChild => $valueChild) {
85
								$type = new $classDetails->className;
86
								$type->set($valueChild);
87
								$this->{'addTo' . $key}($type);
88
							}
89
						}
90
						else if ($classDetails->className === 'DateTime' || $classDetails->className === 'Date' ) {
91
							foreach($value AS $keyChild => $valueChild) {
92
								$type = new \DateTime($valueChild);
93
								$this->{'addTo' . $key}($type);
94
							}
95
						}
96
						else {
97
							foreach($value AS $keyChild => $valueChild) {
98
								$this->{'addTo' . $key}($valueChild);
99
							}
100
						}
101
					}
102
					else {
103
						if ($classDetails->isCustomDefined){
104
							$type = new $classDetails->className;
105
							$type->set($value);
106
							$this->{'set' . $key}($type);
107
						}
108
						else if ($classDetails->className === 'DateTime' || $classDetails->className === 'Date' ) {
109
							$type = new \DateTime($value);
110
							$this->{'set' . $key}($type);
111
						}
112
						else {
113
							$this->{'set' . $key}($value);
114
						}
115
					}
116
				}
117
			}
118
		}
119
    }
120
    
121
}
122
123