peakphp/framework

View on GitHub
src/Common/Traits/MicroTime.php

Summary

Maintainability
A
0 mins
Test Coverage
<?php

declare(strict_types=1);

namespace Peak\Common\Traits;

use function microtime;
use function round;

trait MicroTime
{
    /**
     * @return float
     */
    protected function getMicroTime(): float
    {
        return microtime(true);
    }

    /**
     * @param float $time
     * @param int $decimalPrecision
     * @return float
     */
    protected function formatMs(float $time, int $decimalPrecision = 2): float
    {
        return round($time * 1000, $decimalPrecision);
    }

    /**
     * @param float $time
     * @param int $decimalPrecision
     * @return float
     */
    protected function formatSec(float $time, int $decimalPrecision = 2): float
    {
        return round($time, $decimalPrecision);
    }
}