|
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 PartFire\MangoPayBundle\MangoPayConstants; |
|
18
|
|
|
use PartFire\MangoPayBundle\Models\DTOs\UserNatural as PFUserNatural; |
|
19
|
|
|
use PartFire\MangoPayBundle\Models\DTOs\UserLegal as PFUserLegal; |
|
20
|
|
|
|
|
21
|
|
|
class UserTranslator |
|
22
|
|
|
{ |
|
23
|
|
View Code Duplication |
public function convertDTOToMangoPayNaturalUser(PFUserNatural $userDto) |
|
|
|
|
|
|
24
|
|
|
{ |
|
25
|
|
|
$mangoUser = new UserNatural(); |
|
26
|
|
|
$mangoUser->PersonType = MangoPayConstants::NATURAL_PERSON_TYPE; |
|
27
|
|
|
$mangoUser->FirstName = $userDto->getFirstName(); |
|
28
|
|
|
$mangoUser->LastName = $userDto->getLastName(); |
|
29
|
|
|
$mangoUser->Birthday = (int) $userDto->getBirthday(); |
|
30
|
|
|
$mangoUser->Nationality = $userDto->getNationality(); |
|
31
|
|
|
$mangoUser->CountryOfResidence = $userDto->getCountryOfResidence(); |
|
32
|
|
|
$mangoUser->Email = $userDto->getEmail(); |
|
33
|
|
|
$mangoUser->Tag = $userDto->getTag(); |
|
34
|
|
|
if ($userDto->getId()) { |
|
35
|
|
|
$mangoUser->Id = $userDto->getId(); |
|
36
|
|
|
} |
|
37
|
|
|
return $mangoUser; |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
View Code Duplication |
public function convertMangoPayNaturalUserToDTO(UserNatural $mangoUser) |
|
|
|
|
|
|
41
|
|
|
{ |
|
42
|
|
|
$userDto = new PFUserNatural(); |
|
43
|
|
|
$userDto->setPersonType($mangoUser->PersonType); |
|
44
|
|
|
$userDto->setFirstName($mangoUser->FirstName); |
|
45
|
|
|
$userDto->setLastName($mangoUser->LastName); |
|
46
|
|
|
$userDto->setBirthday($mangoUser->Birthday); |
|
|
|
|
|
|
47
|
|
|
$userDto->setNationality($mangoUser->Nationality); |
|
48
|
|
|
$userDto->setCountryOfResidence($mangoUser->CountryOfResidence); |
|
49
|
|
|
$userDto->setEmail($mangoUser->Email); |
|
50
|
|
|
$userDto->setId($mangoUser->Id); |
|
51
|
|
|
$userDto->setKYCLevel($mangoUser->KYCLevel); |
|
52
|
|
|
return $userDto; |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
View Code Duplication |
public function convertDTOToMangoPayLegalUser(PFUserLegal $userDto) |
|
|
|
|
|
|
56
|
|
|
{ |
|
57
|
|
|
$mangoUser = new UserLegal(); |
|
58
|
|
|
$mangoUser->PersonType = MangoPayConstants::LEAGAL_PERSON_TYPE; |
|
59
|
|
|
$mangoUser->Name = $userDto->getFirstName() . " " . $userDto->getLastName(); |
|
60
|
|
|
$mangoUser->LastName = $userDto->getLastName(); |
|
|
|
|
|
|
61
|
|
|
$mangoUser->Birthday = (int) $userDto->getLegalRepresentativeBirthday(); |
|
|
|
|
|
|
62
|
|
|
$mangoUser->Nationality = $userDto->getNationality(); |
|
|
|
|
|
|
63
|
|
|
$mangoUser->CountryOfResidence = $userDto->getCountryOfResidence(); |
|
|
|
|
|
|
64
|
|
|
$mangoUser->Email = $userDto->getEmail(); |
|
65
|
|
|
$mangoUser->Tag = $userDto->getTag(); |
|
66
|
|
|
if ($userDto->getId()) { |
|
67
|
|
|
$mangoUser->Id = $userDto->getId(); |
|
68
|
|
|
} |
|
69
|
|
|
return $mangoUser; |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
View Code Duplication |
public function convertMangoPayLegalUserToDTO(UserNatural $mangoUser) |
|
|
|
|
|
|
73
|
|
|
{ |
|
74
|
|
|
$userDto = new PFUserLegal(); |
|
75
|
|
|
$userDto->setPersonType($mangoUser->PersonType); |
|
76
|
|
|
$userDto->setFirstName($mangoUser->FirstName); |
|
77
|
|
|
$userDto->setLastName($mangoUser->LastName); |
|
78
|
|
|
$userDto->setLegalRepresentativeBirthday($mangoUser->Birthday); |
|
79
|
|
|
$userDto->setNationality($mangoUser->Nationality); |
|
80
|
|
|
$userDto->setCountryOfResidence($mangoUser->CountryOfResidence); |
|
81
|
|
|
$userDto->setEmail($mangoUser->Email); |
|
82
|
|
|
$userDto->setId($mangoUser->Id); |
|
83
|
|
|
$userDto->setKYCLevel($mangoUser->KYCLevel); |
|
84
|
|
|
return $userDto; |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
} |
|
88
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.