Passed
Push — master ( 397ecf...9bcda0 )
by
unknown
02:37
created

UserTranslator   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 112
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 6

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 8
c 1
b 0
f 0
lcom 0
cbo 6
dl 0
loc 112
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A convertDTOToMangoPayNaturalUser() 0 19 2
A convertMangoPayNaturalUserToDTO() 0 17 1
B convertDTOToMangoPayLegalUser() 0 26 2
A convertMangoPayLegalUserToDTO() 0 17 1
A getConvertDTOToMangoPayAddress() 0 12 1
A getConvertMangoAddressToDTO() 0 12 1
1
<?php
2
/**
3
 * Created by Carl Owens ([email protected])
4
 * Company: PartFire Ltd (www.partfire.co.uk)
5
 * Copyright © 2016 PartFire Ltd. All rights reserved.
6
 *
7
 * User:    Carl Owens
8
 * Date:    28/11/2016
9
 * Time:    11:14
10
 * File:    UserTranslator.php
11
 **/
12
13
namespace PartFire\MangoPayBundle\Models\DTOs\Translators;
14
15
use MangoPay\UserLegal;
16
use MangoPay\UserNatural;
17
use MangoPay\Address;
18
19
use PartFire\MangoPayBundle\MangoPayConstants;
20
use PartFire\MangoPayBundle\Models\DTOs\UserBase;
21
use PartFire\MangoPayBundle\Models\DTOs\Address as PFAddress;
22
use PartFire\MangoPayBundle\Models\DTOs\UserNatural as PFUserNatural;
23
use PartFire\MangoPayBundle\Models\DTOs\UserLegal as PFUserLegal;
24
25
class UserTranslator
26
{
27
    public function convertDTOToMangoPayNaturalUser(PFUserNatural $userDto)
28
    {
29
        $mangoUser = new UserNatural();
30
        $mangoUser->PersonType = MangoPayConstants::NATURAL_PERSON_TYPE;
31
        $mangoUser->FirstName = $userDto->getFirstName();
32
        $mangoUser->LastName = $userDto->getLastName();
33
        $mangoUser->Birthday = (int) $userDto->getBirthday();
34
        $mangoUser->Nationality = $userDto->getNationality();
35
        $mangoUser->CountryOfResidence = $userDto->getCountryOfResidence();
36
        $mangoUser->Email = $userDto->getEmail();
37
        $mangoUser->Tag = $userDto->getTag();
38
        $mangoUser->Address = $this->getConvertDTOToMangoPayAddress($userDto->getAddress());
39
        $mangoUser->IncomeRange = $userDto->getIncomeRange();
40
        $mangoUser->Occupation = $userDto->getOccupation();
41
        if ($userDto->getId()) {
42
            $mangoUser->Id = $userDto->getId();
43
        }
44
        return $mangoUser;
45
    }
46
47
    public function convertMangoPayNaturalUserToDTO(UserNatural $mangoUser)
48
    {
49
        $userDto = new PFUserNatural();
50
        $userDto->setPersonType($mangoUser->PersonType);
51
        $userDto->setFirstName($mangoUser->FirstName);
52
        $userDto->setLastName($mangoUser->LastName);
53
        $userDto->setBirthday($mangoUser->Birthday);
54
        $userDto->setNationality($mangoUser->Nationality);
55
        $userDto->setCountryOfResidence($mangoUser->CountryOfResidence);
56
        $userDto->setEmail($mangoUser->Email);
57
        $userDto->setId($mangoUser->Id);
58
        $userDto->setKYCLevel($mangoUser->KYCLevel);
59
        $userDto->setAddress($this->getConvertMangoAddressToDTO($mangoUser->Address));
60
        $userDto->setOccupation($mangoUser->Occupation);
61
        $userDto->setIncomeRange($mangoUser->IncomeRange);
62
        return $userDto;
63
    }
64
65
    public function convertDTOToMangoPayLegalUser(PFUserLegal $userDto)
66
    {
67
        $mangoUser = new UserLegal();
68
        $mangoUser->PersonType                      = MangoPayConstants::LEGAL_PERSON_TYPE;
69
        $mangoUser->LegalPersonType                 = $userDto->getLegalPersonType();
70
        $mangoUser->Name                            = $userDto->getName();
71
        $mangoUser->HeadquartersAddress             = $this->getConvertDTOToMangoPayAddress(
72
            $userDto->getHeadquartersAddress()
73
        );
74
        $mangoUser->LegalRepresentativeFirstName    = $userDto->getLegalRepresentativeFirstName();
75
        $mangoUser->LegalRepresentativeLastName     = $userDto->getLegalRepresentativeLastName();
76
        $mangoUser->LegalRepresentativeAddress      = $this->getConvertDTOToMangoPayAddress(
77
            $userDto->getLegalRepresentativeAddress()
78
        );
79
        $mangoUser->LegalRepresentativeEmail        = $userDto->getLegalRepresentativeEmail();
80
        $mangoUser->LegalRepresentativeBirthday     = (int) $userDto->getLegalRepresentativeBirthday();
81
        $mangoUser->LegalRepresentativeNationality  = $userDto->getLegalRepresentativeNationality();
82
        $mangoUser->LegalRepresentativeCountryOfResidence = $userDto->getLegalRepresentativeCountryOfResidence();
83
84
        $mangoUser->Email = $userDto->getEmail();
85
        $mangoUser->Tag = $userDto->getTag();
86
        if ($userDto->getId()) {
87
            $mangoUser->Id = $userDto->getId();
88
        }
89
        return $mangoUser;
90
    }
91
92
    public function convertMangoPayLegalUserToDTO(UserLegal $mangoUser)
93
    {
94
        $userDto = new PFUserLegal();
95
        $userDto->setLegalPersonType($mangoUser->LegalPersonType);
96
        $userDto->setName($mangoUser->Name);
97
        $userDto->setHeadquartersAddress($this->getConvertMangoAddressToDTO($mangoUser->HeadquartersAddress));
98
        $userDto->setLegalRepresentativeFirstName($mangoUser->LegalRepresentativeFirstName);
99
        $userDto->setLegalRepresentativeLastName($mangoUser->LegalRepresentativeLastName);
100
        $userDto->setLegalRepresentativeAddress($this->getConvertMangoAddressToDTO($mangoUser->LegalRepresentativeAddress));
101
        $userDto->setLegalRepresentativeEmail($mangoUser->LegalRepresentativeEmail);
102
        $userDto->setLegalRepresentativeBirthday($mangoUser->LegalRepresentativeBirthday);
103
        $userDto->setLegalRepresentativeNationality($mangoUser->LegalRepresentativeNationality);
104
        $userDto->setLegalRepresentativeCountryOfResidence($mangoUser->LegalRepresentativeCountryOfResidence);
105
        $userDto->setId($mangoUser->Id);
106
        $userDto->setKYCLevel($mangoUser->KYCLevel);
107
        return $userDto;
108
    }
109
110
    private function getConvertDTOToMangoPayAddress(PFAddress $pfAddress)
111
    {
112
        $address = new Address();
113
        $address->AddressLine1 = $pfAddress->getAddressLine1();
114
        $address->AddressLine2 = $pfAddress->getAddressLine2();
115
        $address->City = $pfAddress->getCity();
116
        $address->Region = $pfAddress->getRegion();
117
        $address->PostalCode = $pfAddress->getPostalCode();
118
        $address->Country = $pfAddress->getCountry();
119
120
        return $address;
121
    }
122
123
    private function getConvertMangoAddressToDTO(Address $address)
124
    {
125
        $pfAddress = new PFAddress();
126
        $pfAddress->setAddressLine1($address->AddressLine1);
127
        $pfAddress->setAddressLine2($address->AddressLine2);
128
        $pfAddress->setCity($address->City);
129
        $pfAddress->setRegion($address->Region);
130
        $pfAddress->setPostalCode($address->PostalCode);
131
        $pfAddress->setCountry($address->Country);
132
133
        return $pfAddress;
134
    }
135
136
}
137