Assert\Assertion::integerish PHP Method

integerish() public static method

Assert that value is a php integer'ish.
public static integerish ( mixed $value, string | null $message = null, string | null $propertyPath = null ) : boolean
$value mixed
$message string | null
$propertyPath string | null
return boolean
    public static function integerish($value, $message = null, $propertyPath = null)
    {
        if (is_object($value) || strval(intval($value)) != $value || is_bool($value) || is_null($value)) {
            $message = sprintf($message ?: 'Value "%s" is not an integer or a number castable to integer.', static::stringify($value));
            throw static::createException($value, $message, static::INVALID_INTEGERISH, $propertyPath);
        }
        return true;
    }

Usage Example

Exemplo n.º 1
0
 /**
  * @param string $direction
  * @param int $days
  */
 public function __construct($direction, $days)
 {
     Assertion::integerish($days);
     Assertion::choice($direction, [self::DIRECTION_PAST, self::DIRECTION_FUTURE]);
     $this->direction = $direction;
     $this->days = (int) $days;
 }
All Usage Examples Of Assert\Assertion::integerish