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   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
wmc 8
lcom 1
cbo 0
dl 0
loc 40
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A getTimestamp() 0 3 1
A accrue() 0 3 1
A start() 0 9 2
A read() 0 6 2
A stop() 0 5 1
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