Completed
Pull Request — develop (#512)
by Bastian
16:54 queued 09:51
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
use Symfony\Component\HttpFoundation\Request;
6
7
/**
8
 * Class FundinfoRequestTransformation
9
 *
10
 * @package Graviton\ProxyBundle\Transformation
11
 */
12
class FundinfoRequestTransformation implements RequestTransformationInterface
13
{
14
    /** @var array  */
15
    private $configuration;
16
17
    /**
18
     * FundinfoRequestTransformation constructor.
19
     *
20
     * @param array $configuration
21
     */
22
    public function __construct(array $configuration)
23
    {
24
        $this->configuration = $configuration;
25
    }
26
27
    /**
28
     * @inheritDoc
29
     */
30
    public function transformRequest(Request $requestIn, Request $requestOut)
31
    {
32
        $options = $this->configuration['custom']['fundinfo'];
33
        preg_match("@[^/]+$@", $requestIn->getRequestUri(), $pathItems);
34
35
        $queryString = str_replace("{shareClass}", $pathItems[0], $options['queryStringTemplate']);
36
        $queryString = str_replace("{documentType}", 'KID', $queryString);
37
        $queryString = str_replace("{language}", 'de', $queryString);
38
39
        $url = sprintf(
40
            '%s?%s&%s',
41
            $options['uri'],
42
            'apiKey='.$options['apiKey'],
43
            $queryString
44
        );
45
46
        return Request::create(
47
            $url,
48
            'GET'
49
        );
50
    }
51
}
52