Completed
Push — master ( a9c6ec...e2169c )
by Songda
01:29
created

PosGateway   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 34
Duplicated Lines 29.41 %

Coupling/Cohesion

Components 0
Dependencies 4

Importance

Changes 0
Metric Value
wmc 2
lcom 0
cbo 4
dl 10
loc 34
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getTradeType() 0 4 1
A pay() 10 10 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 Yansongda\Pay\Gateways\Wechat;
4
5
use Yansongda\Pay\Events;
6
use Yansongda\Pay\Exceptions\GatewayException;
7
use Yansongda\Pay\Exceptions\InvalidArgumentException;
8
use Yansongda\Pay\Exceptions\InvalidSignException;
9
use Yansongda\Supports\Collection;
10
11
class PosGateway extends Gateway
12
{
13
    /**
14
     * Pay an order.
15
     *
16
     * @author yansongda <[email protected]>
17
     *
18
     * @param string $endpoint
19
     *
20
     * @throws GatewayException
21
     * @throws InvalidArgumentException
22
     * @throws InvalidSignException
23
     */
24 View Code Duplication
    public function pay($endpoint, array $payload): Collection
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...
25
    {
26
        unset($payload['trade_type'], $payload['notify_url']);
27
28
        $payload['sign'] = Support::generateSign($payload);
29
30
        Events::dispatch(new Events\PayStarted('Wechat', 'Pos', $endpoint, $payload));
31
32
        return Support::requestApi('pay/micropay', $payload);
33
    }
34
35
    /**
36
     * Get trade type config.
37
     *
38
     * @author yansongda <[email protected]>
39
     */
40
    protected function getTradeType(): string
41
    {
42
        return 'MICROPAY';
43
    }
44
}
45