Completed
Push — master ( bf6fd0...fe0998 )
by i
04:47
created

WapPayment::toPay()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 12
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 2.9765

Importance

Changes 0
Metric Value
cc 2
eloc 8
nc 2
nop 2
dl 0
loc 12
ccs 3
cts 8
cp 0.375
crap 2.9765
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace Nilnice\Payment\Wechat;
4
5
use Nilnice\Payment\Constant;
6
7
class WapPayment extends AbstractWechat
8
{
9
    /**
10
     * To pay.
11
     *
12
     * @param string $gateway
13
     * @param array  $payload
14
     *
15
     * @throws \InvalidArgumentException
16
     * @throws \Nilnice\Payment\Exception\GatewayException
17
     * @throws \Nilnice\Payment\Exception\InvalidKeyException
18
     * @throws \Nilnice\Payment\Exception\InvalidSignException
19
     * @throws \RuntimeException
20
     */
21 3
    public function toPay(string $gateway, array $payload)
22
    {
23 3
        $payload['trade_type'] = Constant::WX_PAY_WAP_TYPE;
24 3
        $object = $this->prepare(Constant::WX_PAY_PREPARE_URI, $payload);
25
        $returnUrl = $this->config->get('return_url');
26
27
        if (null === $returnUrl) {
28
            $url = $object->url;
29
        } else {
30
            $url = $object->url . '&redirect_url=' . urlencode($returnUrl);
0 ignored issues
show
Bug introduced by
Are you sure $object->url of type Illuminate\Support\HigherOrderCollectionProxy can be used in concatenation? Consider adding a __toString()-method. ( Ignorable by Annotation )

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

30
            $url = /** @scrutinizer ignore-type */ $object->url . '&redirect_url=' . urlencode($returnUrl);
Loading history...
31
        }
32
        echo $url;
0 ignored issues
show
Bug introduced by
Are you sure $url of type Illuminate\Support\Highe...rCollectionProxy|string can be used in echo? ( Ignorable by Annotation )

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

32
        echo /** @scrutinizer ignore-type */ $url;
Loading history...
33
    }
34
}
35