<commit_before><?php
namespace Imtigger\OneExcel\Writer;

use Imtigger\OneExcel\OneExcelWriterInterface;

abstract class OneExcelWriter implements OneExcelWriterInterface
{
    public static $input_format_supported = [];
    public static $output_format_supported = [];
    public static $input_output_same_format;

    protected function isInputFormatSupported($format)
    {
        return in_array($format, static::$input_format_supported);
    }


    protected function isOutputFormatSupported($format)
    {
        return in_array($format, static::$output_format_supported);
    }

    protected function checkFormatSupported($output_format, $input_format = null)
    {
        if (static::$input_output_same_format == true && $input_format != null && $input_format != $output_format) {
            throw new \Exception("Input format and output format needed to be the same {$input_format} for " . static::class);
        }

        if (!$this->isInputFormatSupported($input_format)) {
            throw new \Exception("Input format {$input_format} is not supported by " . static::class);
        }

        if (!$this->isOutputFormatSupported($output_format)) {
            throw new \Exception("Output format {$output_format} is not supported by " . static::class);
        }
    }

    protected function autoDetectInputFormat($filename, &$input_format)
    {
        if ($input_format == self::FORMAT_AUTO) {
            $input_format = self::guessFormatFromFilename($filename);
        }
    }

    protected function guessFormatFromFilename($filename)
    {
        $pathinfo = pathinfo($filename);

        switch(strtolower($pathinfo['extension'])) {
            case 'csv':
                return OneExcelWriterInterface::FORMAT_CSV;
            case 'xls':
                return OneExcelWriterInterface::FORMAT_XLS;
            case 'xlsx':
                return OneExcelWriterInterface::FORMAT_XLSX;
            case 'ods':
                return OneExcelWriterInterface::FORMAT_ODS;
            default:
                throw new \Exception("Could not guess format for filename {$filename}");
        }
    }

    protected function getFormatMime($format)
    {
        switch ($format) {
            case self::FORMAT_XLSX:
                return 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet';
            case self::FORMAT_XLS:
                return 'application/vnd.ms-excel';
            case self::FORMAT_CSV:
                return 'text/csv';
            case self::FORMAT_ODS:
                return 'application/vnd.oasis.opendocument.spreadsheet';
        }

        throw new \Exception("Unknown format {$format}");
    }
}<commit_msg>Fixed input format detection<commit_after><?php
namespace Imtigger\OneExcel\Writer;

use Imtigger\OneExcel\OneExcelWriterInterface;

abstract class OneExcelWriter implements OneExcelWriterInterface
{
    public static $input_format_supported = [];
    public static $output_format_supported = [];
    public static $input_output_same_format;

    protected function isInputFormatSupported($format)
    {
        return in_array($format, static::$input_format_supported);
    }


    protected function isOutputFormatSupported($format)
    {
        return in_array($format, static::$output_format_supported);
    }

    protected function checkFormatSupported($output_format, $input_format = null)
    {
        if (static::$input_output_same_format == true && $input_format != null && $input_format != $output_format) {
            throw new \Exception("Input format and output format needed to be the same {$input_format} for " . static::class);
        }

        if ($input_format != null && !$this->isInputFormatSupported($input_format)) {
            throw new \Exception("Input format {$input_format} is not supported by " . static::class);
        }

        if (!$this->isOutputFormatSupported($output_format)) {
            throw new \Exception("Output format {$output_format} is not supported by " . static::class);
        }
    }

    protected function autoDetectInputFormat($filename, &$input_format)
    {
        if ($input_format == self::FORMAT_AUTO) {
            $input_format = self::guessFormatFromFilename($filename);
        }
    }

    protected function guessFormatFromFilename($filename)
    {
        $pathinfo = pathinfo($filename);

        switch(strtolower($pathinfo['extension'])) {
            case 'csv':
                return OneExcelWriterInterface::FORMAT_CSV;
            case 'xls':
                return OneExcelWriterInterface::FORMAT_XLS;
            case 'xlsx':
                return OneExcelWriterInterface::FORMAT_XLSX;
            case 'ods':
                return OneExcelWriterInterface::FORMAT_ODS;
            default:
                throw new \Exception("Could not guess format for filename {$filename}");
        }
    }

    protected function getFormatMime($format)
    {
        switch ($format) {
            case self::FORMAT_XLSX:
                return 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet';
            case self::FORMAT_XLS:
                return 'application/vnd.ms-excel';
            case self::FORMAT_CSV:
                return 'text/csv';
            case self::FORMAT_ODS:
                return 'application/vnd.oasis.opendocument.spreadsheet';
        }

        throw new \Exception("Unknown format {$format}");
    }
}
{'fraction_non_alphanumeric': 0.10202952029520296, 'fraction_numerical': 0.0, 'mean_word_length': 2.6188251001335114, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, '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': '926994', 'n_tokens_mistral': 1444, 'n_tokens_neox': 1381, 'n_words': 303}