<commit_before><?php declare(strict_types=1);

namespace Goose\Images;

use Goose\Configuration;
use GuzzleHttp\{Client, Pool};
use GuzzleHttp\Psr7\Request;

/**
 * Image Utils
 *
 * @package Goose\Images
 * @license http://www.apache.org/licenses/LICENSE-2.0 Apache License 2.0
 */
class ImageUtils {
    /**
     * @param string $filePath
     *
     * @return object|null
     */
    public static function getImageDimensions(string $filePath): ?\stdClass {
        list($width, $height, $type) = getimagesize($filePath);

        if ( $type === null ) {
            return null;
        }

        return (object)[
            'width' => (int)$width,
            'height' => (int)$height,
            'mime' => $type ? image_type_to_mime_type($type) : null,
        ];
    }

    /**
     * Writes an image src http string to disk as a temporary file and returns the LocallyStoredImage object that has the info you should need
     * on the image
     *
     * @param string[] $imageSrcs
     * @param bool $returnAll
     * @param Configuration $config
     *
     * @return LocallyStoredImage[]
     */
    public static function storeImagesToLocalFile($imageSrcs, bool $returnAll, Configuration $config): array {
        $localImages = self::handleEntity($imageSrcs, $returnAll, $config);

        if (empty($localImages)) {
            return [];
        }

        $locallyStoredImages = [];

        foreach ($localImages as $localImage) {
            if (empty($localImage->file) || !filesize($localImage->file)) {
                continue;
            }

            $imageDetails = self::getImageDimensions($localImage->file);

            if ( $imageDetails !== null ) {
                $locallyStoredImages[] = new LocallyStoredImage([
                    'imgSrc' => $localImage->url,
                    'localFileName' => $localImage->file,
                    'bytes' => filesize($localImage->file),
                    'height' => $imageDetails->height,
                    'width' => $imageDetails->width,
                    'fileExtension' => self::getFileExtensionName($imageDetails),
                ]);
            }
        }

        return $locallyStoredImages;
    }

    /**
     * @param object $imageDetails
     *
     * @return string
     */
    private static function getFileExtensionName(\stdClass $imageDetails): string {
        $extensions = [
            'image/gif' => '.gif',
            'image/jpeg' => '.jpg',<commit_msg>Clean-up<commit_after><?php declare(strict_types=1);

namespace Goose\Images;

use Goose\Configuration;
use GuzzleHttp\{Client, Pool};
use GuzzleHttp\Psr7\Request;

/**
 * Image Utils
 *
 * @package Goose\Images
 * @license http://www.apache.org/licenses/LICENSE-2.0 Apache License 2.0
 */
class ImageUtils {
    /**
     * @param string $filePath
     *
     * @return object|null
     */
    public static function getImageDimensions(string $filePath): ?\stdClass {
        list($width, $height, $type) = getimagesize($filePath);

        if ($type === null) {
            return null;
        }

        return (object)[
            'width' => (int)$width,
            'height' => (int)$height,
            'mime' => image_type_to_mime_type($type),
        ];
    }

    /**
     * Writes an image src http string to disk as a temporary file and returns the LocallyStoredImage object that has the info you should need
     * on the image
     *
     * @param string[] $imageSrcs
     * @param bool $returnAll
     * @param Configuration $config
     *
     * @return LocallyStoredImage[]
     */
    public static function storeImagesToLocalFile($imageSrcs, bool $returnAll, Configuration $config): array {
        $localImages = self::handleEntity($imageSrcs, $returnAll, $config);

        if (empty($localImages)) {
            return [];
        }

        $locallyStoredImages = [];

        foreach ($localImages as $localImage) {
            if (empty($localImage->file) || !filesize($localImage->file)) {
                continue;
            }

            $imageDetails = self::getImageDimensions($localImage->file);

            if ($imageDetails !== null) {
                $locallyStoredImages[] = new LocallyStoredImage([
                    'imgSrc' => $localImage->url,
                    'localFileName' => $localImage->file,
                    'bytes' => filesize($localImage->file),
                    'height' => $imageDetails->height,
                    'width' => $imageDetails->width,
                    'fileExtension' => self::getFileExtensionName($imageDetails),
                ]);
            }
        }

        return $locallyStoredImages;
    }

    /**
     * @param object $imageDetails
     *
     * @return string
     */
    private static function getFileExtensionName(\stdClass $imageDetails): string {
        $extensions = [
            'image/gif' => '.gif',
            'image/jpeg' => '.jpg',
{'fraction_non_alphanumeric': 0.13029315960912052, 'fraction_numerical': 0.0024429967426710096, 'mean_word_length': 2.032716049382716, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 41, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '2852138', 'n_tokens_mistral': 1383, 'n_tokens_neox': 1336, 'n_words': 303}