sw = $sw ?? Stopwatch::startNew(); $this->lastLapTicks = $this->sw->getElapsedTicks(); } public function getStopwatch(): Stopwatch { return $this->sw; } public function getLaps(): array { return $this->laps; } public function start(): void { $this->sw->start(); } public function stop(): void { $this->sw->stop(); } public function isRunning(): bool { return $this->sw->isRunning(); } public function lap(string $name, string $comment = ''): void { if(!ctype_alnum($name)) throw new InvalidArgumentException('$name must be alpha-numeric.'); $lapTicks = $this->sw->getElapsedTicks(); $elapsed = $lapTicks - $this->lastLapTicks; $this->lastLapTicks = $lapTicks; $this->laps[] = new TimingPoint( $lapTicks, $elapsed, $name, $comment ); } }