GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — thruway-0.4 ( 2e415f...2c60a9 )
by Cees-Jan
09:33
created

JWTController   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 0
Metric Value
dl 0
loc 33
rs 10
c 0
b 0
f 0
wmc 5
lcom 1
cbo 5

2 Methods

Rating   Name   Duplication   Size   Complexity  
A initialize() 0 6 1
B token() 0 23 4
1
<?php
2
3
namespace WyriHaximus\Ratchet\Controller;
4
5
use Cake\Controller\Controller;
6
use Cake\Core\Configure;
7
use Firebase\JWT\JWT;
8
use function igorw\get_in;
9
10
class JWTController extends Controller
11
{
12
    public function initialize()
13
    {
14
        $this->loadComponent('RequestHandler');
15
        $this->loadComponent('Auth');
16
        $this->Auth->allow(['token']);
17
    }
18
19
    public function token()
20
    {
21
        $realm = $this->request->query('realm');
22
        $realms = Configure::read('WyriHaximus.Ratchet.realms');
23
        if (!isset($realms[$realm])) {
24
            throw new \InvalidArgumentException('Unknown realm');
25
        }
26
        if (!isset($realms[$realm]['auth_key'])) {
27
            throw new \InvalidArgumentException('Unknown realm');
28
        }
29
30
        $user = $this->Auth->user();
31
        $this->set(
32
            'token',
33
            JWT::encode(
34
                [
35
                    'authId' => $user === null ? 0 : get_in($user, ['id'], 0),
36
                ],
37
                $realms[$realm]['auth_key']
38
            )
39
        );
40
        $this->set('_serialize', ['token']);
41
    }
42
}
43