Completed
Push — master ( c52910...66a65c )
by lyu
02:53 queued 47s
created

Paid   A

Complexity

Total Complexity 16

Size/Duplication

Total Lines 75
Duplicated Lines 66.67 %

Coupling/Cohesion

Components 2
Dependencies 2

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
dl 50
loc 75
ccs 0
cts 49
cp 0
rs 10
c 0
b 0
f 0
wmc 16
lcom 2
cbo 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A handle() 0 8 1
C validate() 50 50 15

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 Kaylyu\Alipay\F2fpay\Notify;
4
5
use Closure;
6
use Exception;
7
use Kaylyu\Alipay\F2fpay\Kernel\AopClient;
8
use Kaylyu\Alipay\Kernel\Support\Arr;
9
10
class Paid extends Handler
11
{
12
    /**
13
     * 入口
14
     * @param Closure $closure
15
     * @author kaylv <[email protected]>
16
     * @return string
17
     */
18
    public function handle(Closure $closure)
19
    {
20
        $this->strict(
21
            \call_user_func($closure, $this->getMessage(), [$this, 'fail'])
22
        );
23
24
        return $this->toResponse();
25
    }
26
27
    /**
28
     * 验签过程
29
     * @param $message
30
     * @author kaylv <[email protected]>
31
     * @return bool
32
     * @throws Exception
33
     */
34 View Code Duplication
    public function validate($message)
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
        $f2fpay = $this->app->getF2fpay();
38
39
        //获取配置参数
40
        $gatewayUrl = $f2fpay['gateway_url'];
41
        $appId = $f2fpay['app_id'];
42
        $signType = $f2fpay['sign_type'];
43
        $rsaPrivateKey = $f2fpay['merchant_private_key'];
44
        $alipayPublicKey = $f2fpay['alipay_public_key'];
45
        $charset = $f2fpay['charset'];
46
        $notifyUrl = $f2fpay['notify_url'];
47
48
        if (empty($appId) || trim($appId) == "") {
49
            throw new Exception("appid should not be NULL!");
50
        }
51
        if (empty($rsaPrivateKey) || trim($rsaPrivateKey) == "") {
52
            throw new Exception("merchant_private_key should not be NULL!");
53
        }
54
        if (empty($alipayPublicKey) || trim($alipayPublicKey) == "") {
55
            throw new Exception("alipay_public_key should not be NULL!");
56
        }
57
        if (empty($charset) || trim($charset) == "") {
58
            throw new Exception("charset should not be NULL!");
59
        }
60
        if (empty($notifyUrl) || trim($notifyUrl) == "") {
61
            throw new Exception("sign_type should not be NULL");
62
        }
63
        if (empty($gatewayUrl) || trim($gatewayUrl) == "") {
64
            throw new Exception("gateway_url should not be NULL");
65
        }
66
        if (empty($signType) || trim($signType) == "") {
67
            throw new Exception("sign_type should not be NULL");
68
        }
69
70
        //组装请求数据
71
        $aop = new AopClient();
72
        $aop->gatewayUrl = $gatewayUrl;
73
        $aop->appId =$appId;
74
        $aop->signType = $signType;
75
        $aop->rsaPrivateKey = $rsaPrivateKey;
76
        $aop->alipayrsaPublicKey = $alipayPublicKey;
77
        $aop->apiVersion = "1.0";
78
        $aop->charset = $charset;
0 ignored issues
show
Bug introduced by
The property charset does not seem to exist. Did you mean postCharset?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
79
        $aop->format = 'json';
80
81
        //验签
82
        return $aop->rsaCheckV2($message, null);
83
    }
84
}