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

Paid::validate()   C

Complexity

Conditions 15
Paths 8

Size

Total Lines 50

Duplication

Lines 50
Ratio 100 %

Code Coverage

Tests 0
CRAP Score 240

Importance

Changes 0
Metric Value
cc 15
nc 8
nop 1
dl 50
loc 50
ccs 0
cts 42
cp 0
crap 240
rs 5.9166
c 0
b 0
f 0

How to fix   Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

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
}