Passed
Push — master ( 735f41...25c7eb )
by Carl
04:13
created

BankAccountTranslator::translateMangoToIbanDto()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 24
Code Lines 21

Duplication

Lines 24
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 24
loc 24
rs 8.9713
cc 1
eloc 21
nc 1
nop 1
1
<?php
2
/**
3
 * Created by Carl Owens ([email protected])
4
 * Company: PartFire Ltd (www.partfire.co.uk)
5
 * Copyright © 2017 PartFire Ltd. All rights reserved.
6
 *
7
 * User:    Carl Owens
8
 * Date:    20/01/2017
9
 * Time:    13:14
10
 * File:    BankAccountTranslator.php
11
 **/
12
13
namespace PartFire\MangoPayBundle\Models\DTOs\Translators;
14
15
use MangoPay\Address;
16
use MangoPay\BankAccount;
17
use MangoPay\BankAccountDetailsGB;
18
use MangoPay\BankAccountDetailsIBAN;
19
use PartFire\MangoPayBundle\Models\DTOs\Address as AddressDto;
20
use PartFire\MangoPayBundle\Models\DTOs\GbBankAccount;
21
use PartFire\MangoPayBundle\Models\DTOs\IbanBankAccount;
22
23
class BankAccountTranslator
24
{
25
    /**
26
     * @param IbanBankAccount $ibanBankAccount
27
     * @return BankAccount
28
     */
29
    public function translateIbanDtoToMango(IbanBankAccount $ibanBankAccount) : BankAccount
30
    {
31
        $bankAccount = new BankAccount();
32
        $bankAccount->Tag = $ibanBankAccount->getTag();
33
        $bankAccount->OwnerName = $ibanBankAccount->getOwnerName();
34
        $bankAccount->Details = new BankAccountDetailsIBAN();
35
        $bankAccount->Details->IBAN = $ibanBankAccount->getIban();
36
        $bankAccount->Details->BIC = $ibanBankAccount->getBic();
37
        $bankAccount->OwnerAddress = new Address();
38
        $bankAccount->OwnerAddress->AddressLine1 = $ibanBankAccount->getOwnerAddress()->getAddressLine1();
39
        $bankAccount->OwnerAddress->AddressLine2 = $ibanBankAccount->getOwnerAddress()->getAddressLine2();
40
        $bankAccount->OwnerAddress->City = $ibanBankAccount->getOwnerAddress()->getCity();
41
        $bankAccount->OwnerAddress->Country = $ibanBankAccount->getOwnerAddress()->getCountry();
42
        $bankAccount->OwnerAddress->PostalCode = $ibanBankAccount->getOwnerAddress()->getPostalCode();
43
        $bankAccount->OwnerAddress->Region = $ibanBankAccount->getOwnerAddress()->getRegion();
44
        return $bankAccount;
45
    }
46
47 View Code Duplication
    public function translateMangoToIbanDto(BankAccount $bankAccount) : IbanBankAccount
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...
48
    {
49
        $ibanBankAccount = new IbanBankAccount();
50
        $ibanBankAccount->setTag($bankAccount->Tag);
51
        $ibanBankAccount->setActive($bankAccount->Active);
52
        $ibanBankAccount->setCreationDate($bankAccount->CreationDate);
53
        $ibanBankAccount->setId($bankAccount->Id);
54
        $ibanBankAccount->setUserId($bankAccount->UserId);
55
        $ibanBankAccount->setOwnerName($bankAccount->OwnerName);
56
        $ibanBankAccount->setType($bankAccount->Type);
57
        $ibanBankAccount->setIban($bankAccount->Details->IBAN);
58
        $ibanBankAccount->setBic($bankAccount->Details->Bic);
59
        $ibanBankAccount->setCreationDate($bankAccount->CreationDate);
60
61
        $address = new AddressDto();
62
        $address->setAddressLine1($bankAccount->OwnerAddress->AddressLine1);
63
        $address->setAddressLine2($bankAccount->OwnerAddress->AddressLine2);
64
        $address->setCity($bankAccount->OwnerAddress->City);
65
        $address->setCountry($bankAccount->OwnerAddress->Country);
66
        $address->setPostalCode($bankAccount->OwnerAddress->PostalCode);
67
        $address->setRegion($bankAccount->OwnerAddress->Region);
68
        $ibanBankAccount->setOwnerAddress($address);
69
        return $ibanBankAccount;
70
    }
71
72
    public function translateGbDtoToMango(GbBankAccount $gbBankAccount) : BankAccount
73
    {
74
        $bankAccount = new BankAccount();
75
        $bankAccount->Tag = $gbBankAccount->getTag();
76
        $bankAccount->OwnerName = $gbBankAccount->getOwnerName();
77
        $bankAccount->Details = new BankAccountDetailsGB();
78
        $bankAccount->Details->AccountNumber = $gbBankAccount->getAccountNumber();
79
        $bankAccount->Details->SortCode = $gbBankAccount->getSortCode();
80
        $bankAccount->OwnerAddress = new Address();
81
        $bankAccount->OwnerAddress->AddressLine1 = $gbBankAccount->getOwnerAddress()->getAddressLine1();
82
        $bankAccount->OwnerAddress->AddressLine2 = $gbBankAccount->getOwnerAddress()->getAddressLine2();
83
        $bankAccount->OwnerAddress->City = $gbBankAccount->getOwnerAddress()->getCity();
84
        $bankAccount->OwnerAddress->Country = $gbBankAccount->getOwnerAddress()->getCountry();
85
        $bankAccount->OwnerAddress->PostalCode = $gbBankAccount->getOwnerAddress()->getPostalCode();
86
        $bankAccount->OwnerAddress->Region = $gbBankAccount->getOwnerAddress()->getRegion();
87
        return $bankAccount;
88
    }
89
90 View Code Duplication
    public function translateMangoToGbDto(BankAccount $bankAccount) : GbBankAccount
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...
91
    {
92
        $gbBankAccount = new GbBankAccount();
93
        $gbBankAccount->setTag($bankAccount->Tag);
94
        $gbBankAccount->setActive($bankAccount->Active);
95
        $gbBankAccount->setCreationDate($bankAccount->CreationDate);
96
        $gbBankAccount->setId($bankAccount->Id);
97
        $gbBankAccount->setUserId($bankAccount->UserId);
98
        $gbBankAccount->setOwnerName($bankAccount->OwnerName);
99
        $gbBankAccount->setType($bankAccount->Type);
100
        $gbBankAccount->setSortCode($bankAccount->Details->SortCode);
101
        $gbBankAccount->setAccountNumber($bankAccount->Details->AccountNumber);
102
        $gbBankAccount->setCreationDate($bankAccount->CreationDate);
103
104
105
        $address = new AddressDto();
106
        $address->setAddressLine1($bankAccount->OwnerAddress->AddressLine1);
107
        $address->setAddressLine2($bankAccount->OwnerAddress->AddressLine2);
108
        $address->setCity($bankAccount->OwnerAddress->City);
109
        $address->setCountry($bankAccount->OwnerAddress->Country);
110
        $address->setPostalCode($bankAccount->OwnerAddress->PostalCode);
111
        $address->setRegion($bankAccount->OwnerAddress->Region);
112
        $gbBankAccount->setOwnerAddress($address);
113
        return $gbBankAccount;
114
    }
115
}
116