Completed
Push — master ( 9ebe33...7fa78e )
by Kaushik
52:50 queued 23:00
created

UpdateMerchantDetailsResponse::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 UpdateMerchantDetailsResponse
7
 */
8
class UpdateMerchantDetailsResponse extends ANetApiResponseType
9
{
10
11
12
    // Json Set Code
13
    public function set($data)
14
    {
15
        if(is_array($data) || is_object($data)) {
16
			$mapper = \net\authorize\util\Mapper::Instance();
17
			foreach($data AS $key => $value) {
18
				$classDetails = $mapper->getClass(get_class() , $key);
19
	 
20
				if($classDetails !== NULL ) {
21
					if ($classDetails->isArray) {
22
						if ($classDetails->isCustomDefined) {
23
							foreach($value AS $keyChild => $valueChild) {
24
								$type = new $classDetails->className;
25
								$type->set($valueChild);
26
								$this->{'addTo' . $key}($type);
27
							}
28
						}
29
						else if ($classDetails->className === 'DateTime' || $classDetails->className === 'Date' ) {
30
							foreach($value AS $keyChild => $valueChild) {
31
								$type = new \DateTime($valueChild);
32
								$this->{'addTo' . $key}($type);
33
							}
34
						}
35
						else {
36
							foreach($value AS $keyChild => $valueChild) {
37
								$this->{'addTo' . $key}($valueChild);
38
							}
39
						}
40
					}
41
					else {
42
						if ($classDetails->isCustomDefined){
43
							$type = new $classDetails->className;
44
							$type->set($value);
45
							$this->{'set' . $key}($type);
46
						}
47
						else if ($classDetails->className === 'DateTime' || $classDetails->className === 'Date' ) {
48
							$type = new \DateTime($value);
49
							$this->{'set' . $key}($type);
50
						}
51
						else {
52
							$this->{'set' . $key}($value);
53
						}
54
					}
55
				}
56
			}
57
		}
58
    }
59
    
60
}
61
62