Passed
Push — master ( f87cd0...02e408 )
by
unknown
08:57
created

UserTranslator::getConvertDTOToMangoPayAddress()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 10
rs 9.4285
cc 1
eloc 8
nc 1
nop 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());
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $mangoUser->Address is correct as $this->getConvertDTOToMa...$userDto->getAddress()) (which targets PartFire\MangoPayBundle\...tDTOToMangoPayAddress()) seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
39
        if ($userDto->getId()) {
40
            $mangoUser->Id = $userDto->getId();
41
        }
42
        return $mangoUser;
43
    }
44
45
    public function convertMangoPayNaturalUserToDTO(UserNatural $mangoUser)
46
    {
47
        $userDto = new PFUserNatural();
48
        $userDto->setPersonType($mangoUser->PersonType);
49
        $userDto->setFirstName($mangoUser->FirstName);
50
        $userDto->setLastName($mangoUser->LastName);
51
        $userDto->setBirthday($mangoUser->Birthday);
52
        $userDto->setNationality($mangoUser->Nationality);
53
        $userDto->setCountryOfResidence($mangoUser->CountryOfResidence);
54
        $userDto->setEmail($mangoUser->Email);
55
        $userDto->setId($mangoUser->Id);
56
        $userDto->setKYCLevel($mangoUser->KYCLevel);
57
        $userDto->setAddress($this->getConvertMangoAddressToDTO($mangoUser->Address));
58
        return $userDto;
59
    }
60
61
    public function convertDTOToMangoPayLegalUser(PFUserLegal $userDto)
62
    {
63
        $mangoUser = new UserLegal();
64
        $mangoUser->PersonType = MangoPayConstants::LEAGAL_PERSON_TYPE;
65
        $mangoUser->Name = $userDto->getFirstName() . " " . $userDto->getLastName();
66
        $mangoUser->LastName = $userDto->getLastName();
0 ignored issues
show
Bug introduced by
The property LastName does not seem to exist. Did you mean LegalRepresentativeLastName?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
67
        $mangoUser->Birthday = (int) $userDto->getLegalRepresentativeBirthday();
0 ignored issues
show
Bug introduced by
The property Birthday does not seem to exist. Did you mean LegalRepresentativeBirthday?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
68
        $mangoUser->Nationality = $userDto->getNationality();
0 ignored issues
show
Bug introduced by
The property Nationality does not seem to exist. Did you mean LegalRepresentativeNationality?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
69
        $mangoUser->CountryOfResidence = $userDto->getCountryOfResidence();
0 ignored issues
show
Bug introduced by
The property CountryOfResidence does not seem to exist. Did you mean LegalRepresentativeCountryOfResidence?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
70
        $mangoUser->Email = $userDto->getEmail();
71
        $mangoUser->Tag = $userDto->getTag();
72
        if ($userDto->getId()) {
73
            $mangoUser->Id = $userDto->getId();
74
        }
75
        return $mangoUser;
76
    }
77
78
    public function convertMangoPayLegalUserToDTO(UserNatural $mangoUser)
79
    {
80
        $userDto = new PFUserLegal();
81
        $userDto->setPersonType($mangoUser->PersonType);
82
        $userDto->setFirstName($mangoUser->FirstName);
83
        $userDto->setLastName($mangoUser->LastName);
84
        $userDto->setLegalRepresentativeBirthday($mangoUser->Birthday);
85
        $userDto->setNationality($mangoUser->Nationality);
86
        $userDto->setCountryOfResidence($mangoUser->CountryOfResidence);
87
        $userDto->setEmail($mangoUser->Email);
88
        $userDto->setId($mangoUser->Id);
89
        $userDto->setKYCLevel($mangoUser->KYCLevel);
90
        return $userDto;
91
    }
92
93
    private function getConvertDTOToMangoPayAddress(PFAddress $pfAddress)
94
    {
95
        $address = new Address();
96
        $address->AddressLine1 = $pfAddress->getAddressLine1();
97
        $address->AddressLine2 = $pfAddress->getAddressLine2();
98
        $address->City = $pfAddress->getCity();
99
        $address->Region = $pfAddress->getRegion();
100
        $address->PostalCode = $pfAddress->getPostalCode();
101
        $address->Country = $pfAddress->getCountry();
102
    }
103
104
    private function getConvertMangoAddressToDTO(Address $address)
105
    {
106
        $pfAddress = new PFAddress();
107
        $pfAddress->setAddressLine1($address->AddressLine1);
108
        $pfAddress->setAddressLine2($address->AddressLine2);
109
        $pfAddress->setCity($address->City);
110
        $pfAddress->setRegion($address->Region);
111
        $pfAddress->setPostalCode($address->PostalCode);
112
        $pfAddress->setCountry($address->Country);
113
114
        return $pfAddress;
115
    }
116
117
}
118