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

BankAccountTranslator   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 93
Duplicated Lines 52.69 %

Coupling/Cohesion

Components 0
Dependencies 7

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
c 1
b 0
f 0
lcom 0
cbo 7
dl 49
loc 93
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A translateIbanDtoToMango() 0 17 1
B translateMangoToIbanDto() 24 24 1
A translateGbDtoToMango() 0 17 1
B translateMangoToGbDto() 25 25 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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