Completed
Push — master ( 158640...6228b6 )
by Carlos
02:38 queued 01:15
created

Scanned::alert()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 1
dl 0
loc 6
rs 9.4285
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 Symfony\Component\HttpFoundation\Response;
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
     * @return $this
29
     */
30
    public function alert(string $message)
31
    {
32
        $this->alert = $message;
33
34
        return $this;
35
    }
36
37
    /**
38
     * @param callable $callback
39
     *
40
     * @return \Symfony\Component\HttpFoundation\Response
41
     */
42
    public function handle(callable $callback): Response
43
    {
44
        $result = $callback->__invoke($this->getMessage(), [$this, 'fail'], [$this, 'alert']);
0 ignored issues
show
Bug introduced by
The method __invoke cannot be called on $callback (of type callable).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
45
46
        $attributes = [
47
            'result_code' => is_null($this->alert) && is_null($this->fail) ? static::SUCCESS : static::FAIL,
48
            'err_code_des' => $this->alert,
49
        ];
50
51
        if (is_null($this->alert) && is_string($result)) {
52
            $attributes += [
53
                'appid' => $this->app['config']->app_id,
54
                'mch_id' => $this->app['config']->mch_id,
55
                'nonce_str' => uniqid(),
56
                'prepay_id' => $result,
57
            ];
58
        }
59
60
        return $this->respondWith($attributes, true)->toResponse();
61
    }
62
}
63