Completed
Pull Request — master (#1418)
by milkmeowo
04:24 queued 01:28
created

Guard::isSafeMode()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
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\OpenWork\Server;
13
14
use EasyWeChat\Kernel\Encryptor;
15
use EasyWeChat\Kernel\ServerGuard;
16
17
/**
18
 * Guard.
19
 *
20
 * @author xiaomin <[email protected]>
21
 */
22
class Guard extends ServerGuard
23
{
24
    /**
25
     * @var bool
26
     */
27
    protected $alwaysValidate = true;
28
29
    /**
30
     * @return bool
31
     */
32 1
    public function validate()
33
    {
34 1
        return $this;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this returns the type EasyWeChat\OpenWork\Server\Guard which is incompatible with the documented return type boolean.
Loading history...
35
    }
36
37
    /**
38
     * @return bool
39
     */
40 1
    protected function shouldReturnRawResponse(): bool
41
    {
42 1
        return !is_null($this->app['request']->get('echostr'));
43
    }
44
45 1
    protected function isSafeMode(): bool
46
    {
47 1
        return true;
48
    }
49
50
    /**
51
     * @param array $message
52
     *
53
     * @return mixed
54
     *
55
     * @throws \EasyWeChat\Kernel\Exceptions\RuntimeException
56
     */
57 1
    protected function decryptMessage(array $message)
58
    {
59 1
        $encryptor = new Encryptor($message['ToUserName'], $this->app['config']->get('token'), $this->app['config']->get('aes_key'));
60
61 1
        return $message = $encryptor->decrypt(
0 ignored issues
show
Unused Code introduced by
The assignment to $message is dead and can be removed.
Loading history...
62 1
            $message['Encrypt'],
63 1
            $this->app['request']->get('msg_signature'),
64 1
            $this->app['request']->get('nonce'),
65 1
            $this->app['request']->get('timestamp')
66
        );
67
    }
68
}
69