<commit_before><?php
namespace Ddeboer\DocumentManipulationBundle\File;

use Symfony\Component\HttpFoundation\File\File as SymfonyFile;

/**
 * Generic file object
 */
class File extends SymfonyFile
{
    /**
     * @var File
     */
    protected $file;

    protected $contents;

    /**
     * Create file object from filename
     *
     * @param string $filename
     *
     * @return \self
     */
    public static function fromFilename($filename)
    {
        return new self($filename);
    }

    /**
     * Create file object from file contents
     *
     * @param string $string
     *
     * @return \self
     */
    public static function fromString($string)
    {
        // Try to determine file extension
        $finfo = new \finfo(FILEINFO_MIME_TYPE);
        $extension = null;
        switch ($finfo->buffer($string)) {
            case 'application/pdf':
                $extension = '.pdf';
                break;

            case 'application/msword':
            case 'application/zip':
                $finfo2 = new \finfo();
                $info = $finfo2->buffer($string);
                switch ($info) {
                    case 'Microsoft Office Document Microsoft Word Document':
                        $extension = '.doc';
                        break;

                    case 'Microsoft Word 2007+':
                    default:
                        $extension = '.docx';
                        break;
                }
        }

        $filename = sys_get_temp_dir() . '/' . md5($string) . $extension;
        file_put_contents($filename, $string);

        return new self($filename);
    }

    /**
     * Get file contents as string
     *
     * @return string
     */
    public function getContents()
    {
        if (null === $this->contents) {
            $this->contents = \file_get_contents($this->getPathname());
        }

        return $this->contents;
    }


    /**
     * Get MD5 hash based on this file's contents
     *
     * @return type
     */
    public function getHash()
    {
        return md5($this->getContents());<commit_msg>Change self into static<commit_after><?php
namespace Ddeboer\DocumentManipulationBundle\File;

use Symfony\Component\HttpFoundation\File\File as SymfonyFile;

/**
 * Generic file object
 */
class File extends SymfonyFile
{
    /**
     * @var File
     */
    protected $file;

    protected $contents;

    /**
     * Create file object from filename
     *
     * @param string $filename
     *
     * @return \self
     */
    public static function fromFilename($filename)
    {
        return new self($filename);
    }

    /**
     * Create file object from file contents
     *
     * @param string $string
     *
     * @return \self
     */
    public static function fromString($string)
    {
        // Try to determine file extension
        $finfo = new \finfo(FILEINFO_MIME_TYPE);
        $extension = null;
        switch ($finfo->buffer($string)) {
            case 'application/pdf':
                $extension = '.pdf';
                break;

            case 'application/msword':
            case 'application/zip':
                $finfo2 = new \finfo();
                $info = $finfo2->buffer($string);
                switch ($info) {
                    case 'Microsoft Office Document Microsoft Word Document':
                        $extension = '.doc';
                        break;

                    case 'Microsoft Word 2007+':
                    default:
                        $extension = '.docx';
                        break;
                }
        }

        $filename = sys_get_temp_dir() . '/' . md5($string) . $extension;
        file_put_contents($filename, $string);

        return new static($filename);
    }

    /**
     * Get file contents as string
     *
     * @return string
     */
    public function getContents()
    {
        if (null === $this->contents) {
            $this->contents = \file_get_contents($this->getPathname());
        }

        return $this->contents;
    }


    /**
     * Get MD5 hash based on this file's contents
     *
     * @return type
     */
    public function getHash()
    {
        return md5($this->getContents());
{'fraction_non_alphanumeric': 0.1140018921475875, 'fraction_numerical': 0.004257332071901609, 'mean_word_length': 1.5112826603325415, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 17, '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': '2585122', 'n_tokens_mistral': 1148, 'n_tokens_neox': 1091, 'n_words': 280}