<commit_before><?php

/**
 * @author <NAME> <<EMAIL>>
 */
class UploadedFile {
    /**
     * @var CUploadedFile
     */
    public $file;

    public function __construct($name) {
        $this->file = CUploadedFile::getInstanceByName($name);
    }

    /**
     * Verifies whether the file extension is in given list.
     * @param array $extensions The expected file extensions (without dot).
     * @return bool Returns whether the file extension can be found in the given list.
     */
    public function isExtensionInList($extensions) {
        $actual = $this->file->getExtensionName();
        foreach ($extensions as $expected) {
            if (0 === strcasecmp($actual, ltrim($expected, '.'))) {
                return true;
            }
        }

        return false;
    }

    /**
     * Verifies whether the file MIME type is in given list.
     * @param array $mimeTypes The expected file MIME types.
     * @return boolean Returns whether the file MIME type can be found in the given list.
     */
    public function isMimeTypeInList($mimeTypes) {
        $fileName = $this->file->getTempName();
        $actual = CFileHelper::getMimeType($fileName);
        if (empty($actual)) {
            $actual = $this->file->getType();
        }

        if (empty($actual)) {
            return false;
        }

        foreach ($mimeTypes as $expected) {
            if (0 === strcasecmp($expected, $actual)) {
                return true;
            }
        }

        return false;
    }

    /**
     * Verifies whether the file is an image and its type is in given list.
     * @param array $imageTypes The expected image types.
     * @return boolean Returns whether the file is an image AND its type matches one of the types in the given list.
     */
    public function isImageTypeInList($imageTypes) {
        $fileName = $this->file->getTempName();
        $imageType = @exif_imagetype($fileName);
        if (false === $imageType) {
            return false;
        }

        return in_array($imageType, $imageTypes, true);
    }

    /**
     * Verifies whether the image dimensions are in range.
     * @param int $maxWidth Maximum allowed image width; pass a NULL if you don't want to limit the image width.
     * @param int $maxHeight Maximum allowed image height; pass a NULL if you don't want to limit the image height.
     * @param int $minWidth Minimum allowed image width; pass a NULL if you don't want to limit the image width.
     * @param int $minHeight Minimum allowed image height; pass a NULL if you don't want to limit the image height.
     * @return int Returns
     *  1 if the image exceeds maximum allowed width;
     *  2 if the image exceeds maximum allowed height;
     *  3 if the image exceeds minimum allowed width;
     *  4 if the image exceeds minimum allowed height.
     */
    public function validateImageDimensions($maxWidth, $maxHeight, $minWidth, $minHeight) {
        $fileName = $this->file->getTempName();
        $size = @getimagesize($fileName);
<commit_msg>Use getimagesize instead of exif_imagetype<commit_after><?php

/**
 * @author <NAME> <<EMAIL>>
 */
class UploadedFile {
    /**
     * @var CUploadedFile
     */
    public $file;

    public function __construct($name) {
        $this->file = CUploadedFile::getInstanceByName($name);
    }

    /**
     * Verifies whether the file extension is in given list.
     * @param array $extensions The expected file extensions (without dot).
     * @return bool Returns whether the file extension can be found in the given list.
     */
    public function isExtensionInList($extensions) {
        $actual = $this->file->getExtensionName();
        foreach ($extensions as $expected) {
            if (0 === strcasecmp($actual, ltrim($expected, '.'))) {
                return true;
            }
        }

        return false;
    }

    /**
     * Verifies whether the file MIME type is in given list.
     * @param array $mimeTypes The expected file MIME types.
     * @return boolean Returns whether the file MIME type can be found in the given list.
     */
    public function isMimeTypeInList($mimeTypes) {
        $fileName = $this->file->getTempName();
        $actual = CFileHelper::getMimeType($fileName);
        if (empty($actual)) {
            $actual = $this->file->getType();
        }

        if (empty($actual)) {
            return false;
        }

        foreach ($mimeTypes as $expected) {
            if (0 === strcasecmp($expected, $actual)) {
                return true;
            }
        }

        return false;
    }

    /**
     * Verifies whether the file is an image and its type is in given list.
     * @param array $imageTypes The expected image types.
     * @return boolean Returns whether the file is an image AND its type matches one of the types in the given list.
     */
    public function isImageTypeInList($imageTypes) {
        $fileName = $this->file->getTempName();
        $imageInfo = @getimagesize($fileName);
        $imageType = is_array($imageInfo) && isset($imageInfo[2]) ? $imageInfo[2] : null;
        if (is_null($imageType)) {
            return false;
        }

        return in_array($imageType, $imageTypes, true);
    }

    /**
     * Verifies whether the image dimensions are in range.
     * @param int $maxWidth Maximum allowed image width; pass a NULL if you don't want to limit the image width.
     * @param int $maxHeight Maximum allowed image height; pass a NULL if you don't want to limit the image height.
     * @param int $minWidth Minimum allowed image width; pass a NULL if you don't want to limit the image width.
     * @param int $minHeight Minimum allowed image height; pass a NULL if you don't want to limit the image height.
     * @return int Returns
     *  1 if the image exceeds maximum allowed width;
     *  2 if the image exceeds maximum allowed height;
     *  3 if the image exceeds minimum allowed width;
     *  4 if the image exceeds minimum allowed height.
     */
    public function validateImageDimensions($maxWidth, $maxHeight, $minWidth, $minHeight) {
        $fileName = $this->file->getTempName();
        $size = @getimagesize($fileName);

{'fraction_non_alphanumeric': 0.10038797284190107, 'fraction_numerical': 0.0022631749110895573, 'mean_word_length': 2.377183406113537, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 31, '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': '6096452', 'n_tokens_mistral': 1683, 'n_tokens_neox': 1645, 'n_words': 630}