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.

Csrf   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 2
dl 0
loc 37
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A makeToken() 0 14 3
A isTokenValid() 0 5 2
1
<?php
2
3
/**
4
 * Cross Site Request Forgery Class
5
 *
6
 */
7
8
/**
9
 * Instructions:
10
 *
11
 * At your form, before the submit button put:
12
 * <input type="hidden" name="csrf_token" value="<?= Csrf::makeToken(); ?>" />
13
 *
14
 * This validation needed in the controller action method to validate CSRF token submitted with the form:
15
 *
16
 * if (!Csrf::isTokenValid()) {
17
 *     LoginModel::logout();
18
 *     Redirect::home();
19
 *     exit();
20
 * }
21
 *
22
 * To get simpler code it might be better to put the logout, redirect, exit into an own (static) method.
23
 */
24
class Csrf
25
{
26
    /**
27
     * get CSRF token and generate a new one if expired
28
     *
29
     * @access public
30
     * @static static method
31
     * @return string
32
     */
33
    public static function makeToken()
34
    {
35
        // token is valid for 1 day
36
        $max_time    = 60 * 60 * 24;
37
        $stored_time = Session::get('csrf_token_time');
38
        $csrf_token  = Session::get('csrf_token');
39
40
        if ($max_time + $stored_time <= time() || empty($csrf_token)) {
41
            Session::set('csrf_token', md5(uniqid(rand(), true)));
42
            Session::set('csrf_token_time', time());
43
        }
44
45
        return Session::get('csrf_token');
46
    }
47
48
    /**
49
     * checks if CSRF token in session is same as in the form submitted
50
     *
51
     * @access public
52
     * @static static method
53
     * @return bool
54
     */
55
    public static function isTokenValid()
56
    {
57
        $token = Request::post('csrf_token');
58
        return $token === Session::get('csrf_token') && !empty($token);
59
    }
60
}
61