<commit_before><?php

/*
 * This file is part of Gush package.
 *
 * (c) 2013-2014 <NAME> <<EMAIL>>
 *
 * This source file is subject to the MIT license that is bundled
 * with this source code in the file LICENSE.
 */

namespace Gush\Helper;

use Gush\Exception\UnsupportedTypeException;
use Gush\Meta\Iterator\PathFilterIterator;
use Gush\Meta\Meta;
use Symfony\Component\Console\Helper\Helper;

class MetaHelper extends Helper
{
    /**
     * @var array
     */
    protected $supportedFiles;

    public function __construct($supportedExtensionClassCollection)
    {
        $this->supportedFiles = $supportedExtensionClassCollection;
        foreach ($this->supportedFiles as $type => $class) {
            if (!$class instanceof Meta) {
                throw new \Exception(
                    sprintf(
                        'Meta header class for type "%s" does not implement the Gush\Meta\Meta interface.',
                        $type
                    )
                );
            }
        }
    }

    /**
     * @param string $fileType
     * @param Meta   $class
     */
    public function registerFileType($fileType, Meta $class)
    {
        $this->supportedFiles[$fileType] = $class;
    }

    /**
     * @return array
     */
    public function getSupportedFiles()
    {
        return $this->supportedFiles;
    }

    /**
     * @param string $header
     * @param string $type
     *
     * @return string
     */
    public function renderHeader($header, $type)
    {
        $class = $this->getMetaClass($type);

        $out = [$class->getStartDelimiter()];
        foreach (preg_split('{\r?\n}', $header) as $line) {
            // avoid trailing spaces
            $out[] = ' '.$class->getDelimiter().($line ? ' '.$line : '');
        }
        $out[] = ' '.$class->getEndDelimiter();
        $out[] = "\n";<commit_msg>trim white space from input header<commit_after><?php

/*
 * This file is part of Gush package.
 *
 * (c) 2013-2014 <NAME> <<EMAIL>>
 *
 * This source file is subject to the MIT license that is bundled
 * with this source code in the file LICENSE.
 */

namespace Gush\Helper;

use Gush\Exception\UnsupportedTypeException;
use Gush\Meta\Iterator\PathFilterIterator;
use Gush\Meta\Meta;
use Symfony\Component\Console\Helper\Helper;

class MetaHelper extends Helper
{
    /**
     * @var array
     */
    protected $supportedFiles;

    public function __construct($supportedExtensionClassCollection)
    {
        $this->supportedFiles = $supportedExtensionClassCollection;
        foreach ($this->supportedFiles as $type => $class) {
            if (!$class instanceof Meta) {
                throw new \Exception(
                    sprintf(
                        'Meta header class for type "%s" does not implement the Gush\Meta\Meta interface.',
                        $type
                    )
                );
            }
        }
    }

    /**
     * @param string $fileType
     * @param Meta   $class
     */
    public function registerFileType($fileType, Meta $class)
    {
        $this->supportedFiles[$fileType] = $class;
    }

    /**
     * @return array
     */
    public function getSupportedFiles()
    {
        return $this->supportedFiles;
    }

    /**
     * @param string $header
     * @param string $type
     *
     * @return string
     */
    public function renderHeader($header, $type)
    {
        $class = $this->getMetaClass($type);

        $out = [$class->getStartDelimiter()];
        foreach (preg_split('{\r?\n}', trim($header)) as $line) {
            // avoid trailing spaces
            $out[] = ' '.$class->getDelimiter().($line ? ' '.$line : '');
        }
        $out[] = ' '.$class->getEndDelimiter();
        $out[] = "\n";
{'fraction_non_alphanumeric': 0.1297037630104083, 'fraction_numerical': 0.004270082732852949, 'mean_word_length': 1.9605055292259084, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 27, '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': '891596', 'n_tokens_mistral': 1071, 'n_tokens_neox': 1044, 'n_words': 268}