Completed
Pull Request — master (#1418)
by milkmeowo
03:01
created

Guard   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 11
dl 0
loc 44
ccs 13
cts 13
cp 1
rs 10
c 0
b 0
f 0
wmc 4

4 Methods

Rating   Name   Duplication   Size   Complexity  
A decryptMessage() 0 9 1
A shouldReturnRawResponse() 0 3 1
A validate() 0 3 1
A isSafeMode() 0 3 1
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