<commit_before><?php

namespace App;

use App\Interfaces\ImageArchiveInterface;

class ImageArchive
{
    public static function getExtension($name)
    {
        $extension = [];

        $result = preg_match('/\.(\w+)$/m', $name, $extension);

        return $result != 0 ? $extension[1] : false;
    }

    public static function isJunk($name)
    {
        return preg_match('/^(__MACOSX|\.DS_STORE)/m', $name) == true;
    }

    public static function isImage($name)
    {
        // there are some images in junk folders that we don't care about
        if (ImageArchive::isJunk($name) != true) {
            $image_extensions = [
                'jpg',
                'jpeg',
                'png',
                'gif' // really rare but I've come across this.
            ];

            return in_array(self::getExtension($name), $image_extensions);
        }

        return false;
    }

    /**
     *  Opens an archive for accessing image files.
     *
     *  @param string $file_path The file path to the archive.
     *  @return ImageArchiveInterface|false
     */
    public static function open($file_path)
    {
        $extension = ImageArchive::getExtension($file_path);

        if (preg_match("/zip|cbz/i", $extension))
            return new ImageArchiveZip($file_path);
        elseif (preg_match("/rar|cbr/i", $extension))
            return new ImageArchiveRar($file_path);<commit_msg>Minor tweaks to regex and doc.<commit_after><?php

namespace App;

use App\Interfaces\ImageArchiveInterface;

class ImageArchive
{
    /**
     * Gets the extension from a file name.
     *
     * @param string $name
     * @return string|false
     */
    public static function getExtension(string $name)
    {
        $extension = [];

        $result = preg_match('/\.(\w+)$/', $name, $extension);

        return $result && ! empty($extension) ? $extension[1] : false;
    }

    /**
     * Indicates whether an image should be considered useless based on its name.
     *
     * @param string $name
     * @return bool
     */
    public static function isJunk(string $name)
    {
        return preg_match('/^(__MACOSX|\.DS_STORE)/', $name) != false;
    }

    /**
     * Indicates whether a file is an image or not based on its name.
     *
     * @param $name
     * @return bool
     */
    public static function isImage(string $name)
    {
        // there are some images in junk folders that we don't care about
        return ! ImageArchive::isJunk($name) ?
            preg_match('/jpe?g|png|gif/i', self::getExtension($name)) :
            false;
    }

    /**
     *  Opens an archive for accessing image files.
     *
     *  @param string $file_path The file path to the archive.
     *  @return ImageArchiveInterface|false
     */
    public static function open($file_path)
    {
        $extension = ImageArchive::getExtension($file_path);

        if (preg_match('/zip|cbz/i', $extension))
            return new ImageArchiveZip($file_path);
        elseif (preg_match('/rar|cbr/i', $extension))
            return new ImageArchiveRar($file_path);
{'fraction_non_alphanumeric': 0.12398834574295889, 'fraction_numerical': 0.0009711880867594691, 'mean_word_length': 2.208722741433022, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, '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': '6677068', 'n_tokens_mistral': 931, 'n_tokens_neox': 892, 'n_words': 240}