<commit_before><?php

namespace SteffenBrand\CurrCurr\Client;

use GuzzleHttp\Psr7\Response;
use Psr\Http\Message\ResponseInterface;
use Psr\SimpleCache\CacheInterface;
use SteffenBrand\CurrCurr\Exception\ExchangeRatesRequestFailedException;
use SteffenBrand\CurrCurr\Mapper\ExchangeRatesMapper;
use SteffenBrand\CurrCurr\Mapper\MapperInterface;
use SteffenBrand\CurrCurr\Model\ExchangeRate;

class EcbClientMock implements EcbClientInterface
{

    /**
     * @const string
     */
    const VALID_RESPONSE = 'ValidResponse';

    /**
     * @const string
     */
    const USD_MISSING_RESPONSE = 'UsdMissingResponse';

    /**
     * @const string
     */
    const DATE_MISSING_RESPONSE = 'DateMissingResponse';

    /**
     * @var ResponseInterface
     */
    private $response;

    /**
     * @var MapperInterface
     */
    private $mapper;

    /**
     * @param string $expectedResponse
     * @param CacheInterface $cache
     * @param int $cacheTimeInSeconds
     * @param MapperInterface $mapper
     */
    public function __construct(string $expectedResponse = self::VALID_RESPONSE,
                                CacheInterface $cache = null,
                                int $cacheTimeInSeconds = self::CACHE_UNTIL_MIDNIGHT,
                                MapperInterface $mapper = null)
    {

        if (null === $mapper) {
            $mapper = new ExchangeRatesMapper();
        }
        $this->mapper = $mapper;

        switch ($expectedResponse) {
            case self::VALID_RESPONSE:
                $this->response = $this->createResponseFromFile(__DIR__ . '/../../resources/eurofxref-daily-valid.xml');
                break;
            case self::USD_MISSING_RESPONSE:
                $this->response = $this->createResponseFromFile(__DIR__ . '/../../resources/eurofxref-daily-usd-missing.xml');
                break;
            case self::DATE_MISSING_RESPONSE:
                $this->response = $this->createResponseFromFile(__DIR__ . '/../../resources/eurofxref-daily-date-missing.xml');
                break;
        }
    }

    /**
     * @throws ExchangeRatesRequestFailedException
     * @return ExchangeRate[]
     */
    public function getExchangeRates(): array
    {
        return $this->mapper->map($this->response);
    }

    /**
     * @param string $file
     * @return Response
     */
    private function createResponseFromFile(string $file): Response
    {
        return new Response(200, [], file_get_contents($file));
    }

}<commit_msg>code cleanup<commit_after><?php

namespace SteffenBrand\CurrCurr\Client;

use GuzzleHttp\Psr7\Response;
use Psr\Http\Message\ResponseInterface;
use Psr\SimpleCache\CacheInterface;
use SteffenBrand\CurrCurr\Exception\ExchangeRatesRequestFailedException;
use SteffenBrand\CurrCurr\Mapper\ExchangeRatesMapper;
use SteffenBrand\CurrCurr\Mapper\MapperInterface;
use SteffenBrand\CurrCurr\Model\ExchangeRate;

class EcbClientMock implements EcbClientInterface
{

    /**
     * @const string
     */
    const VALID_RESPONSE = 'ValidResponse';

    /**
     * @const string
     */
    const USD_MISSING_RESPONSE = 'UsdMissingResponse';

    /**
     * @const string
     */
    const DATE_MISSING_RESPONSE = 'DateMissingResponse';

    /**
     * @var ResponseInterface
     */
    private $response;

    /**
     * @var MapperInterface
     */
    private $mapper;

    /**
     * @param string $expectedResponse
     * @param CacheInterface $cache
     * @param int $cacheTimeInSeconds
     * @param MapperInterface $mapper
     */
    public function __construct(string $expectedResponse = self::VALID_RESPONSE,
                                CacheInterface $cache = null,
                                int $cacheTimeInSeconds = self::CACHE_UNTIL_MIDNIGHT,
                                MapperInterface $mapper = null)
    {
        if (null === $mapper) {
            $mapper = new ExchangeRatesMapper();
        }
        $this->mapper = $mapper;

        switch ($expectedResponse) {
            case self::VALID_RESPONSE:
                $this->response = $this->createResponseFromFile(__DIR__ . '/../../resources/eurofxref-daily-valid.xml');
                break;
            case self::USD_MISSING_RESPONSE:
                $this->response = $this->createResponseFromFile(__DIR__ . '/../../resources/eurofxref-daily-usd-missing.xml');
                break;
            case self::DATE_MISSING_RESPONSE:
                $this->response = $this->createResponseFromFile(__DIR__ . '/../../resources/eurofxref-daily-date-missing.xml');
                break;
        }
    }

    /**
     * @throws ExchangeRatesRequestFailedException
     * @return ExchangeRate[]
     */
    public function getExchangeRates(): array
    {
        return $this->mapper->map($this->response);
    }

    /**
     * @param string $file
     * @return Response
     */
    private function createResponseFromFile(string $file): Response
    {
        return new Response(200, [], file_get_contents($file));
    }

}
{'fraction_non_alphanumeric': 0.11417165668662675, 'fraction_numerical': 0.0015968063872255488, 'mean_word_length': 2.2644951140065146, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 6}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4711859', 'n_tokens_mistral': 1503, 'n_tokens_neox': 1424, 'n_words': 245}