Skip to content
PHP Ecosystem
Explore

Coerce

API reference › Debug Core › Helper › Coerce

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

Narrows arbitrary mixed payloads into the typed scalars debug-panel renderers expect.

MethodDescriptionDefined by
float() staticReturns a numeric value as a float or the supplied default.Coerce
floatOrNull() staticReturns the value as a float when it is numeric, null otherwise.Coerce
int() staticReturns a numeric value as an int or the supplied default.Coerce
intOrNull() staticReturns the value as an int when it is numeric, null otherwise.Coerce
string() staticReturns a string value or the supplied default.Coerce
stringKeyedArray() staticReturns only the entries of $data whose key is a string, preserving order.Coerce
stringList() staticReturns only the string entries of a raw list, preserving order.Coerce
stringOrNull() staticReturns the value as a string when it is scalar or Stringable, null otherwise.Coerce
traceFrames() staticNarrows a raw trace value (as captured by Yii’s logger) into the list<array<string, mixed>> shape every panel renderer consumes.Coerce
public static function float(mixed $value, float $default = 0.0): float

Returns a numeric value as a float or the supplied default.

Parameters

ParameterTypeDescription
$valuemixedValue to narrow.
$defaultfloatValue returned for non-numeric input.

Returns

float: Numeric value or the configured default.

public static function floatOrNull(mixed $value): float|null

Returns the value as a float when it is numeric, null otherwise.

Parameters

ParameterTypeDescription
$valuemixedValue to narrow.

Returns

float|null: Numeric value or null.

public static function int(mixed $value, int $default = 0): int

Returns a numeric value as an int or the supplied default.

Parameters

ParameterTypeDescription
$valuemixedValue to narrow.
$defaultintValue returned for non-numeric input.

Returns

int: Numeric value or the configured default.

public static function intOrNull(mixed $value): int|null

Returns the value as an int when it is numeric, null otherwise.

Parameters

ParameterTypeDescription
$valuemixedValue to narrow.

Returns

int|null: Numeric value or null.

public static function string(mixed $value, string $default = ''): string

Returns a string value or the supplied default.

Parameters

ParameterTypeDescription
$valuemixedValue to narrow.
$defaultstringValue returned for non-string input.

Returns

string: String value or the configured default.

public static function stringKeyedArray(array<array-key, mixed> $data): array<string, mixed>

Returns only the entries of $data whose key is a string, preserving order.

Narrows a mixed/array<array-key, mixed> snapshot down to the array<string, mixed> shape downstream view-model normalizers expect.

Parameters

ParameterTypeDescription
$dataarray<array-key, mixed>Source array with arbitrary keys.

Returns

array<string, mixed>: Entries whose key was already a string, in original order.

public static function stringList(mixed $values): list<string>

Returns only the string entries of a raw list, preserving order.

Parameters

ParameterTypeDescription
$valuesmixedRaw list, typically a user-configured category list.

Returns

list<string>: String entries in original order, possibly empty.

public static function stringOrNull(mixed $value): string|null

Returns the value as a string when it is scalar or Stringable, null otherwise.

Parameters

ParameterTypeDescription
$valuemixedValue to narrow.

Returns

string|null: String representation or null.

public static function traceFrames(mixed $value): list<array<string, mixed>>

Narrows a raw trace value (as captured by Yii’s logger) into the list<array<string, mixed>> shape every panel renderer consumes.

Parameters

ParameterTypeDescription
$valuemixedRaw trace payload.

Returns

list<array<string, mixed>>: Trace frames normalized to string-keyed maps.