<commit_before><?php
/**
 * Conveniance class that converts the given object
 * in to associative array
 * @category   Framework
 * @package    restler
 * @subpackage format
 * @author     <NAME> <<EMAIL>>
 * @copyright  2010 Luracast
 * @license    http://www.opensource.org/licenses/lgpl-license.php LGPL
 * @link       http://luracast.com/products/restler/
 */
class RestlerHelper {

    /**
     * Conveniance function that converts the given object
     * in to associative array
     *
     * @param object $object
     *            that needs to be converted
     */
    public static function objectToArray($object, $encoderFunctionName = false)
    {
        if (is_array ( $object ) || is_object ( $object )) {
            $array = array ();
            foreach ($object as $key => $value) {
                $value = self::objectToArray ( $value, $encoderFunctionName );
                if ($encoderFunctionName && is_string ( $value )) {
                    $value = $$encoderFunctionName ( $value );
                }
                $array [$key] = $value;
            }
            return $array;
        }
        return $object;
    }
}<commit_msg>improved to handle JsonSerializable objects<commit_after><?php
/**
 * Conveniance class that converts the given object
 * in to associative array
 * @category   Framework
 * @package    restler
 * @subpackage format
 * @author     <NAME> <<EMAIL>>
 * @copyright  2010 Luracast
 * @license    http://www.opensource.org/licenses/lgpl-license.php LGPL
 * @link       http://luracast.com/products/restler/
 */
class RestlerHelper {

    /**
     * Conveniance function that converts the given object
     * in to associative array
     *
     * @param object $object
     *            that needs to be converted
     */
    public static function objectToArray($object, $encoderFunctionName = false)
    {
        if($object instanceof JsonSerializable){
            $object = $object->jsonSerialize();
        }
        if (is_array ( $object ) || is_object ( $object )) {
            $array = array ();
            foreach ($object as $key => $value) {
                $value = self::objectToArray ( $value, $encoderFunctionName );
                if ($encoderFunctionName && is_string ( $value )) {
                    $value = $$encoderFunctionName ( $value );
                }
                $array [$key] = $value;
            }
            return $array;
        }
        return $object;
    }
}
{'fraction_non_alphanumeric': 0.11480730223123732, 'fraction_numerical': 0.0032454361054766734, 'mean_word_length': 1.9818621523579203, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 12, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '7188853', 'n_tokens_mistral': 685, 'n_tokens_neox': 655, 'n_words': 181}