Passed
Push — master ( 8392a0...119f32 )
by
unknown
02:41
created

TransferQuery::get()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 13
Code Lines 10

Duplication

Lines 13
Ratio 100 %

Importance

Changes 0
Metric Value
dl 13
loc 13
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 10
nc 3
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:    06/12/2016
9
 * Time:    22:41
10
 * File:    TransferQuery.php
11
 **/
12
13
namespace PartFire\MangoPayBundle\Models\Adapters;
14
15
use PartFire\MangoPayBundle\Models\DTOs\Transfer;
16
use PartFire\MangoPayBundle\Models\DTOs\Translators\TransferTranslator;
17
use PartFire\MangoPayBundle\Models\TransferQueryInterface;
18
use MangoPay\Libraries\ResponseException;
19
use MangoPay\Libraries\Exception;
20
use PartFire\MangoPayBundle\Models\Exception as PartFireException;
21
use Symfony\Bridge\Monolog\Logger;
22
use MangoPay\MangoPayApi;
23
24
class TransferQuery extends AbstractQuery implements TransferQueryInterface
25
{
26
    /**
27
     * @var TransferTranslator
28
     */
29
    protected $transferTranslator;
30
31
    /**
32
     * TransferQuery constructor.
33
     * @param $clientId
34
     * @param $clientPassword
35
     * @param $baseUrl
36
     * @param MangoPayApi $mangoPayApi
37
     * @param Logger $logger
38
     * @param TransferTranslator $transferTranslator
39
     */
40
    public function __construct(
41
        $clientId,
42
        $clientPassword,
43
        $baseUrl,
44
        MangoPayApi $mangoPayApi,
45
        Logger $logger,
46
        TransferTranslator $transferTranslator
47
    ) {
48
        parent::__construct($clientId, $clientPassword, $baseUrl, $mangoPayApi, $logger);
49
        $this->transferTranslator = $transferTranslator;
50
    }
51
52
    /**
53
     * @param Transfer $transferDto
54
     * @return Transfer|PartFireException
55
     */
56 View Code Duplication
    public function create(Transfer $transferDto)
57
    {
58
        $mangoTransfer = $this->transferTranslator->convertDTOToMangoPayTransfer($transferDto);
59
        try {
60
            $mangoTransfer = $this->mangoPayApi->Transfers->Create($mangoTransfer);
61
        } catch (ResponseException $e) {
62
            $this->logger->addCritical($e->getMessage(), ['code' => $e->getCode(), 'details' => $e->GetErrorDetails()]);
63
            return new PartFireException($e->getMessage(), $e->getCode());
64
        } catch (Exception $e) {
65
            $this->logger->addError($e->getMessage());
66
            return new PartFireException($e->getMessage(), $e->getCode());
67
        }
68
        return $this->transferTranslator->convertMangoPayTransferToDTO($mangoTransfer);
69
    }
70
71 View Code Duplication
    public function get(string $transferId) : Transfer
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...
72
    {
73
        try {
74
            $mangoTransfer = $this->mangoPayApi->Transfers->Get($transferId);
75
        } catch (ResponseException $e) {
76
            $this->logger->addCritical($e->getMessage(), ['code' => $e->getCode(), 'details' => $e->GetErrorDetails()]);
77
            return new PartFireException($e->getMessage(), $e->getCode());
78
        } catch (Exception $e) {
79
            $this->logger->addError($e->getMessage());
80
            return new PartFireException($e->getMessage(), $e->getCode());
81
        }
82
        return $this->transferTranslator->convertMangoPayKycDocumentToDTO($mangoTransfer);
0 ignored issues
show
Bug introduced by
The method convertMangoPayKycDocumentToDTO() does not seem to exist on object<PartFire\MangoPay...ors\TransferTranslator>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
83
    }
84
}
85