<commit_before><?php
/**
 * Created by PhpStorm.
 * User: igor
 * Date: 14.08.15
 * Time: 10:32
 */

namespace Darvin\ConfigBundle\Parameter;

/**
 * Configuration parameter value converter
 */
class ParameterValueConverter
{
    /**
     * @var array
     */
    private static $fromStringCallbacks = array(
        ParameterModel::TYPE_ARRAY   => 'json_decode',
        ParameterModel::TYPE_BOOL    => 'boolval',
        ParameterModel::TYPE_FLOAT   => 'floatval',
        ParameterModel::TYPE_INTEGER => 'intval',
    );

    /**
     * @var array
     */
    private static $toStringCallbacks = array(
        ParameterModel::TYPE_ARRAY   => 'json_encode',
        ParameterModel::TYPE_BOOL    => 'strval',
        ParameterModel::TYPE_FLOAT   => 'strval',
        ParameterModel::TYPE_INTEGER => 'strval',
    );

    /**
     * @param string $value Parameter value
     * @param string $type  Parameter type
     *
     * @return mixed
     */
    public function fromString($value, $type)
    {
        return $this->convert($value, $type, self::$fromStringCallbacks);
    }

    /**
     * @param mixed  $value Parameter value
     * @param string $type  Parameter type
     *
     * @return string
     */
    public function toString($value, $type)
    {
        return $this->convert($value, $type, self::$toStringCallbacks);
    }

    /**
     * @param mixed  $value            Parameter value
     * @param string $type             Parameter type
     * @param array  $convertCallbacks Convert callbacks
     *
     * @return mixed
     */
    private function convert($value, $type, array $convertCallbacks)
    {
        if (!isset($convertCallbacks[$type])) {
            return $value;
        }

        $callback = $convertCallbacks[$type];

        return $callback[$value];
    }<commit_msg>Fix parameter value converter.<commit_after><?php
/**
 * Created by PhpStorm.
 * User: igor
 * Date: 14.08.15
 * Time: 10:32
 */

namespace Darvin\ConfigBundle\Parameter;

/**
 * Configuration parameter value converter
 */
class ParameterValueConverter
{
    /**
     * @var array
     */
    private static $fromStringCallbacks = array(
        ParameterModel::TYPE_ARRAY   => 'json_decode',
        ParameterModel::TYPE_BOOL    => 'boolval',
        ParameterModel::TYPE_FLOAT   => 'floatval',
        ParameterModel::TYPE_INTEGER => 'intval',
    );

    /**
     * @var array
     */
    private static $toStringCallbacks = array(
        ParameterModel::TYPE_ARRAY   => 'json_encode',
        ParameterModel::TYPE_BOOL    => 'strval',
        ParameterModel::TYPE_FLOAT   => 'strval',
        ParameterModel::TYPE_INTEGER => 'strval',
    );

    /**
     * @param string $value Parameter value
     * @param string $type  Parameter type
     *
     * @return mixed
     */
    public function fromString($value, $type)
    {
        return $this->convert($value, $type, self::$fromStringCallbacks);
    }

    /**
     * @param mixed  $value Parameter value
     * @param string $type  Parameter type
     *
     * @return string
     */
    public function toString($value, $type)
    {
        return $this->convert($value, $type, self::$toStringCallbacks);
    }

    /**
     * @param mixed  $value            Parameter value
     * @param string $type             Parameter type
     * @param array  $convertCallbacks Convert callbacks
     *
     * @return mixed
     */
    private function convert($value, $type, array $convertCallbacks)
    {
        if (!isset($convertCallbacks[$type])) {
            return $value;
        }

        $callback = $convertCallbacks[$type];

        return $callback($value);
    }
{'fraction_non_alphanumeric': 0.12654405709580016, 'fraction_numerical': 0.005489980785067252, 'mean_word_length': 2.3217866909753875, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 23, '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': '2632345', 'n_tokens_mistral': 1041, 'n_tokens_neox': 1018, 'n_words': 237}