Completed
Pull Request — master (#1)
by Dmitry
11:43 queued 10:09
created

InterKassaMerchant   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 56
Duplicated Lines 100 %

Coupling/Cohesion

Components 2
Dependencies 8

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 3
lcom 2
cbo 8
dl 56
loc 56
ccs 0
cts 19
cp 0
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A createGateway() 8 8 1
A requestPurchase() 17 17 1
A completePurchase() 13 13 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
namespace hiqdev\php\merchant\merchants\interkassa;
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\WebMoney\Gateway;
10
11
/**
12
 * Class PaxumMerchant
13
 *
14
 * @author Dmytro Naumenko <[email protected]>
15
 */
16 View Code Duplication
class InterKassaMerchant extends AbstractMerchant
0 ignored issues
show
Duplication introduced by
This class 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...
17
{
18
    /**
19
     * @var Gateway
20
     */
21
    protected $gateway;
22
23
    protected function createGateway()
24
    {
25
        return $this->gatewayFactory->build('InterKassa', [
26
            'checkoutId' => $this->credentials->getPurse(),
27
            'signKey'  => $this->credentials->getKey1(),
28
            'signAlgorithm' => 'md5'
29
        ]);
30
    }
31
32
    /**
33
     * @param InvoiceInterface $invoice
34
     * @return RedirectPurchaseResponse
35
     */
36
    public function requestPurchase(InvoiceInterface $invoice)
37
    {
38
        /**
39
         * @var \Omnipay\Paxum\Message\PurchaseResponse $response
40
         */
41
        $response = $this->gateway->purchase([
42
            'transactionId' => $invoice->getId(),
43
            'description' => $invoice->getDescription(),
44
            'amount' => $this->moneyFormatter->format($invoice->getAmount()),
45
            'currency' => $invoice->getCurrency()->getCode(),
46
            'returnUrl' => $invoice->getReturnUrl(),
47
            'notifyUrl' => $invoice->getNotifyUrl(),
48
            'cancelUrl' => $invoice->getCancelUrl(),
49
        ])->send();
50
51
        return new RedirectPurchaseResponse($response->getRedirectUrl(), $response->getRedirectData());
52
    }
53
54
    /**
55
     * @param array $data
56
     * @return CompletePurchaseResponse
57
     */
58
    public function completePurchase($data)
59
    {
60
        /** @var \Omnipay\InterKassa\Message\CompletePurchaseResponse $response */
61
        $response = $this->gateway->completePurchase($data)->send();
62
63
        return (new CompletePurchaseResponse())
64
            ->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...
65
            ->setAmount($this->moneyParser->parse($response->getAmount(), $response->getCurrency()))
66
            ->setTransactionReference($response->getTransactionReference())
67
            ->setTransactionId($response->getTransactionId())
68
            ->setPayer($response->getPayer())
69
            ->setTime((new \DateTime($response->getTime()))->setTimezone(new \DateTimeZone('UTC')));
70
    }
71
}
72