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.

ChangeDetector   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 11
c 1
b 0
f 0
dl 0
loc 41
ccs 9
cts 9
cp 1
rs 10
wmc 4

1 Method

Rating   Name   Duplication   Size   Complexity  
A handle() 0 14 4
1
<?php
2
3
declare(strict_types=1);
4
5
namespace ZsSarkany\LaravelDatabaseStickyTimezone;
6
7
class ChangeDetector
8
{
9
    /**
10
     * SPL object hash of PDO instance.
11
     *
12
     * It is used to catch PDO instance replacements, which could easily happen
13
     * by calling setPdo or setReadPdo on \Illuminate\Database\Connection.
14
     *
15
     * @var string
16
     */
17
    protected $objectHash;
18
19
    /**
20
     * Last set offset value for change detection.
21
     *
22
     * @var string
23
     */
24
    protected $currentOffset;
25
26
    /**
27
     * Invoke callback if change (or uninitialized state) is detected.
28
     *
29
     * @param \PDO $pdo
30
     * @param callable $callback
31
     *
32
     * @return void
33
     */
34 5
    public function handle(?\PDO $pdo, callable $callback): void
35
    {
36 5
        if (is_null($pdo)) {
37 1
            return;
38
        }
39
40 4
        $objectHash = spl_object_hash($pdo);
41 4
        $offset = date('P');
42
43 4
        if ($this->objectHash !== $objectHash || $this->currentOffset !== $offset) {
44 4
            call_user_func($callback, $offset);
45
46 4
            $this->objectHash = $objectHash;
47 4
            $this->currentOffset = $offset;
48
        }
49 4
    }
50
}
51