BankAccountQuery::getAll()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 1
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:10
10
 * File:    BankAccountQuery.php
11
 **/
12
13
namespace PartFire\MangoPayBundle\Models\Adapters;
14
15
use MangoPay\BankAccount;
16
use PartFire\MangoPayBundle\Models\BankAccountQueryInterface;
17
use PartFire\MangoPayBundle\Models\DTOs\AbstractBankAccount;
18
use PartFire\MangoPayBundle\Models\DTOs\GbBankAccount;
19
use PartFire\MangoPayBundle\Models\DTOs\IbanBankAccount;
20
use MangoPay\MangoPayApi;
21
use PartFire\MangoPayBundle\Models\DTOs\Translators\BankAccountTranslator;
22
use Symfony\Bridge\Monolog\Logger;
23
use PartFire\MangoPayBundle\Models\Exception as PartFireException;
24
use MangoPay\Libraries\Exception;
25
use MangoPay\Libraries\ResponseException;
26
27
class BankAccountQuery extends AbstractQuery implements BankAccountQueryInterface
28
{
29
    /**
30
     * @var BankAccountTranslator
31
     */
32
    private $bankAccountTranslator;
33
34
    public function __construct(
35
        $clientId,
36
        $clientPassword,
37
        $baseUrl,
38
        MangoPayApi $mangoPayApi,
39
        Logger $logger,
40
        BankAccountTranslator $bankAccountTranslator
41
    ) {
42
        parent::__construct($clientId, $clientPassword, $baseUrl, $mangoPayApi, $logger);
43
        $this->bankAccountTranslator = $bankAccountTranslator;
44
    }
45
46 View Code Duplication
    public function createIbanBankAccount(IbanBankAccount $ibanBankAccount): 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...
47
    {
48
        try {
49
            $bankAccount = $this->bankAccountTranslator->translateIbanDtoToMango($ibanBankAccount);
50
            $bankAccount = $this->mangoPayApi->Users->CreateBankAccount($ibanBankAccount->getUserId(), $bankAccount);
51
            if ($bankAccount instanceof BankAccount) {
52
                return $this->bankAccountTranslator->translateMangoToIbanDto($bankAccount);
53
            }
54
            $this->logger->addCritical("Bank account not created when querying API.");
55
            throw new PartFireException("Bank account not created when querying API.");
56
        } catch (ResponseException $e) {
57
            $this->logger->addCritical($e->getMessage(), ['code' => $e->getCode(), 'details' => $e->GetErrorDetails()]);
58
            throw new PartFireException($e->getMessage(), $e->getCode(), $e);
59
        } catch (Exception $e) {
60
            $this->logger->addError($e->getMessage());
61
            throw new PartFireException($e->getMessage(), $e->getCode(), $e);
62
        }
63
    }
64
65 View Code Duplication
    public function createGbBankAccount(GbBankAccount $gbBankAccount) : 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...
66
    {
67
        try {
68
            $bankAccount = $this->bankAccountTranslator->translateGbDtoToMango($gbBankAccount);
69
            $bankAccount = $this->mangoPayApi->Users->CreateBankAccount($gbBankAccount->getUserId(), $bankAccount);
70
            if ($bankAccount instanceof BankAccount) {
71
                return $this->bankAccountTranslator->translateMangoToGbDto($bankAccount);
72
            }
73
            $this->logger->addCritical("Bank account not created when querying API.");
74
            throw new PartFireException("Bank account not created when querying API.");
75
        } catch (ResponseException $e) {
76
            $this->logger->addCritical($e->getMessage(), ['code' => $e->getCode(), 'details' => $e->GetErrorDetails()]);
77
            throw new PartFireException($e->getMessage(), $e->getCode(), $e);
78
        } catch (Exception $e) {
79
            $this->logger->addError($e->getMessage());
80
            throw new PartFireException($e->getMessage(), $e->getCode(), $e);
81
        }
82
    }
83
84 View Code Duplication
    public function deactivate($userId, $bankAccountId) : bool
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...
85
    {
86
        try {
87
            $bankAccount = $this->mangoPayApi->Users->UpdateBankAccount($userId, $bankAccountId);
88
            if ($bankAccount instanceof BankAccount) {
89
                return true;
90
            }
91
            $this->logger->addCritical("Bank account not deactivated when querying API.");
92
            throw new PartFireException("Bank account not deactivated when querying API.");
93
        } catch (ResponseException $e) {
94
            $this->logger->addCritical($e->getMessage(), ['code' => $e->getCode(), 'details' => $e->GetErrorDetails()]);
95
            throw new PartFireException($e->getMessage(), $e->getCode(), $e);
96
        } catch (Exception $e) {
97
            $this->logger->addError($e->getMessage());
98
            throw new PartFireException($e->getMessage(), $e->getCode(), $e);
99
        }
100
    }
101
102
    /**
103
     * @param $userId
104
     * @param $bankAccountId
105
     * @return AbstractBankAccount
106
     * @throws PartFireException
107
     */
108 View Code Duplication
    public function get($userId, $bankAccountId) : AbstractBankAccount
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...
109
    {
110
        try {
111
            $bankAccount = $this->mangoPayApi->Users->GetBankAccount($userId, $bankAccountId);
112
            if ($bankAccount instanceof BankAccount) {
113
                if ($bankAccount->Type == 'IBAN') {
114
                    return $this->bankAccountTranslator->translateMangoToIbanDto($bankAccount);
115
                }
116
                return $this->bankAccountTranslator->translateMangoToGbDto($bankAccount);
117
            }
118
            $this->logger->addCritical("Bank account not deactivated when querying API.");
119
            throw new PartFireException("Bank account not deactivated when querying API.");
120
        } catch (ResponseException $e) {
121
            $this->logger->addCritical($e->getMessage(), ['code' => $e->getCode(), 'details' => $e->GetErrorDetails()]);
122
            throw new PartFireException($e->getMessage(), $e->getCode(), $e);
123
        } catch (Exception $e) {
124
            $this->logger->addError($e->getMessage());
125
            throw new PartFireException($e->getMessage(), $e->getCode(), $e);
126
        }
127
    }
128
129
    public function getAll($userId)
130
    {
131
        // TODO: Implement getAll() method.
132
    }
133
}