UserBase::setSnapShotArrayToObject()   C
last analyzed

Complexity

Conditions 8
Paths 11

Size

Total Lines 28
Code Lines 17

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 28
rs 5.3846
cc 8
eloc 17
nc 11
nop 1
1
<?php
2
/**
3
 * Created by Graham Owens ([email protected])
4
 * Company: PartFire Ltd (www.partfire.co.uk)
5
 * Console: Discovery
6
 *
7
 * User:    gra
8
 * Date:    10/01/17
9
 * Time:    15:13
10
 * Project: PartFire MangoPay Bundle
11
 * File:    UserBase.php
12
 *
13
 **/
14
15
namespace PartFire\MangoPayBundle\Models\DTOs;
16
17
18
use PartFire\MangoPayBundle\MangoPayConstants;
19
20
class UserBase
21
{
22
    private $personType;
23
    private $email;
24
    private $kYCLevel;
25
    private $id;
26
    private $tag;
27
    private $creationDate;
28
29
    /**
30
     * @return mixed
31
     */
32
    public function getPersonType()
33
    {
34
        return $this->personType;
35
    }
36
37
    /**
38
     * @param mixed $personType
39
     */
40
    public function setPersonType(string $personType)
41
    {
42
        $this->personType = $personType;
43
    }
44
45
    /**
46
     * @return mixed
47
     */
48
    public function getEmail()
49
    {
50
        return $this->email;
51
    }
52
53
    /**
54
     * @param mixed $email
55
     */
56
    public function setEmail($email)
57
    {
58
        $this->email = $email;
59
    }
60
61
    /**
62
     * @return mixed
63
     */
64
    public function getKYCLevel()
65
    {
66
        return $this->kYCLevel;
67
    }
68
69
    /**
70
     * @param mixed $kYCLevel
71
     */
72
    public function setKYCLevel($kYCLevel)
73
    {
74
        $this->kYCLevel = $kYCLevel;
75
    }
76
77
    /**
78
     * @return mixed
79
     */
80
    public function getId()
81
    {
82
        return $this->id;
83
    }
84
85
    /**
86
     * @param mixed $id
87
     */
88
    public function setId($id)
89
    {
90
        $this->id = $id;
91
    }
92
93
    /**
94
     * @return mixed
95
     */
96
    public function getTag()
97
    {
98
        return $this->tag;
99
    }
100
101
    /**
102
     * @param mixed $tag
103
     */
104
    public function setTag($tag)
105
    {
106
        $this->tag = $tag;
107
    }
108
109
    /**
110
     * @return mixed
111
     */
112
    public function getCreationDate()
113
    {
114
        return $this->creationDate;
115
    }
116
117
    /**
118
     * @param mixed $creationDate
119
     */
120
    public function setCreationDate($creationDate)
121
    {
122
        $this->creationDate = $creationDate;
123
    }
124
125
    public function setSnapShotArrayToObject(array $array)
126
    {
127
        foreach ($array as $key => $value)
128
        {
129
            $methodName = 'set' . $key;
130
131
            if ($key instanceof \DateTime) {
132
                $value = $key->format('U');
133
            }
134
135
            if ($this->getPersonType() == MangoPayConstants::NATURAL_PERSON_TYPE) {
136
                if ($key == 'Address') {
137
                    $value = $this->getAddressDTO($value);
138
                }
139
            } elseif ($this->getPersonType() == MangoPayConstants::LEGAL_PERSON_TYPE) {
140
                if ($key == 'HeadquartersAddress' || $key == 'LegalRepresentativeAddress') {
141
                    $value = $this->getAddressDTO($value);
142
                }
143
            } else {
144
                throw new \Exception(
145
                    "Person type was set to " . $this->getPersonType() . ". 
146
                    Can only be " . MangoPayConstants::NATURAL_PERSON_TYPE . " or 
147
                    " . MangoPayConstants::LEGAL_PERSON_TYPE);
148
            }
149
150
            $this->$methodName($value);
151
        }
152
    }
153
154
    protected function getAddressDTO(array $addressArray)
155
    {
156
        $value = new Address();
157
        $value->setAddressLine1($addressArray['AddressLine1']);
158
        $value->setAddressLine2($addressArray['AddressLine2']);
159
        $value->setCity($addressArray['City']);
160
        $value->setRegion($addressArray['Region']);
161
        $value->setPostalCode($addressArray['PostalCode']);
162
        $value->setCountry($addressArray['Country']);
163
164
        return $value;
165
    }
166
167
}