Completed
Push — master ( 259fd8...a43b07 )
by Andrii
03:33
created

EPayServiceMerchant   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 59
Duplicated Lines 100 %

Coupling/Cohesion

Components 2
Dependencies 13

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
lcom 2
cbo 13
dl 59
loc 59
ccs 25
cts 25
cp 1
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
 * Generalization over Omnipay and Payum
4
 *
5
 * @link      https://github.com/hiqdev/php-merchant
6
 * @package   php-merchant
7
 * @license   BSD-3-Clause
8
 * @copyright Copyright (c) 2015-2017, HiQDev (http://hiqdev.com/)
9
 */
10
11
namespace hiqdev\php\merchant\merchants\epayservice;
12
13
use hiqdev\php\merchant\InvoiceInterface;
14
use hiqdev\php\merchant\merchants\AbstractMerchant;
15
use hiqdev\php\merchant\response\CompletePurchaseResponse;
16
use hiqdev\php\merchant\response\RedirectPurchaseResponse;
17
18
/**
19
 * Class EPayServiceMerchant.
20
 *
21
 * @author Dmytro Naumenko <[email protected]>
22
 */
23 View Code Duplication
class EPayServiceMerchant 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...
24
{
25
    /**
26
     * @var \Omnipay\ePayService\Gateway
27
     */
28
    protected $gateway;
29
30
    /**
31
     * @return \Omnipay\Common\GatewayInterface
32
     */
33 3
    protected function createGateway()
34
    {
35 3
        return $this->gatewayFactory->build('ePayService', [
36 3
            'purse' => $this->credentials->getPurse(),
37 3
            'secret'  => $this->credentials->getKey1(),
38 3
            'signAlgorithm' => 'sha256',
39
        ]);
40
    }
41
42
    /**
43
     * @param InvoiceInterface $invoice
44
     * @return RedirectPurchaseResponse
45
     */
46 1
    public function requestPurchase(InvoiceInterface $invoice)
47
    {
48
        /**
49
         * @var \Omnipay\Paxum\Message\PurchaseResponse
50
         */
51 1
        $response = $this->gateway->purchase([
52 1
            'transactionId' => $invoice->getId(),
53 1
            'description' => $invoice->getDescription(),
54 1
            'amount' => $this->moneyFormatter->format($invoice->getAmount()),
55 1
            'currency' => $invoice->getCurrency()->getCode(),
56 1
            'returnUrl' => $invoice->getReturnUrl(),
57 1
            'notifyUrl' => $invoice->getNotifyUrl(),
58 1
            'cancelUrl' => $invoice->getCancelUrl(),
59 1
        ])->send();
60
61 1
        return new RedirectPurchaseResponse($response->getRedirectUrl(), $response->getRedirectData());
62
    }
63
64
    /**
65
     * @param array $data
66
     * @return CompletePurchaseResponse
67
     */
68 1
    public function completePurchase($data)
69
    {
70
        /** @var \Omnipay\ePayService\Message\CompletePurchaseResponse $response */
71 1
        $response = $this->gateway->completePurchase($data)->send();
72
73 1
        return (new CompletePurchaseResponse())
74 1
            ->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...
75 1
            ->setAmount($this->moneyParser->parse($response->getAmount(), $response->getCurrency()))
76 1
            ->setTransactionReference($response->getTransactionReference())
77 1
            ->setTransactionId($response->getTransactionId())
78 1
            ->setPayer($response->getData()['EPS_ACCNUM'])
79 1
            ->setTime((new \DateTime())->setTimezone(new \DateTimeZone('UTC')));
80
    }
81
}
82