<commit_before><?php

namespace Tekstove\SiteBundle\Model\Gateway\Tekstove\Client\Guzzle;

use Tekstove\SiteBundle\Model\Gateway\Tekstove\Client\ClientInterface;
use GuzzleHttp\Client as GuzzleClient;

use Tekstove\SiteBundle\Model\Gateway\Tekstove\Client\Exception\RequestException as TekstoveRequestException;
use Tekstove\SiteBundle\Model\Gateway\Tekstove\Client\Exception\NotFoundException as TesktoveNotFoundException;
use GuzzleHttp\Exception\RequestException as GuzzleRequestException;

use Tekstove\SiteBundle\Model\Gateway\Tekstove\Client\Response as TekstoveResponse;

/**
 * Description of GuzzleAdapter
 *
 * @author po_taka
 */
class GuzzleAdapter implements ClientInterface
{
    private $guzzle;
    
    public function __construct()
    {
        $this->guzzle = new GuzzleClient([]);
    }
    
    public function setBaseUri($uri)
    {
        $this->baseUri = $uri;
        $config = $this->guzzle->getConfig();
        $config['base_uri'] = $uri;
        $this->guzzle = new GuzzleClient($config);
    }
    
    public function post($url, $data)
    {
        try {
            $response = $this->guzzle->post($url, $data);
            $tekstoveResponse = new TekstoveResponse($response->getBody()->getContents());
            return $tekstoveResponse;
        } catch (GuzzleRequestException $e) {
            $tekstoveException = new TekstoveRequestException(
                $e->getMessage(),
                $e->getCode(),
                $e->getPrevious()
            );
            
            $response = $e->getResponse();
            $responseBody = $response->getBody()->getContents();
            $tekstoveException->setBody($responseBody);
            
            throw $tekstoveException;
        }
    }
    
    public function patch($url, $data)
    {
        try {
            $response = $this->guzzle->patch($url, $data);
            $tekstoveResponse = new TekstoveResponse($response->getBody()->getContents());
            return $tekstoveResponse;
        } catch (GuzzleRequestException $e) {
            $tekstoveException = new TekstoveRequestException(
                $e->getMessage(),
                $e->getCode(),
                $e->getPrevious()
            );
            
            $response = $e->getResponse();
            $responseBody = $response->getBody()->getContents();
            $tekstoveException->setBody($responseBody);
            
            throw $tekstoveException;
        }
    }
    
    /**
     * {@inheritdoc}
     */
    public function delete($url)
    {
        try {
            $response = $this->guzzle->delete($url);
            $tekstoveResponse = new TekstoveResponse($response->getBody()->getContents());
            return $tekstoveResponse;
        } catch (GuzzleRequestException $e) {
            $tekstoveException = new TekstoveRequestException(
                $e->getMessage(),
                $e->getCode(),
                $e->getPrevious()
            );
            
            $response = $e->getResponse();
            $responseBody = $response->getBody()->getContents();
            $tekstoveException->setBody($responseBody);
            
            throw $tekstoveException;
        }
    }
    
    /**
     * {@inheritdoc}
     */
    public function get($url)
    {
        try {
        $guzzleResponse = $this->guzzle->get($url);
        } catch (GuzzleRequestException $e) {
            $tekstoveException = new TesktoveNotFoundException(
                $e->getMessage(),
                $e->getCode(),
                $e->getPrevious()
            );
            
            $response = $e->getResponse();
            $responseBody = $response->getBody()->getContents();
            $tekstoveException->setBody($responseBody);
            
            throw $tekstoveException;
        }
        $tekstoveResponse = new TekstoveResponse($guzzleResponse->getBody());
        return $tekstoveResponse;
    }<commit_msg>code style<commit_after><?php

namespace Tekstove\SiteBundle\Model\Gateway\Tekstove\Client\Guzzle;

use Tekstove\SiteBundle\Model\Gateway\Tekstove\Client\ClientInterface;
use GuzzleHttp\Client as GuzzleClient;

use Tekstove\SiteBundle\Model\Gateway\Tekstove\Client\Exception\RequestException as TekstoveRequestException;
use Tekstove\SiteBundle\Model\Gateway\Tekstove\Client\Exception\NotFoundException as TesktoveNotFoundException;
use GuzzleHttp\Exception\RequestException as GuzzleRequestException;

use Tekstove\SiteBundle\Model\Gateway\Tekstove\Client\Response as TekstoveResponse;

/**
 * Description of GuzzleAdapter
 *
 * @author po_taka
 */
class GuzzleAdapter implements ClientInterface
{
    private $guzzle;
    
    public function __construct()
    {
        $this->guzzle = new GuzzleClient([]);
    }
    
    public function setBaseUri($uri)
    {
        $this->baseUri = $uri;
        $config = $this->guzzle->getConfig();
        $config['base_uri'] = $uri;
        $this->guzzle = new GuzzleClient($config);
    }
    
    public function post($url, $data)
    {
        try {
            $response = $this->guzzle->post($url, $data);
            $tekstoveResponse = new TekstoveResponse($response->getBody()->getContents());
            return $tekstoveResponse;
        } catch (GuzzleRequestException $e) {
            $tekstoveException = new TekstoveRequestException(
                $e->getMessage(),
                $e->getCode(),
                $e->getPrevious()
            );
            
            $response = $e->getResponse();
            $responseBody = $response->getBody()->getContents();
            $tekstoveException->setBody($responseBody);
            
            throw $tekstoveException;
        }
    }
    
    public function patch($url, $data)
    {
        try {
            $response = $this->guzzle->patch($url, $data);
            $tekstoveResponse = new TekstoveResponse($response->getBody()->getContents());
            return $tekstoveResponse;
        } catch (GuzzleRequestException $e) {
            $tekstoveException = new TekstoveRequestException(
                $e->getMessage(),
                $e->getCode(),
                $e->getPrevious()
            );
            
            $response = $e->getResponse();
            $responseBody = $response->getBody()->getContents();
            $tekstoveException->setBody($responseBody);
            
            throw $tekstoveException;
        }
    }
    
    /**
     * {@inheritdoc}
     */
    public function delete($url)
    {
        try {
            $response = $this->guzzle->delete($url);
            $tekstoveResponse = new TekstoveResponse($response->getBody()->getContents());
            return $tekstoveResponse;
        } catch (GuzzleRequestException $e) {
            $tekstoveException = new TekstoveRequestException(
                $e->getMessage(),
                $e->getCode(),
                $e->getPrevious()
            );
            
            $response = $e->getResponse();
            $responseBody = $response->getBody()->getContents();
            $tekstoveException->setBody($responseBody);
            
            throw $tekstoveException;
        }
    }
    
    /**
     * {@inheritdoc}
     */
    public function get($url)
    {
        try {
            $guzzleResponse = $this->guzzle->get($url);
        } catch (GuzzleRequestException $e) {
            $tekstoveException = new TesktoveNotFoundException(
                $e->getMessage(),
                $e->getCode(),
                $e->getPrevious()
            );
            
            $response = $e->getResponse();
            $responseBody = $response->getBody()->getContents();
            $tekstoveException->setBody($responseBody);
            
            throw $tekstoveException;
        }
        $tekstoveResponse = new TekstoveResponse($guzzleResponse->getBody());
        return $tekstoveResponse;
    }
{'fraction_non_alphanumeric': 0.12457186350374223, 'fraction_numerical': 0.0, 'mean_word_length': 1.9795918367346939, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 99, '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': '3838356', 'n_tokens_mistral': 2220, 'n_tokens_neox': 2164, 'n_words': 337}