<commit_before><?php

namespace Markup\OEmbedBundle\Client;

use GuzzleHttp\Exception\GuzzleException;
use Markup\OEmbedBundle\Exception\OEmbedUnavailableException;
use Markup\OEmbedBundle\OEmbed\OEmbedFactory;
use Markup\OEmbedBundle\OEmbed\OEmbedInterface;
use Markup\OEmbedBundle\Provider\ProviderInterface;

class GuzzleClient extends AbstractClient
{
    /**
     * @var \GuzzleHttp\ClientInterface
     */
    private $guzzle;

    public function __construct(\GuzzleHttp\ClientInterface $guzzle = null)
    {
        $this->guzzle = $guzzle;
    }

    /**
     * Fetches an oEmbed instance from the provider.
     *
     * @param  ProviderInterface $provider
     * @param  string            $mediaId
     * @param  array             $parameters
     * @return OEmbedInterface
     **/
    public function fetchEmbed(ProviderInterface $provider, $mediaId, array $parameters = [])
    {
        $oEmbedUrl = $this->resolveOEmbedUrl($provider, $mediaId, $parameters);
        try {
            $response = $this->guzzle->request('GET', $oEmbedUrl);
        } catch (GuzzleException $e) {
            $response = null;
            $guzzleException = $e;
        } catch (\Exception $e) {
            $response = null;
        } catch (\Throwable $e) {
            $response = null;
        }

        if (!$response || $response->getStatusCode() != 200) {
            throw new OEmbedUnavailableException(
                sprintf(
                    'Trying to get the embed code for media ID %s from provider "%s" failed.',
                    $mediaId,
                    $provider->getName()
                ),
                0,
                (isset($guzzleException)) ? $guzzleException : null);
        }

        return (new OEmbedFactory())->createFromJson((string) $response->getBody(), $provider);
    }
}
<commit_msg>fix(client): If no guzzle client injected create a new instance. (#6)<commit_after><?php

namespace Markup\OEmbedBundle\Client;

use GuzzleHttp\Exception\GuzzleException;
use GuzzleHttp\Client as Guzzle;
use Markup\OEmbedBundle\Exception\OEmbedUnavailableException;
use Markup\OEmbedBundle\OEmbed\OEmbedFactory;
use Markup\OEmbedBundle\OEmbed\OEmbedInterface;
use Markup\OEmbedBundle\Provider\ProviderInterface;

class GuzzleClient extends AbstractClient
{
    /**
     * @var \GuzzleHttp\ClientInterface
     */
    private $guzzle;

    public function __construct(\GuzzleHttp\ClientInterface $guzzle = null)
    {
        $this->guzzle = $guzzle ?: new Guzzle([
            'defaults' => [
                'connect_timeout' => 5,
                'timeout' => 5,
            ]
        ]);
    }

    /**
     * Fetches an oEmbed instance from the provider.
     *
     * @param  ProviderInterface $provider
     * @param  string            $mediaId
     * @param  array             $parameters
     * @return OEmbedInterface
     **/
    public function fetchEmbed(ProviderInterface $provider, $mediaId, array $parameters = [])
    {
        $oEmbedUrl = $this->resolveOEmbedUrl($provider, $mediaId, $parameters);
        try {
            $response = $this->guzzle->request('GET', $oEmbedUrl);
        } catch (GuzzleException $e) {
            $response = null;
            $guzzleException = $e;
        } catch (\Exception $e) {
            $response = null;
        } catch (\Throwable $e) {
            $response = null;
        }

        if (!$response || $response->getStatusCode() != 200) {
            throw new OEmbedUnavailableException(
                sprintf(
                    'Trying to get the embed code for media ID %s from provider "%s" failed.',
                    $mediaId,
                    $provider->getName()
                ),
                0,
                (isset($guzzleException)) ? $guzzleException : null);
        }

        return (new OEmbedFactory())->createFromJson((string) $response->getBody(), $provider);
    }
}

{'fraction_non_alphanumeric': 0.11449795081967214, 'fraction_numerical': 0.0028176229508196722, 'mean_word_length': 2.116520351157223, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 22, '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': '201219', 'n_tokens_mistral': 1159, 'n_tokens_neox': 1066, 'n_words': 243}