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 — master ( 4ccb09...2f9dc2 )
by Nicolas
03:16
created

TimestampValidator   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
dl 0
loc 50
rs 10
c 0
b 0
f 0
wmc 4
lcom 1
cbo 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
A check() 0 15 3
1
<?php
2
/**
3
 * @package toolkit
4
 */
5
6
/**
7
 * This class checks against the Database for the latest timestamp, to make
8
 * sure the data being saved is the one the user saw.
9
 *
10
 * @since Symphony 2.7.0
11
 */
12
13
class TimestampValidator
14
{
15
    /**
16
     * The name of the table to check against
17
     * @var string
18
     */
19
    private $table = '';
20
21
    /**
22
     * Creates a new TimestampValidator object, for a particular table.
23
     * The `tbl_` prefix is automatically added.
24
     *
25
     * @param string $table
26
     *   The table name
27
     */
28
    public function __construct($table)
29
    {
30
        General::ensureType(array(
31
            'table' => array('var' => $table, 'type'=> 'string'),
32
        ));
33
        $this->table = 'tbl_' . MySQL::cleanValue($table);
34
    }
35
36
    /**
37
     * Checks if the modified date of the record identified with $id
38
     * if equal to the supplied $timestamp
39
     *
40
     * @param int|string $id
41
     *  The record id to check
42
     * @param string $timestamp
43
     *  The user supplied timestamp
44
     * @return boolean
45
     *  true if the $timestamp is the latest or the $id is invalid, false other wise
46
     */
47
    public function check($id, $timestamp)
48
    {
49
        $id = General::intval(MySQL::cleanValue($id));
50
        if ($id < 1) {
51
            return false;
52
        }
53
        $timestamp = MySQL::cleanValue($timestamp);
54
        $sql = "
55
            SELECT `id` FROM `{$this->table}`
56
                WHERE `id` = $id
57
                    AND `modification_date` = '$timestamp'
58
        ";
59
        $results = Symphony::Database()->fetchVar('id', 0, $sql);
60
        return !empty($results) && General::intval($results) === $id;
61
    }
62
}
63