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

RouteParams::setKey()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 6
ccs 0
cts 3
cp 0
rs 9.4285
cc 1
eloc 3
nc 1
nop 1
crap 2
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