Skip to content

Commit

Permalink
Some little refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
SbWereWolf committed Feb 10, 2023
1 parent 5f02b12 commit 07348d0
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 20 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "sbwerewolf/stopwatch",
"description": "Primitive stopwatch with simple start and stop for measurement of every time periods and whole time",
"description": "Primitive stopwatch with simple start and stop for measurement of every single time periods and whole time",
"type": "libary",
"license": "MIT",
"authors": [
Expand Down
28 changes: 14 additions & 14 deletions src/SbWereWolf/Stopwatch/DateTimeStopwatch.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ protected function calcDiffNowWith($moment): int
/** @var DateTimeImmutable $readings */
$readings = $this->getReadings();
$delta = $readings->diff($moment);
$duration = $this->toNanoSeconds($delta);
$duration = static::toNanoSeconds($delta);

return $duration;
}
Expand All @@ -32,11 +32,23 @@ protected function getReadings()
return new DateTimeImmutable();
}

/**
* @param int $moment
* @return int
*/
protected function calcDiffLastEndWith($moment): int
{
$delta = $this->lastEndedAt->diff($moment);
$duration = $this->toNanoSeconds($delta);

return $duration;
}

/**
* @param DateInterval $delta
* @return float|int
*/
private function toNanoSeconds(DateInterval $delta)
private static function toNanoSeconds(DateInterval $delta)
{
$duration =
($delta->s + $delta->f) * ITimerReadings::TO_SECONDS +
Expand All @@ -49,16 +61,4 @@ private function toNanoSeconds(DateInterval $delta)

return (int)$duration;
}

/**
* @param int $moment
* @return int
*/
protected function calcDiffLastEndWith($moment): int
{
$delta = $this->lastEndedAt->diff($moment);
$duration = $this->toNanoSeconds($delta);

return $duration;
}
}
10 changes: 5 additions & 5 deletions src/SbWereWolf/Stopwatch/MicroTimeStopwatch.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ protected function getReadings()
*/
protected function calcDiffNowWith($moment): int
{
$start = $this->readingsToNanoseconds($moment);
$now = $this->readingsToNanoseconds($this->getReadings());
$start = static::readingsToNanoseconds($moment);
$now = static::readingsToNanoseconds($this->getReadings());

$duration = $now - $start;

Expand All @@ -35,8 +35,8 @@ protected function calcDiffNowWith($moment): int
*/
protected function calcDiffLastEndWith($moment): int
{
$start = $this->readingsToNanoseconds($moment);
$end = $this->readingsToNanoseconds($this->lastEndedAt);
$start = static::readingsToNanoseconds($moment);
$end = static::readingsToNanoseconds($this->lastEndedAt);

$duration = $end - $start;

Expand All @@ -47,7 +47,7 @@ protected function calcDiffLastEndWith($moment): int
* @param $readings
* @return float|int
*/
private function readingsToNanoseconds($readings)
private static function readingsToNanoseconds($readings)
{
list($mcs, $s) = explode(' ', $readings);
$moment =
Expand Down

0 comments on commit 07348d0

Please sign in to comment.