Completed
Push — master ( 332770...076a6e )
by Guillaume
05:49
created

JwtMiddleware   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 52
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 2
c 1
b 0
f 0
lcom 0
cbo 1
dl 0
loc 52
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A __invoke() 0 16 1
1
<?php
2
3
namespace Eljam\GuzzleJwt;
4
5
use Eljam\GuzzleJwt\Manager\JwtManager;
6
use Psr\Http\Message\RequestInterface;
7
8
/**
9
 * @author Guillaume Cavana <[email protected]>
10
 */
11
class JwtMiddleware
12
{
13
    const AUTH_BEARER = 'Bearer %s';
14
15
    /**
16
     * $token.
17
     *
18
     * @var JwtToken
19
     */
20
    protected $token;
21
22
    /**
23
     * $JwtManager.
24
     *
25
     * @var JwtManager
26
     */
27
    protected $JwtManager;
28
29
    /**
30
     * Constructor.
31
     *
32
     * @param JwtManager $jwtManager
33
     */
34
    public function __construct(JwtManager $jwtManager)
35
    {
36
        $this->jwtManager = $jwtManager;
0 ignored issues
show
Bug introduced by
The property jwtManager does not seem to exist. Did you mean JwtManager?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
37
    }
38
39
    /**
40
     * Called when the middleware is handled by the client.
41
     *
42
     * @param callable $handler
43
     *
44
     * @return Closure
45
     */
46
    public function __invoke(callable $handler)
47
    {
48
        $token = $this->jwtManager->getJwtToken()->getToken();
0 ignored issues
show
Bug introduced by
The property jwtManager does not seem to exist. Did you mean JwtManager?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
49
50
        return function (
51
            RequestInterface $request,
52
            array $options
53
        ) use (
54
            $handler,
55
            $token
56
        ) {
57
            $request = $request->withHeader('Authorization', sprintf(self::AUTH_BEARER, $token));
58
59
            return $handler($request, $options);
60
        };
61
    }
62
}
63