public static function secureKnownType($data, string $type)
    {
        $filterType = 'text';

        if ($type === 'int' || $type === 'integer') {
            $filterType = FILTER_VALIDATE_INT;
        } elseif ($type === 'float' || $type === 'double') {
            $filterType = FILTER_VALIDATE_FLOAT;
        } elseif ($type === 'bool' || $type === 'boolean') {
            $filterType = FILTER_VALIDATE_BOOLEAN;
        } elseif ($type === 'email') {
            $filterType = FILTER_VALIDATE_EMAIL;
        }

        if ($filterType === 'text') {
            throw new Exception(
                'Cannot secure the type',
                self::ERR_SECURE_KNOWN_TYPE_FILTER_NOT_MANAGED
            );
        }

        return filter_var($data, $filterType);
    }
public static function secureKnownType($data, string $type)
    {
        $filterType = 'text';

        if ($type === 'int' || $type === 'integer') {
            $filterType = FILTER_VALIDATE_INT;
        } elseif ($type === 'float' || $type === 'double') {
            $filterType = FILTER_VALIDATE_FLOAT;
        } elseif ($type === 'bool' || $type === 'boolean') {
            $filterType = FILTER_VALIDATE_BOOLEAN;
        } elseif ($type === 'email') {
            $filterType = FILTER_VALIDATE_EMAIL;
        }

        if ($filterType === 'text') {
            throw new Exception(
                'Cannot secure the type',
                self::ERR_SECURE_KNOWN_TYPE_FILTER_NOT_MANAGED
            );
        }

        return filter_var($data, $filterType);
    }
public static function secureKnownType ( $ data , string $ type ) { $ filterType = 'text' ; if ( $ type === 'int' || $ type === 'integer' ) { $ filterType = FILTER_VALIDATE_INT ; } elseif ( $ type === 'float' || $ type === 'double' ) { $ filterType = FILTER_VALIDATE_FLOAT ; } elseif ( $ type === 'bool' || $ type === 'boolean' ) { $ filterType = FILTER_VALIDATE_BOOLEAN ; } elseif ( $ type === 'email' ) { $ filterType = FILTER_VALIDATE_EMAIL ; } if ( $ filterType === 'text' ) { throw new Exception ( 'Cannot secure the type' , self :: ERR_SECURE_KNOWN_TYPE_FILTER_NOT_MANAGED ) ; } return filter_var ( $ data , $ filterType ) ; }
Securize a string for some types with filter_var function.

@param mixed $data String to securize
@param string $type Type of filter

@return mixed

@throws \Exception If the type is unknown
Securize a string for some types with filter_var function .