RequestToken   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 11
dl 0
loc 33
rs 10
c 1
b 0
f 0
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A get() 0 13 3
1
<?php
2
3
declare(strict_types=1);
4
5
namespace xiaodi\JWTAuth\Handle;
6
7
use think\App;
8
use xiaodi\JWTAuth\Exception\JWTException;
9
10
class RequestToken
11
{
12
    protected $handles = ['Header', 'Url', 'Cookie'];
13
14
    protected $token;
15
16
    protected $app;
17
18
    public function __construct(App $app)
19
    {
20
        $this->app = $app;
21
    }
22
23
    /**
24
     * 获取请求Token.
25
     *
26
     * @param string $handle
27
     *
28
     * @return string
29
     */
30
    public function get(string $handle): string
31
    {
32
        if (!in_array($handle, $this->handles)) {
33
            throw new JwtException('不支持此方式获取.', 500);
34
        }
35
36
        $this->token = (new Header($this->app))->handle();
37
38
        if (!$this->token) {
39
            throw new JwtException('获取Token失败.', 500);
40
        }
41
42
        return $this->token;
43
    }
44
}
45