<commit_before><?php

namespace Embed\ImageInfo;

/**
 * Class to retrieve the size and mimetype of images using curl.
 */
class Curl implements ImageInfoInterface
{
    protected static $mimetypes = [
        'image/jpeg',
        'image/png',
        'image/gif',
        'image/bmp',
        'image/x-icon',
    ];

    protected $connection;
    protected $finfo;
    protected $mime;
    protected $info;
    protected $content = '';
    protected $config = [
        CURLOPT_MAXREDIRS => 20,
        CURLOPT_CONNECTTIMEOUT => 10,
        CURLOPT_TIMEOUT => 10,
        CURLOPT_SSL_VERIFYPEER => 0,
        CURLOPT_SSL_VERIFYHOST => 0,
        CURLOPT_ENCODING => '',
        CURLOPT_AUTOREFERER => true,
        CURLOPT_USERAGENT => 'Embed PHP Library',
        CURLOPT_IPRESOLVE => CURL_IPRESOLVE_V4,
    ];

    /**
     * {@inheritdoc}
     */
    public static function getImagesInfo(array $images, array $config = null)
    {
        if (empty($images)) {
            return [];
        }

        if (count($images) === 1) {
            $info = self::getImageInfo($images[0], $config);

            return empty($info) ? [] : [array_merge($images[0], $info)];
        }

        $finfo = finfo_open(FILEINFO_MIME_TYPE);
        $connections = [];
        $curl = curl_multi_init();

        foreach ($images as $k => $image) {
            $connections[$k] = new static($image['value'], $finfo, $config);

            curl_multi_add_handle($curl, $connections[$k]->getConnection());
        }

        do {
            $return = curl_multi_exec($curl, $active);
        } while ($return === CURLM_CALL_MULTI_PERFORM);

        while ($active && $return === CURLM_OK) {
            if (curl_multi_select($curl) === -1) {
                usleep(100);
            }

            do {
                $return = curl_multi_exec($curl, $active);
            } while ($return === CURLM_CALL_MULTI_PERFORM);
        }

        $result = [];

        foreach ($connections as $k => $connection) {
            curl_multi_remove_handle($curl, $connection->getConnection());

            if (($info = $connection->getInfo())) {
                $result[] = array_merge($images[$k], $info);
            }
        }

        finfo_close($finfo);
        curl_multi_close($curl);

        return $result;
    }

    /**
     * Get the info of only one image.
     *
     * @param string     $image
     * @param null|array $config
     *
     * @return array|null
     */
    public static function getImageInfo($image, array $config = null)
    {
        $finfo = finfo_open(FILEINFO_MIME_TYPE);
        $img = new static($image['value'], $finfo, $config);

        $curl = $img->getConnection();
        curl_exec($curl);
        curl_close($curl);

        $info = $img->getInfo();

        finfo_close($finfo);

        return $info;
    }

    /**
     * Init the curl connection.
     *
     * @param string     $url    The image url
     * @param resource   $finfo  A fileinfo resource to get the mimetype
     * @param null|array $config Custom options for the curl request
     */
    public function __construct($url, $finfo, array $config = null)
    {
        $this->finfo = $finfo;
        $this->connection = curl_init();

        if ($config) {
            $this->config = array_replace($this->config, $config);
        }
<commit_msg>changed visibility of Embed\ImageInfo\Curl::getImageInfo to private, because it's out of the interface<commit_after><?php

namespace Embed\ImageInfo;

/**
 * Class to retrieve the size and mimetype of images using curl.
 */
class Curl implements ImageInfoInterface
{
    protected static $mimetypes = [
        'image/jpeg',
        'image/png',
        'image/gif',
        'image/bmp',
        'image/x-icon',
    ];

    protected $connection;
    protected $finfo;
    protected $mime;
    protected $info;
    protected $content = '';
    protected $config = [
        CURLOPT_MAXREDIRS => 20,
        CURLOPT_CONNECTTIMEOUT => 10,
        CURLOPT_TIMEOUT => 10,
        CURLOPT_SSL_VERIFYPEER => 0,
        CURLOPT_SSL_VERIFYHOST => 0,
        CURLOPT_ENCODING => '',
        CURLOPT_AUTOREFERER => true,
        CURLOPT_USERAGENT => 'Embed PHP Library',
        CURLOPT_IPRESOLVE => CURL_IPRESOLVE_V4,
    ];

    /**
     * {@inheritdoc}
     */
    public static function getImagesInfo(array $images, array $config = null)
    {
        if (empty($images)) {
            return [];
        }

        if (count($images) === 1) {
            $info = self::getImageInfo($images[0], $config);

            return empty($info) ? [] : [array_merge($images[0], $info)];
        }

        $finfo = finfo_open(FILEINFO_MIME_TYPE);
        $connections = [];
        $curl = curl_multi_init();

        foreach ($images as $k => $image) {
            $connections[$k] = new static($image['value'], $finfo, $config);

            curl_multi_add_handle($curl, $connections[$k]->getConnection());
        }

        do {
            $return = curl_multi_exec($curl, $active);
        } while ($return === CURLM_CALL_MULTI_PERFORM);

        while ($active && $return === CURLM_OK) {
            if (curl_multi_select($curl) === -1) {
                usleep(100);
            }

            do {
                $return = curl_multi_exec($curl, $active);
            } while ($return === CURLM_CALL_MULTI_PERFORM);
        }

        $result = [];

        foreach ($connections as $k => $connection) {
            curl_multi_remove_handle($curl, $connection->getConnection());

            if (($info = $connection->getInfo())) {
                $result[] = array_merge($images[$k], $info);
            }
        }

        finfo_close($finfo);
        curl_multi_close($curl);

        return $result;
    }

    /**
     * Get the info of only one image.
     *
     * @param string     $image
     * @param null|array $config
     *
     * @return array|null
     */
    private static function getImageInfo($image, array $config = null)
    {
        $finfo = finfo_open(FILEINFO_MIME_TYPE);
        $img = new static($image['value'], $finfo, $config);

        $curl = $img->getConnection();
        curl_exec($curl);
        curl_close($curl);

        $info = $img->getInfo();

        finfo_close($finfo);

        return $info;
    }

    /**
     * Init the curl connection.
     *
     * @param string     $url    The image url
     * @param resource   $finfo  A fileinfo resource to get the mimetype
     * @param null|array $config Custom options for the curl request
     */
    public function __construct($url, $finfo, array $config = null)
    {
        $this->finfo = $finfo;
        $this->connection = curl_init();

        if ($config) {
            $this->config = array_replace($this->config, $config);
        }

{'fraction_non_alphanumeric': 0.13720861611094717, 'fraction_numerical': 0.00472115668338743, 'mean_word_length': 2.0155693950177938, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 43, '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': '7424169', 'n_tokens_mistral': 2154, 'n_tokens_neox': 2016, 'n_words': 449}