<commit_before><?php

namespace NewUp\Configuration\Parsers;

use Symfony\Component\Yaml\Parser;
use Symfony\Component\Yaml\Yaml;

class YAMLParser
{

    /**
     * The parser instance.
     *
     * @var Parser
     */
    protected $yamlParser = null;

    /**
     * Indicates if array values (strings) will be trimmed.
     *
     * @var bool
     */
    protected $trimArrayValues = false;

    /**
     * Gets a Symfony YAML parser.
     *
     * @return Parser
     */
    private function getParser()
    {
        if ($this->yamlParser == null) {
            $this->yamlParser = new Parser;
        }

        return $this->yamlParser;
    }

    /**
     * Parses a YAML file.
     *
     * @param  $fileLocation
     * @return string
     */
    public function parseFile($fileLocation)
    {
        return $this->parseString(file_get_contents($fileLocation));
    }

    /**
     * Recursively trims all string values in an array.
     *
     * @param  $array
     * @return array
     */
    private function trimArray(&$array)
    {
        foreach ($array as $key => $value) {
            if (is_string($value)) {
                $array[$key] = trim($value);
            } else if (is_array($value)) {
                $array[$key] = $this->trimArray($value);
            }
        }

        return $array;
    }

    /**
     * Sets whether or not the parser trims array values.
     *
     * @param bool $value
     */
    public function trimArrayValues($value)
    {
        $this->trimArrayValues = $value;
    }

    /**
     * Parses a YAML string.
     *
     * @param  $string
     * @return string
     */
    public function parseString($string)
    {
        $value = $this->getParser()->parse($string);

        if ($this->trimArrayValues && is_array($value)) {
            return $this->trimArray($value);
        }

        return $value;
    }<commit_msg>Adds a getter and sets a default value from trim array values<commit_after><?php

namespace NewUp\Configuration\Parsers;

use Symfony\Component\Yaml\Parser;
use Symfony\Component\Yaml\Yaml;

class YAMLParser
{

    /**
     * The parser instance.
     *
     * @var Parser
     */
    protected $yamlParser = null;

    /**
     * Indicates if array values (strings) will be trimmed.
     *
     * @var bool
     */
    protected $trimArrayValues = false;

    /**
     * Gets a Symfony YAML parser.
     *
     * @return Parser
     */
    private function getParser()
    {
        if ($this->yamlParser == null) {
            $this->yamlParser = new Parser;
        }

        return $this->yamlParser;
    }

    /**
     * Parses a YAML file.
     *
     * @param  $fileLocation
     * @return string
     */
    public function parseFile($fileLocation)
    {
        return $this->parseString(file_get_contents($fileLocation));
    }

    /**
     * Recursively trims all string values in an array.
     *
     * @param  $array
     * @return array
     */
    private function trimArray(&$array)
    {
        foreach ($array as $key => $value) {
            if (is_string($value)) {
                $array[$key] = trim($value);
            } else if (is_array($value)) {
                $array[$key] = $this->trimArray($value);
            }
        }

        return $array;
    }

    /**
     * Sets whether or not the parser trims array values.
     *
     * @param bool|true $value
     */
    public function trimArrayValues($value= true)
    {
        $this->trimArrayValues = $value;
    }

    /**
     * Gets whether or not the parser trims array values.
     *
     * @return bool
     */
    public function willTrimArrayValues()
    {
        return $this->trimArrayValues;
    }

    /**
     * Parses a YAML string.
     *
     * @param  $string
     * @return string
     */
    public function parseString($string)
    {
        $value = $this->getParser()->parse($string);

        if ($this->trimArrayValues && is_array($value)) {
            return $this->trimArray($value);
        }

        return $value;
    }
{'fraction_non_alphanumeric': 0.12555831265508685, 'fraction_numerical': 0.0, 'mean_word_length': 1.7440435670524166, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 26, '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': '7137228', 'n_tokens_mistral': 1230, 'n_tokens_neox': 1194, 'n_words': 286}