Scanned::handle()   A
last analyzed

Complexity

Conditions 5
Paths 8

Size

Total Lines 19
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 10
CRAP Score 5

Importance

Changes 0
Metric Value
cc 5
eloc 11
nc 8
nop 1
dl 0
loc 19
ccs 10
cts 10
cp 1
crap 5
rs 9.6111
c 0
b 0
f 0
1
<?php
2
3
/*
4
 * This file is part of the overtrue/wechat.
5
 *
6
 * (c) overtrue <[email protected]>
7
 *
8
 * This source file is subject to the MIT license that is bundled
9
 * with this source code in the file LICENSE.
10
 */
11
12
namespace EasyWeChat\Payment\Notify;
13
14
use Closure;
15
16
class Scanned extends Handler
17
{
18
    protected $check = false;
19
20
    /**
21
     * @var string|null
22
     */
23
    protected $alert;
24
25
    /**
26
     * @param string $message
27
     */
28 1
    public function alert(string $message)
29
    {
30 1
        $this->alert = $message;
31 1
    }
32
33
    /**
34
     * @param \Closure $closure
35
     *
36
     * @return \Symfony\Component\HttpFoundation\Response
37
     *
38
     * @throws \EasyWeChat\Kernel\Exceptions\Exception
39
     */
40 2
    public function handle(Closure $closure)
41
    {
42 2
        $result = \call_user_func($closure, $this->getMessage(), [$this, 'fail'], [$this, 'alert']);
43
44
        $attributes = [
45 2
            'result_code' => is_null($this->alert) && is_null($this->fail) ? static::SUCCESS : static::FAIL,
46 2
            'err_code_des' => $this->alert,
47
        ];
48
49 2
        if (is_null($this->alert) && is_string($result)) {
50
            $attributes += [
51 1
                'appid' => $this->app['config']->app_id,
52 1
                'mch_id' => $this->app['config']->mch_id,
53 1
                'nonce_str' => uniqid(),
54 1
                'prepay_id' => $result,
55
            ];
56
        }
57
58 2
        return $this->respondWith($attributes, true)->toResponse();
59
    }
60
}
61