Skip to content
PHP Ecosystem
Explore

Format

API reference › Debug Core › Helper › Format

final classPHPForge\Debug\Helper\Format
Sourcesrc/Helper/Format.php

Formats values, timestamps, and type labels for display in debug-panel views and toolbar chips.

MethodDescriptionDefined by
bytesToMb() staticReturns a N.NN MB string for the given byte count, rounded to the requested precision.Format
cssPercent() staticReturns a CSS percentage (42%, 33.333%) with at most three decimals and trailing zeros trimmed.Format
milliseconds() staticReturns a N ms readout for the given duration in seconds, grouped in thousands.Format
relativeTime() staticReturns a coarse age label for the given elapsed seconds: just now under a minute, then X min ago, X h ago, and X d ago. Ages of 30 days or more fall back to $fallback.Format
timeOfDay() staticReturns the wall-clock readout of the given epoch milliseconds, suffixed with the millisecond fraction (H:i:s.mmm).Format
typeOf() staticReturns the display label of a value’s type, with the element count for arrays and the byte length for strings.Format
ConstantValueDescriptionDefined by
BYTES_PER_MB1024 * 1024Bytes in one mebibyte, the unit of the bytesToMb() readout.Format
MILLISECONDS_PER_SECOND1000Milliseconds in one second, used to scale second-based durations.Format
public static function bytesToMb(float|int $bytes, int $precision = 2): string

Returns a N.NN MB string for the given byte count, rounded to the requested precision.

Parameters

ParameterTypeDescription
$bytesfloat|intByte count to format.
$precisionintNumber of decimal places.

Returns

string: Megabyte readout.

public static function cssPercent(float $value): string

Returns a CSS percentage (42%, 33.333%) with at most three decimals and trailing zeros trimmed.

Parameters

ParameterTypeDescription
$valuefloatPercentage value to format.

Returns

string: CSS percentage.

public static function milliseconds(float $seconds, int $decimals = 0): string

Returns a N ms readout for the given duration in seconds, grouped in thousands.

Parameters

ParameterTypeDescription
$secondsfloatDuration in seconds.
$decimalsintNumber of decimal places.

Returns

string: Millisecond readout.

public static function relativeTime(int $elapsedSeconds, string $fallback): string

Returns a coarse age label for the given elapsed seconds: just now under a minute, then X min ago, X h ago, and X d ago. Ages of 30 days or more fall back to $fallback.

The caller supplies the elapsed seconds so the clock source stays at the call site.

Parameters

ParameterTypeDescription
$elapsedSecondsintAge in seconds, typically time() - $capturedAt.
$fallbackstringAbsolute label used past the 30-day threshold.

Returns

string: Age label, or $fallback when the age reaches 30 days.

public static function timeOfDay(int $epochMilliseconds, string $format = 'H:i:s'): string

Returns the wall-clock readout of the given epoch milliseconds, suffixed with the millisecond fraction (H:i:s.mmm).

Negative timestamps use floor division, so the fraction stays in the 000-999 range and the seconds part names the wall-clock second that contains the instant.

Parameters

ParameterTypeDescription
$epochMillisecondsintUnix timestamp in milliseconds.
$formatstringdate() format for the second-precision part, without the fraction separator.

Returns

string: Formatted timestamp followed by .mmm.

public static function typeOf(mixed $value): string

Returns the display label of a value’s type, with the element count for arrays and the byte length for strings.

Parameters

ParameterTypeDescription
$valuemixedJSON-safe value to describe.

Returns

string: Type label such as array(3), string(16), int, float, bool, or null.