Completed
Push — feature/EVO-7964_fundInfo-exte... ( d593d5 )
by Bastian
08:56
created

FundinfoRequestTransformation::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 4
cp 0
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
crap 2
1
<?php
2
3
namespace Graviton\ProxyBundle\Transformation;
4
5
6
use Symfony\Component\HttpFoundation\Request;
7
8
class FundinfoRequestTransformation implements RequestTransformationInterface
9
{
10
    /** @var array  */
11
    private $configuration;
12
13
    /**
14
     * FundinfoRequestTransformation constructor.
15
     *
16
     * @param array $configuration
17
     */
18
    public function __construct(array $configuration)
19
    {
20
        $this->configuration = $configuration;
21
    }
22
23
    /**
24
     * @inheritDoc
25
     */
26
    public function transformRequest(Request $requestIn, Request $requestOut)
27
    {
28
        $options = $this->configuration['custom']['fundinfo'];
29
30
        // /3rdparty/fundinfo/factsheet/GB0009583252
31
        preg_match("@[^/]+$@", $requestIn->getRequestUri(), $pathItems);
32
33
        $queryString = str_replace("{shareClass}", $pathItems[0], $options['queryStringTemplate']);
34
        $queryString = str_replace("{documentType}", 'KID', $queryString);
35
        $queryString = str_replace("{language}", 'de', $queryString);
36
37
        $url = sprintf(
38
            '%s?%s&%s',
39
            $options['uri'],
40
            'apiKey='.$options['apiKey'],
41
            $queryString
42
        );
43
44
        return Request::create(
45
            $url,
46
            'GET'
47
        );
48
    }
49
50
}
51