Skip to content

Commit c22d26b

Browse files
committed
Improve typing in tests and src
1 parent 8bd8dba commit c22d26b

File tree

4 files changed

+9
-9
lines changed

4 files changed

+9
-9
lines changed

src/Stopwatch.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@
55

66
class Stopwatch {
77

8-
private $accrued = 0;
8+
private float $accrued = 0;
99

10-
private $timestamp;
10+
private float $timestamp;
1111

12-
private $running = false;
12+
private bool $running = false;
1313

1414
public function __construct() {
1515
$this->start();

src/Timer.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class Timer {
3535
*
3636
* @var Stopwatch[]
3737
*/
38-
static private $timers = [];
38+
static private array $timers = [];
3939

4040
/**
4141
* Start or resume the timer.
@@ -136,7 +136,7 @@ private static function secondsToTimeString(float $time): string {
136136
*
137137
* @throws LogicException If the attempted timer has not started already.
138138
*/
139-
public static function stop($key = 'default'): void {
139+
public static function stop(string $key = 'default'): void {
140140
if (!isset(self::$timers[$key])) {
141141
throw new LogicException('Stopping timer when the given key timer was not initialized.');
142142
}

tests/StopwatchTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public function testTimerStoppedValueRetention(): void {
2121
$this->assertSame($time_1, $time_2);
2222
}
2323

24-
public function testTimerContiniuous(): void {
24+
public function testTimerContinious(): void {
2525
$stopwatch = new Stopwatch();
2626
$time_1 = $stopwatch->read();
2727
$this->assertIsFloat($time_1);

tests/TimerTest2.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,21 @@
1111
*/
1212
class TimerTest2 extends TestCase {
1313

14-
public function testTimerDefaultRunning() {
14+
public function testTimerDefaultRunning(): void {
1515
Timer::start();
1616
sleep(20);
1717
$this->assertSame('20000', Timer::read());
1818
}
1919

20-
public function testNamedTimerRunning() {
20+
public function testNamedTimerRunning(): void {
2121
$name = __FUNCTION__;
2222
Timer::start($name);
2323
$time_1 = Timer::read($name);
2424
$time_2 = Timer::read($name);
2525
$this->assertSame($time_1, $time_2);
2626
}
2727

28-
public function testUnknownTimerThrowsException() {
28+
public function testUnknownTimerThrowsException(): void {
2929
Timer::start(__FUNCTION__);
3030
Timer::reset(__FUNCTION__);
3131
$this->expectException(\LogicException::class);

0 commit comments

Comments
 (0)