<commit_before><?php
namespace LazyRecord;
use LazyRecord\Types\DateTime;

class Inflator
{
    static $inflators = array();

    /** 
     * provide a custom inflator for data type
     */
    static function register($isa, $inflator)
    {
        self::$inflators[ $isa ] = $inflator;
    }

    static function inflate($value,$isa = null)
    {
        if( $value === null || $isa === null )
            return $value;

        if( isset(self::$inflators[ $isa ]) ) {
            $inflator = self::$inflators[ $isa ];
            if( is_callable($inflator) ) {
                return call_user_func( $inflator , $value );
            }
            elseif( class_exists($inflator,true) ) {
                $d = new $inflator;
                return $d->inflate( $value );
            }
        }

        /* respect the data type to inflate value */
        if( $isa == 'int' ) {
            return (int) $value;
        }
        elseif( $isa == 'str' ) {
            return (string) $value;
        }
        elseif( $isa == 'bool' ) {
            if( strcasecmp( 'false', $value ) == 0 || $value == '0' ) {
                return false;
            } 
            elseif( strcasecmp( 'true', $value ) == 0 || $value == '1' ) {
                return true;
            }
            return $value ? true : false;
        }
        elseif( $isa == 'float' ) {
            return (float) $value;
        }
        elseif( $isa == 'DateTime' ) {
            // already a DateTime object
            if( is_a( $value , 'DateTime',true) ) {
                return $value;
            }
            if( $value ) {
                return new DateTime( $value );
            }
            return null;
        }
        return $value;
    }

}



<commit_msg>use date_parse to validate date<commit_after><?php
namespace LazyRecord;
use LazyRecord\Types\DateTime;

class Inflator
{
    static $inflators = array();

    /** 
     * provide a custom inflator for data type
     */
    static function register($isa, $inflator)
    {
        self::$inflators[ $isa ] = $inflator;
    }

    static function inflate($value,$isa = null)
    {
        if( $value === null || $isa === null )
            return $value;

        if( isset(self::$inflators[ $isa ]) ) {
            $inflator = self::$inflators[ $isa ];
            if( is_callable($inflator) ) {
                return call_user_func( $inflator , $value );
            }
            elseif( class_exists($inflator,true) ) {
                $d = new $inflator;
                return $d->inflate( $value );
            }
        }

        /* respect the data type to inflate value */
        if( $isa == 'int' ) {
            return (int) $value;
        }
        elseif( $isa == 'str' ) {
            return (string) $value;
        }
        elseif( $isa == 'bool' ) {
            if( strcasecmp( 'false', $value ) == 0 || $value == '0' ) {
                return false;
            } 
            elseif( strcasecmp( 'true', $value ) == 0 || $value == '1' ) {
                return true;
            }
            return $value ? true : false;
        }
        elseif( $isa == 'float' ) {
            return (float) $value;
        }
        elseif( $isa == 'DateTime' ) {
            // already a DateTime object
            if( is_a( $value , 'DateTime',true) ) {
                return $value;
            }
            if ( $value && date_parse($value) !== false ) {
                return new DateTime( $value );
            }
            return null;
        }
        return $value;
    }

}




{'fraction_non_alphanumeric': 0.13976985686219479, 'fraction_numerical': 0.002245298905416784, 'mean_word_length': 1.3602649006622516, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6482984', 'n_tokens_mistral': 1046, 'n_tokens_neox': 1030, 'n_words': 262}