1 | <?php |
||
12 | class AuthHandler |
||
13 | { |
||
14 | const TOKEN_ATTRIBUTE = 'spark/auth:token'; |
||
15 | |||
16 | /** |
||
17 | * @var \Equip\Auth\Token\ExtractorInterface |
||
18 | */ |
||
19 | protected $token; |
||
20 | |||
21 | /** |
||
22 | * @var \Equip\Auth\Credentials\ExtractorInterface |
||
23 | */ |
||
24 | protected $credentials; |
||
25 | |||
26 | /** |
||
27 | * @var AdapterInterface |
||
28 | */ |
||
29 | protected $adapter; |
||
30 | |||
31 | /** |
||
32 | * @var RequestFilterInterface |
||
33 | */ |
||
34 | protected $filter; |
||
35 | |||
36 | /** |
||
37 | * @param \Equip\Auth\Token\ExtractorInterface $token |
||
38 | * @param \Equip\Auth\Credentials\ExtractorInterface $credentials |
||
39 | * @param AdapterInterface $adapter |
||
40 | * @param RequestFilterInterface $filter |
||
41 | */ |
||
42 | 9 | public function __construct( |
|
53 | |||
54 | /** |
||
55 | * @param ServerRequestInterface $request |
||
56 | * @param ResponseInterface $response |
||
57 | * @param callable $next |
||
58 | * @return array |
||
59 | */ |
||
60 | 9 | public function __invoke( |
|
61 | ServerRequestInterface $request, |
||
62 | ResponseInterface $response, |
||
63 | callable $next |
||
64 | ) { |
||
65 | 9 | if ($this->shouldFilter($request)) { |
|
66 | 8 | if ($token = $this->token->getToken($request)) { |
|
67 | 3 | $authToken = $this->adapter->validateToken($token); |
|
68 | 5 | } elseif ($credentials = $this->credentials->getCredentials($request)) { |
|
69 | 4 | $authToken = $this->adapter->validateCredentials($credentials); |
|
70 | } else { |
||
71 | 1 | throw new UnauthorizedException; |
|
72 | } |
||
73 | |||
74 | 3 | $request = $this->handleToken($request, $authToken); |
|
75 | } |
||
76 | |||
77 | 4 | return $next($request, $response); |
|
78 | } |
||
79 | |||
80 | /** |
||
81 | * Handle the Token and put it in the request |
||
82 | * |
||
83 | * @param ServerRequestInterface $request |
||
84 | * @param Token $token |
||
85 | * @return ServerRequestInterface |
||
86 | */ |
||
87 | 3 | protected function handleToken(ServerRequestInterface $request, Token $token) |
|
91 | |||
92 | /** |
||
93 | * @param ServerRequestInterface $request |
||
94 | * @return boolean |
||
95 | */ |
||
96 | 9 | protected function shouldFilter(ServerRequestInterface $request) |
|
103 | } |
||
104 |
This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.
To visualize
will produce issues in the first and second line, while this second example
will produce no issues.