Completed
Push — master ( 5b0350...3befdd )
by Andrii
15:04
created

CoinGateMerchant::requestPurchase()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 24

Duplication

Lines 24
Ratio 100 %

Importance

Changes 0
Metric Value
dl 24
loc 24
rs 9.536
c 0
b 0
f 0
cc 2
nc 2
nop 1
1
<?php
2
3
namespace hiqdev\php\merchant\merchants\coingate;
4
5
use hiqdev\php\merchant\InvoiceInterface;
6
use hiqdev\php\merchant\merchants\AbstractMerchant;
7
use hiqdev\php\merchant\response\CompletePurchaseResponse;
8
use hiqdev\php\merchant\response\RedirectPurchaseResponse;
9
use Omnipay\CoinGate\Gateway;
10
11
/**
12
 * Class CoinGateMerchant.
13
 *
14
 * @author Yurii Myronchuk <[email protected]>
15
 */
16
class CoinGateMerchant extends AbstractMerchant
17
{
18
    /**
19
     * @var Gateway
20
     */
21
    protected $gateway;
22
23
    protected function createGateway()
24
    {
25
        return $this->gatewayFactory->build('CoinGate', [
26
            'apiKey'  => $this->credentials->getKey1(),
27
           ]);
28
    }
29
30
    /**
31
     * @param InvoiceInterface $invoice
32
     * @return RedirectPurchaseResponse
33
     */
34 View Code Duplication
    public function requestPurchase(InvoiceInterface $invoice)
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...
35
    {
36
        /**
37
         * @var \Omnipay\CoinGate\Message\PurchaseResponse $response
38
         */
39
        $response = $this->gateway->purchase([
40
            'transactionId' => $invoice->getId(),
41
            'currency' => $invoice->getCurrency()->getCode(),
42
            'description' => $invoice->getDescription(),
43
            'amount' => $this->moneyFormatter->format($invoice->getAmount()),
44
            'returnUrl' => $invoice->getReturnUrl(),
45
            'cancelUrl' => $invoice->getCancelUrl(),
46
            'notifyUrl' => $invoice->getNotifyUrl(),
47
        ])->send();
48
49
        if ($response->getRedirectUrl() === null) {
50
            throw new MerchantException('Failed to request purchase');
51
        }
52
53
        $response = new RedirectPurchaseResponse($response->getRedirectUrl(), $response->getRedirectData());
0 ignored issues
show
Documentation introduced by
$response->getRedirectData() is of type null, but the function expects a array.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
54
        $response->setMethod('GET');
55
56
        return $response;
57
    }
58
59
    /**
60
     * @param array $data
61
     * @return CompletePurchaseResponse
62
     */
63
    public function completePurchase($data)
64
    {
65
        /** @var \Omnipay\CoinGate\Message\CompletePurchaseResponse $response */
66
        $response = $this->gateway->completePurchase($data)->send();
0 ignored issues
show
Bug introduced by
The method completePurchase() does not exist on Omnipay\CoinGate\Gateway. Did you maybe mean purchase()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
67
68
        return (new CompletePurchaseResponse())
69
            ->setIsSuccessful($response->isSuccessful())
0 ignored issues
show
Documentation introduced by
$response->isSuccessful() is of type boolean, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
70
            ->setAmount($this->moneyParser->parse($response->getAmount(), $response->getCurrency()))
0 ignored issues
show
Bug introduced by
The method getAmount() does not seem to exist on object<Omnipay\CoinGate\...mpletePurchaseResponse>.

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...
Bug introduced by
The method getCurrency() does not seem to exist on object<Omnipay\CoinGate\...mpletePurchaseResponse>.

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...
71
            ->setTransactionReference($response->getTransactionReference())
72
            ->setTransactionId($response->getTransactionId())
73
            ->setPayer($response->getPayer())
0 ignored issues
show
Bug introduced by
The method getPayer() does not seem to exist on object<Omnipay\CoinGate\...mpletePurchaseResponse>.

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...
74
            ->setTime(new \DateTime($response->getTime()));
0 ignored issues
show
Bug introduced by
The method getTime() does not seem to exist on object<Omnipay\CoinGate\...mpletePurchaseResponse>.

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...
75
    }
76
}
77