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 ( 2a232d...928c5b )
by Steffen
02:49
created

EcbClientMock::createStreamFromXmlFile()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 9
rs 9.6666
c 0
b 0
f 0
cc 1
eloc 5
nc 1
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
    /**
16
     * @var ResponseInterface
17
     */
18
    private $response;
19
20
    /**
21
     * @param string $expectedResponse
22
     */
23
    public function __construct(string $expectedResponse)
24
    {
25
        switch ($expectedResponse) {
26
            case 'ValidResponse':
27
                $this->response = new Response(
28
                    200,
29
                    [],
30
                    $this->createStreamFromXmlFile(__DIR__ . '/../../resources/eurofxref-daily-valid.xml')
31
                );
32
                break;
33
            case 'UsdMissingResponse':
34
                $this->response = new Response(
35
                    200,
36
                    [],
37
                    $this->createStreamFromXmlFile(__DIR__ . '/../../resources/eurofxref-daily-usd-missing.xml')
38
                );
39
                break;
40
            case 'DateMissingResponse':
41
                $this->response = new Response(
42
                    200,
43
                    [],
44
                    $this->createStreamFromXmlFile(__DIR__ . '/../../resources/eurofxref-daily-date-missing.xml')
45
                );
46
                break;
47
        }
48
    }
49
50
    /**
51
     * @throws ExchangeRatesRequestFailedException
52
     * @return ExchangeRate[]
53
     */
54
    public function getExchangeRates(): array
55
    {
56
        $mapper = new ExchangeRatesMapper();
57
        return $mapper->map($this->response);
58
    }
59
60
    /**
61
     * @param string $file
62
     * @return Stream
63
     */
64
    private function createStreamFromXmlFile(string $file): Stream
65
    {
66
        return new Stream(
67
            fopen(
68
                'data://application/xml,' . file_get_contents($file),
69
                'r'
70
            )
71
        );
72
    }
73
74
}