Completed
Push — master ( c25059...aa3601 )
by i
04:27
created

AppPayment::toPay()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 18
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 13
nc 1
nop 2
dl 0
loc 18
ccs 0
cts 16
cp 0
crap 2
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace Nilnice\Payment\Wechat;
4
5
use Illuminate\Support\Str;
6
use Nilnice\Payment\Constant;
7
use Nilnice\Payment\Log;
8
use Symfony\Component\HttpFoundation\JsonResponse;
9
use Symfony\Component\HttpFoundation\Response;
10
11
class AppPayment extends AbstractWechat
12
{
13
    /**
14
     * Use app to pay for order.
15
     *
16
     * @param string $gateway
17
     * @param array  $payload
18
     *
19
     * @return \Symfony\Component\HttpFoundation\Response
20
     *
21
     * @throws \InvalidArgumentException
22
     * @throws \Nilnice\Payment\Exception\GatewayException
23
     * @throws \Nilnice\Payment\Exception\InvalidKeyException
24
     * @throws \Nilnice\Payment\Exception\InvalidSignException
25
     * @throws \RuntimeException
26
     */
27
    public function toPay(string $gateway, array $payload) : Response
28
    {
29
        $payload['trade_type'] = Constant::WX_PAY_APP_TYPE;
30
        $object = $this->prepare(Constant::WX_PAY_PREPARE, $payload, 'app');
0 ignored issues
show
Unused Code introduced by
The call to Nilnice\Payment\Wechat\AbstractWechat::prepare() has too many arguments starting with 'app'. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

30
        /** @scrutinizer ignore-call */ 
31
        $object = $this->prepare(Constant::WX_PAY_PREPARE, $payload, 'app');

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
31
        $key = $this->config->get('key');
32
        $parameter = [
33
            'appid'     => $payload['appid'],
34
            'partnerid' => $payload['mch_id'],
35
            'prepayid'  => $object->get('prepay_id'),
36
            'timestamp' => (string)time(),
37
            'noncestr'  => Str::random(),
38
            'package'   => 'Sign=WXPay',
39
        ];
40
        $parameter['sign'] = self::generateSign($parameter, $key);
41
42
        Log::debug('App order:', [$gateway, $payload]);
43
44
        return JsonResponse::create($parameter);
45
    }
46
}
47