# disco/1.4.14/app/Utility/Value.php

Discount Rules for WooCommerce – Disco | Dynamic Pricing, Conditions, Bulk, Bundle, BOGO, version 1.4.14. 65 lines.

- Page: https://pluginprobe.com/plugins/disco/1.4.14/code/app/Utility/Value.php
- Raw: https://pluginprobe.com/plugins/disco/1.4.14/raw/app/Utility/Value.php
- Modified: 2026-08-03T05:42:46+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/disco/1.4.14/code/app/Utility/Value.php#L10-L20`.

```php
<?php
/**
 * Scalar value casting.
 *
 * @package    Disco
 * @subpackage \App\Utility
 */

namespace Disco\App\Utility;

/**
 * Casts untyped campaign / cart values to scalars.
 *
 * Campaign rules come out of a JSON column and cart items out of WooCommerce
 * session data, so quantities and ids arrive as strings, nulls or occasionally
 * arrays. These casts keep calling code free of defensive `is_numeric()` noise
 * and return a harmless zero for anything unusable.
 *
 * @package    Disco
 * @subpackage Disco\App\Utility
 * @category   Utility
 */
class Value {

	/**
	 * Cast a raw value to int, or 0 when it is not numeric.
	 *
	 * @param mixed $value Raw value.
	 */
	public static function to_int( $value ): int {
		if ( ! is_numeric( $value ) ) {
			return 0;
		}

		return (int) $value;
	}

	/**
	 * Cast a raw value to float, or 0.0 when it is not numeric.
	 *
	 * @param mixed $value Raw value.
	 */
	public static function to_float( $value ): float {
		if ( ! is_numeric( $value ) ) {
			return 0.0;
		}

		return (float) $value;
	}

	/**
	 * Cast a raw value to string, or '' when it is not scalar.
	 *
	 * @param mixed $value Raw value.
	 */
	public static function to_string( $value ): string {
		if ( ! is_scalar( $value ) ) {
			return '';
		}

		return (string) $value;
	}

}

```
