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 ( aa3e12...c47ebf )
by Ayesh
02:01
created

Stopwatch::read()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 4
nc 2
nop 0
1
<?php
2
3
4
namespace Ayesh\PHP_Timer;
5
6
class Stopwatch {
7
  private $accrued = 0;
8
  private $timestamp;
9
  private $running = false;
10
11
  public function __construct() {
12
    $this->start();
13
  }
14
15
  private function getTimestamp(): float {
16
    return microtime(true);
17
  }
18
19
  private function accrue(): void {
20
    $this->accrued = $this->read();
0 ignored issues
show
Documentation Bug introduced by
The property $accrued was declared of type integer, but $this->read() is of type double. Maybe add a type cast?

This check looks for assignments to scalar types that may be of the wrong type.

To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.

$answer = 42;

$correct = false;

$correct = (bool) $answer;
Loading history...
21
  }
22
23
  public function start(): void {
24
    if ($this->running) {
25
      return;
26
    }
27
28
    $this->accrue();
29
    $this->running = true;
30
    $this->timestamp = $this->getTimestamp();
31
  }
32
33
  public function read(): float {
34
    if ($this->running) {
35
      return $this->accrued + ($this->getTimestamp() - $this->timestamp);
36
    }
37
    return $this->accrued;
38
  }
39
40
  public function stop(): float {
41
    $this->accrue();
42
    $this->running = false;
43
    return $this->read();
44
  }
45
}
46