Automattic\WooCommerce\Internal\Shipping\FlatRate

WeightPlaceholder::normalize │ private │ WC 1.0

Coerce an untrusted weight into a non-negative float.

Weights reach this class through filters, so they can be anything. Negative weights are clamped the same way wc_get_weight() clamps them.

Method of the class: WeightPlaceholder{}

No Hooks.

Returns

float.

Usage

// private - for code of main (parent) class only
$result = $this->normalize( $weight ): float;
$weight(mixed) (required)
Weight to coerce.

WeightPlaceholder::normalize() code WC 11.3.0

private function normalize( $weight ): float {
	return is_numeric( $weight ) ? max( 0.0, (float) $weight ) : 0.0;
}