Test Failed
Push — master ( b0844f...f87cd0 )
by
unknown
03:20
created

UserTranslator::convertMangoPayLegalUserToDTO()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 14
Code Lines 12

Duplication

Lines 14
Ratio 100 %

Importance

Changes 0
Metric Value
dl 14
loc 14
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 12
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 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)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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.

Loading history...
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)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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.

Loading history...
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);
0 ignored issues
show
Documentation introduced by
$mangoUser->Birthday is of type integer, but the function expects a object<DateTime>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
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)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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.

Loading history...
56
    {
57
        $mangoUser = new UserLegal();
58
        $mangoUser->PersonType = MangoPayConstants::LEAGAL_PERSON_TYPE;
59
        $mangoUser->Name = $userDto->getFirstName() . " " . $userDto->getLastName();
60
        $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...
61
        $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...
62
        $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...
63
        $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...
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)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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.

Loading history...
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