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 ( e71513...2611f3 )
by Steffen
02:35
created

EcbClientMock::__construct()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 14
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 14
rs 9.2
c 0
b 0
f 0
cc 4
eloc 11
nc 4
nop 1
1
<?php
2
3
namespace SteffenBrand\CurrCurr\Client;
4
5
use GuzzleHttp\Psr7\Response;
6
use GuzzleHttp\Psr7\Stream;
7
use Psr\Http\Message\ResponseInterface;
8
use SteffenBrand\CurrCurr\Exception\ExchangeRatesRequestFailedException;
9
use SteffenBrand\CurrCurr\Mapper\ExchangeRatesMapper;
10
use SteffenBrand\CurrCurr\Model\ExchangeRate;
11
12
class EcbClientMock implements EcbClientInterface
13
{
14
15
    const VALID_RESPONSE = 'ValidResponse';
16
    const USD_MISSING_RESPONSE = 'UsdMissingResponse';
17
    const DATE_MISSING_RESPONSE = 'DateMissingResponse';
18
19
    /**
20
     * @var ResponseInterface
21
     */
22
    private $response;
23
24
    /**
25
     * @param string $expectedResponse
26
     */
27
    public function __construct(string $expectedResponse)
28
    {
29
        switch ($expectedResponse) {
30
            case self::VALID_RESPONSE:
31
                $this->response = $this->createResponseFromFile(__DIR__ . '/../../resources/eurofxref-daily-valid.xml');
32
                break;
33
            case self::USD_MISSING_RESPONSE:
34
                $this->response = $this->createResponseFromFile(__DIR__ . '/../../resources/eurofxref-daily-usd-missing.xml');
35
                break;
36
            case self::DATE_MISSING_RESPONSE:
37
                $this->response = $this->createResponseFromFile(__DIR__ . '/../../resources/eurofxref-daily-date-missing.xml');
38
                break;
39
        }
40
    }
41
42
    /**
43
     * @throws ExchangeRatesRequestFailedException
44
     * @return ExchangeRate[]
45
     */
46
    public function getExchangeRates(): array
47
    {
48
        $mapper = new ExchangeRatesMapper();
49
        return $mapper->map($this->response);
50
    }
51
52
    /**
53
     * @param string $file
54
     * @return Response
55
     */
56
    private function createResponseFromFile(string $file)
57
    {
58
        return new Response(200, [], file_get_contents($file));
59
    }
60
61
}