GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — master ( f0511a...373a16 )
by Steffen
02:21
created

EcbClientMock   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 77
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 3
dl 0
loc 77
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
B __construct() 0 23 5
A getExchangeRates() 0 4 1
A createResponseFromFile() 0 4 1
1
<?php
2
3
namespace SteffenBrand\CurrCurr\Client;
4
5
use GuzzleHttp\Psr7\Response;
6
use Psr\Http\Message\ResponseInterface;
7
use Psr\SimpleCache\CacheInterface;
8
use SteffenBrand\CurrCurr\Exception\ExchangeRatesRequestFailedException;
9
use SteffenBrand\CurrCurr\Mapper\ExchangeRatesMapper;
10
use SteffenBrand\CurrCurr\Mapper\MapperInterface;
11
use SteffenBrand\CurrCurr\Model\ExchangeRate;
12
13
class EcbClientMock implements EcbClientInterface
14
{
15
16
    /**
17
     * @const string
18
     */
19
    const VALID_RESPONSE = 'ValidResponse';
20
21
    /**
22
     * @const string
23
     */
24
    const USD_MISSING_RESPONSE = 'UsdMissingResponse';
25
26
    /**
27
     * @const string
28
     */
29
    const DATE_MISSING_RESPONSE = 'DateMissingResponse';
30
31
    /**
32
     * @var ResponseInterface
33
     */
34
    private $response;
35
36
    /**
37
     * @var MapperInterface
38
     */
39
    private $mapper;
40
41
    /**
42
     * @param string $expectedResponse
43
     * @param CacheInterface $cache
44
     * @param int $cacheTimeInSeconds
45
     * @param MapperInterface $mapper
46
     */
47
    public function __construct(string $expectedResponse = self::VALID_RESPONSE,
48
                                CacheInterface $cache = null,
49
                                int $cacheTimeInSeconds = self::CACHE_UNTIL_MIDNIGHT,
50
                                MapperInterface $mapper = null)
51
    {
52
53
        if (null === $mapper) {
54
            $mapper = new ExchangeRatesMapper();
55
        }
56
        $this->mapper = $mapper;
57
58
        switch ($expectedResponse) {
59
            case self::VALID_RESPONSE:
60
                $this->response = $this->createResponseFromFile(__DIR__ . '/../../resources/eurofxref-daily-valid.xml');
61
                break;
62
            case self::USD_MISSING_RESPONSE:
63
                $this->response = $this->createResponseFromFile(__DIR__ . '/../../resources/eurofxref-daily-usd-missing.xml');
64
                break;
65
            case self::DATE_MISSING_RESPONSE:
66
                $this->response = $this->createResponseFromFile(__DIR__ . '/../../resources/eurofxref-daily-date-missing.xml');
67
                break;
68
        }
69
    }
70
71
    /**
72
     * @throws ExchangeRatesRequestFailedException
73
     * @return ExchangeRate[]
74
     */
75
    public function getExchangeRates(): array
76
    {
77
        return $this->mapper->map($this->response);
78
    }
79
80
    /**
81
     * @param string $file
82
     * @return Response
83
     */
84
    private function createResponseFromFile(string $file): Response
85
    {
86
        return new Response(200, [], file_get_contents($file));
87
    }
88
89
}