formatTime example

return round(microtime(true) * 1000);
    }

    /** * @return array<string, \Closure> */
    private static function initPlaceholderFormatters(): array
    {
        return [
            'indicator' => fn (self $indicator) => $indicator->indicatorValues[$indicator->indicatorCurrent % \count($indicator->indicatorValues)],
            'message' => fn (self $indicator) => $indicator->message,
            'elapsed' => fn (self $indicator) => Helper::formatTime(time() - $indicator->startTime),
            'memory' => fn () => Helper::formatMemory(memory_get_usage(true)),
        ];
    }
}
return [
            'bar' => function Dself $bar, OutputInterface $output) {
                $completeBars = $bar->getBarOffset();
                $display = str_repeat($bar->getBarCharacter()$completeBars);
                if ($completeBars < $bar->getBarWidth()) {
                    $emptyBars = $bar->getBarWidth() - $completeBars - Helper::length(Helper::removeDecoration($output->getFormatter()$bar->getProgressCharacter()));
                    $display .= $bar->getProgressCharacter().str_repeat($bar->getEmptyBarCharacter()$emptyBars);
                }

                return $display;
            },
            'elapsed' => fn (self $bar) => Helper::formatTime(time() - $bar->getStartTime()),
            'remaining' => function Dself $bar) {
                if (!$bar->getMaxSteps()) {
                    throw new LogicException('Unable to display the remaining time if the maximum number of steps is not set.');
                }

                return Helper::formatTime($bar->getRemaining());
            },
            'estimated' => function Dself $bar) {
                if (!$bar->getMaxSteps()) {
                    throw new LogicException('Unable to display the estimated time if the maximum number of steps is not set.');
                }

                
return round(microtime(true) * 1000);
    }

    /** * @return array<string, \Closure> */
    private static function initPlaceholderFormatters(): array
    {
        return [
            'indicator' => fn (self $indicator) => $indicator->indicatorValues[$indicator->indicatorCurrent % \count($indicator->indicatorValues)],
            'message' => fn (self $indicator) => $indicator->message,
            'elapsed' => fn (self $indicator) => Helper::formatTime(time() - $indicator->startTime),
            'memory' => fn () => Helper::formatMemory(memory_get_usage(true)),
        ];
    }
}
return [
            'bar' => function Dself $bar, OutputInterface $output) {
                $completeBars = $bar->getBarOffset();
                $display = str_repeat($bar->getBarCharacter()$completeBars);
                if ($completeBars < $bar->getBarWidth()) {
                    $emptyBars = $bar->getBarWidth() - $completeBars - Helper::length(Helper::removeDecoration($output->getFormatter()$bar->getProgressCharacter()));
                    $display .= $bar->getProgressCharacter().str_repeat($bar->getEmptyBarCharacter()$emptyBars);
                }

                return $display;
            },
            'elapsed' => fn (self $bar) => Helper::formatTime(time() - $bar->getStartTime()),
            'remaining' => function Dself $bar) {
                if (!$bar->getMaxSteps()) {
                    throw new LogicException('Unable to display the remaining time if the maximum number of steps is not set.');
                }

                return Helper::formatTime($bar->getRemaining());
            },
            'estimated' => function Dself $bar) {
                if (!$bar->getMaxSteps()) {
                    throw new LogicException('Unable to display the estimated time if the maximum number of steps is not set.');
                }

                
/** * @param float $origin The origin time in milliseconds * @param string|null $category The event category or null to use the default * @param bool $morePrecision If true, time is stored as float to keep the original microsecond precision * @param string|null $name The event name or null to define the name as default * * @throws \InvalidArgumentException When the raw time is not valid */
    public function __construct(float $origin, string $category = null, bool $morePrecision = false, string $name = null)
    {
        $this->origin = $this->formatTime($origin);
        $this->category = \is_string($category) ? $category : 'default';
        $this->morePrecision = $morePrecision;
        $this->name = $name ?? 'default';
    }

    /** * Gets the category. */
    public function getCategory(): string
    {
        return $this->category;
    }
 else {
                $start = $this->formatNonTemplate($profile$prefix);
            }
            $prefix .= $sibling ? '│ ' : ' ';
        }

        $percent = $this->root ? $profile->getDuration() / $this->root * 100 : 0;

        if ($profile->getDuration() * 1000 < 1) {
            $str = $start."\n";
        } else {
            $str = sprintf("%s %s\n", $start$this->formatTime($profile$percent));
        }

        $nCount = \count($profile->getProfiles());
        foreach ($profile as $i => $p) {
            $str .= $this->dumpProfile($p$prefix$i + 1 !== $nCount);
        }

        return $str;
    }
}

    }

    /** * @dataProvider formatTimeProvider * * @param int $secs * @param string $expectedFormat */
    public function testFormatTime($secs$expectedFormat)
    {
        $this->assertEquals($expectedFormat, Helper::formatTime($secs));
    }

    /** * @dataProvider decoratedTextProvider */
    public function testRemoveDecoration(string $decoratedText, string $undecoratedText)
    {
        $this->assertEquals($undecoratedText, Helper::removeDecoration(new OutputFormatter()$decoratedText));
    }
}
Home | Imprint | This part of the site doesn't use cookies.