Passed
Push — master ( 063541...448140 )
by Carl
05:22
created

PayInQuery   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 76
Duplicated Lines 72.37 %

Coupling/Cohesion

Components 1
Dependencies 8

Importance

Changes 0
Metric Value
wmc 11
lcom 1
cbo 8
dl 55
loc 76
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 11 1
B createPayInCardDirect() 27 27 5
B createBankWireDirectPayIn() 28 28 5

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:    19/01/2017
9
 * Time:    12:47
10
 * File:    PayInQuery.php
11
 **/
12
13
namespace PartFire\MangoPayBundle\Models\Adapters;
14
15
use MangoPay\PayIn;
16
use MangoPay\PayInStatus;
17
use PartFire\MangoPayBundle\Models\DTOs\BankwireDirectPayIn;
18
use PartFire\MangoPayBundle\Models\DTOs\CardDirectPayIn;
19
use PartFire\MangoPayBundle\Models\DTOs\Translators\PayInTranslator;
20
use PartFire\MangoPayBundle\Models\PayInQueryInterface;
21
use Symfony\Bridge\Monolog\Logger;
22
use PartFire\MangoPayBundle\Models\Exception as PartFireException;
23
use MangoPay\Libraries\Exception;
24
use MangoPay\Libraries\ResponseException;
25
use MangoPay\MangoPayApi;
26
27
class PayInQuery extends AbstractQuery implements PayInQueryInterface
28
{
29
    /**
30
     * @var PayInTranslator
31
     */
32
    private $payInTranslator;
33
34
    public function __construct(
35
        $clientId,
36
        $clientPassword,
37
        $baseUrl,
38
        MangoPayApi $mangoPayApi,
39
        Logger $logger,
40
        PayInTranslator $payInTranslator
41
    ) {
42
        parent::__construct($clientId, $clientPassword, $baseUrl, $mangoPayApi, $logger);
43
        $this->payInTranslator = $payInTranslator;
44
    }
45
46 View Code Duplication
    public function createPayInCardDirect(CardDirectPayIn $cardDirectPayIn) : CardDirectPayIn
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
            $payIn = $this->payInTranslator->translateDtoToMangoPayInForDirectPayIn($cardDirectPayIn);
50
            $createdPayIn = $this->mangoPayApi->PayIns->Create($payIn);
51
52
            if ($createdPayIn instanceof PayIn) {
53
                if ($createdPayIn->Status == PayInStatus::Succeeded) {
54
                    return $this->payInTranslator->translateMangoPayDirectPayInToDto($createdPayIn);
55
                }
56
                $this->logger->addCritical(
57
                    "Pay-In has been created with status: ".$createdPayIn->Status . ' (result code: ' . $createdPayIn->ResultCode . ')'
58
                );
59
                throw new PartFireException(
60
                    "Pay-In has been created with status: ".$createdPayIn->Status . ' (result code: ' . $createdPayIn->ResultCode . ')'
61
                );
62
            }
63
            $this->logger->addCritical("Failed to create PayIn");
64
            throw new PartFireException("Failed to create PayIn");
65
        } catch (ResponseException $e) {
66
            $this->logger->addCritical($e->getMessage(), ['code' => $e->getCode(), 'details' => $e->GetErrorDetails()]);
67
            throw new PartFireException($e->getMessage(), $e->getCode(), $e);
68
        } catch (Exception $e) {
69
            $this->logger->addError($e->getMessage());
70
            throw new PartFireException($e->getMessage(), $e->getCode(), $e);
71
        }
72
    }
73
74 View Code Duplication
    public function createBankWireDirectPayIn(BankwireDirectPayIn $bankwireDirectPayIn) : BankwireDirectPayIn
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...
75
    {
76
        try {
77
            $payIn = $this->payInTranslator->translateDtoToMangoPayInForBankwireDirectPayIn($bankwireDirectPayIn);
78
            $createdPayIn = $this->mangoPayApi->PayIns->Create($payIn);
79
80
            if ($createdPayIn instanceof PayIn) {
81
82
                if ($createdPayIn->Status == PayInStatus::Created) {
83
                    return $this->payInTranslator->translateMangoPayBankwireDirectPayInToDto($createdPayIn);
84
                }
85
                $this->logger->addCritical(
86
                    "Pay-In has been created with status: ".$createdPayIn->Status . ' (result code: ' . $createdPayIn->ResultCode . ')'
87
                );
88
                throw new PartFireException(
89
                    "Pay-In has been created with status: ".$createdPayIn->Status . ' (result code: ' . $createdPayIn->ResultCode . ')'
90
                );
91
            }
92
            $this->logger->addCritical("Failed to create PayIn");
93
            throw new PartFireException("Failed to create PayIn");
94
        } catch (ResponseException $e) {
95
            $this->logger->addCritical($e->getMessage(), ['code' => $e->getCode(), 'details' => $e->GetErrorDetails()]);
96
            throw new PartFireException($e->getMessage(), $e->getCode(), $e);
97
        } catch (Exception $e) {
98
            $this->logger->addError($e->getMessage());
99
            throw new PartFireException($e->getMessage(), $e->getCode(), $e);
100
        }
101
    }
102
}
103