Completed
Push — develop ( 7b8c01...54328c )
by Sean
02:43
created

RouteParams   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 62.5%

Importance

Changes 3
Bugs 0 Features 0
Metric Value
wmc 3
c 3
b 0
f 0
lcom 1
cbo 1
dl 0
loc 42
ccs 5
cts 8
cp 0.625
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A parse() 0 11 2
A setKey() 0 6 1
1
<?php
2
3
/*
4
 * This file is part of jwt-auth
5
 *
6
 * (c) Sean Tymon <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Tymon\JWTAuth\Http;
13
14
use Illuminate\Http\Request;
15
use Tymon\JWTAuth\Contracts\Http\Parser as ParserContract;
16
17
class RouteParams implements ParserContract
18
{
19
    /**
20
     * The route param key
21
     *
22
     * @var string
23
     */
24
    protected $key = 'token';
25
26
    /**
27
     * Try to get the token from the route parameters
28
     *
29
     * @param  \Illuminate\Http\Request
30
     *
31
     * @return null|string
32
     */
33 8
    public function parse(Request $request)
34
    {
35 8
        $route = $request->route();
36
        
37 8
        if (! is_callable([$route, 'parameter'])) {
38
            // Route may not be an instance of Illuminate\Routing\Route (it's an array
39
            // in Lumen <5.2) or not exist at all (if the request was never dispatched)
40 4
            return null;
41
        }
42 4
        return $route->parameter($this->key);
43
    }
44
45
    /**
46
     * Set the query string key
47
     *
48
     * @param  string  $key
49
     *
50
     * @return RouteParams
51
     */
52
    public function setKey($key)
53
    {
54
        $this->key = $key;
55
56
        return $this;
57
    }
58
}
59