<commit_before><?php

/*
 * This file is part of the PhpTabs package.
 *
 * Copyright (c) landrok at github.com/landrok
 *
 * For the full copyright and license information, please see
 * <https://github.com/stdtabs/phptabs/blob/master/LICENSE>.
 */

namespace PhpTabs\Component;

use Exception;

class Reader
{
    /**
     * @var Tablature object
     */
    private $tablature;

    /**
     * @var ReaderInterface bridge
     */
    private $bridge;

    /**
     * @var array List of extensions
     */
    private $extensions = array(
        'gp3'   => 'PhpTabs\\Reader\\GuitarPro\\GuitarPro3Reader',
        'gp4'   => 'PhpTabs\\Reader\\GuitarPro\\GuitarPro4Reader',
        'gp5'   => 'PhpTabs\\Reader\\GuitarPro\\GuitarPro5Reader',
        'mid'   => 'PhpTabs\\Reader\\Midi\\MidiReader',
        'midi'  => 'PhpTabs\\Reader\\Midi\\MidiReader'
    );

    /**
     * Instanciates tablature container
     * Try to load the right dedicated reader
     *
     * @param \PhpTabs\Component\InputStream $file file which should contain a tablature
     *
     * @throws \Exception If file format is not supported
     */
    public function __construct(InputStream $file, string $extension)
    {
        $this->tablature = new Tablature();

        if (isset($this->extensions[ $extension ])) {
            $name = $this->extensions[ $extension ];

            $this->tablature->setFormat($extension);

            $this->bridge = new $name($file);
        }

        // Bridge not found
        if (!($this->bridge instanceof ReaderInterface)) {
            $message = sprintf(
                'No reader has been found for "%s" type of file',
                $extension
            );

            throw new Exception($message);
        }
    }

    /**
     * @return Tablature A tablature read from file.
     *  Otherwise, an empty tablature with some error information
     *
     * @return \PhpTabs\Component\Tablature
     */
    public function getTablature(): Tablature
    {
        if ($this->bridge instanceof ReaderInterface) {
            return $this->bridge->getTablature();
        }

        return $this->tablature;  // Fallback
    }
}<commit_msg>Reforge Reader constructor<commit_after><?php

/*
 * This file is part of the PhpTabs package.
 *
 * Copyright (c) landrok at github.com/landrok
 *
 * For the full copyright and license information, please see
 * <https://github.com/stdtabs/phptabs/blob/master/LICENSE>.
 */

namespace PhpTabs\Component;

use Exception;

class Reader
{
    /**
     * @var Tablature object
     */
    private $tablature;

    /**
     * @var ReaderInterface bridge
     */
    private $bridge;

    /**
     * @var array List of extensions
     */
    private $extensions = array(
        'gp3'   => 'PhpTabs\\Reader\\GuitarPro\\GuitarPro3Reader',
        'gp4'   => 'PhpTabs\\Reader\\GuitarPro\\GuitarPro4Reader',
        'gp5'   => 'PhpTabs\\Reader\\GuitarPro\\GuitarPro5Reader',
        'mid'   => 'PhpTabs\\Reader\\Midi\\MidiReader',
        'midi'  => 'PhpTabs\\Reader\\Midi\\MidiReader'
    );

    /**
     * Instanciates tablature container and try to load the dedicated
     * parser.
     *
     * @throws \Exception If file format is not supported
     */
    public function __construct(InputStream $input, string $extension)
    {
        // Bridge is not defined
        if (!isset($this->extensions[$extension])) {
            $message = sprintf(
                'No reader has been found for "%s" type of file',
                $extension
            );

            throw new Exception($message);
        }

        $this->tablature = new Tablature();

        $name = $this->extensions[$extension];

        $this->bridge = new $name($input);

        $this->bridge->getTablature()->setFormat($extension);
    }

    /**
     * Get bridge tablature instance
     */
    public function getTablature(): Tablature
    {
        return $this->bridge->getTablature();
    }
}
{'fraction_non_alphanumeric': 0.12975164723770907, 'fraction_numerical': 0.0030410542321338066, 'mean_word_length': 2.1103230890464935, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 35, 'https://': 2, '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': '7637800', 'n_tokens_mistral': 1207, 'n_tokens_neox': 1167, 'n_words': 282}