Completed
Push — feature/EVO-7964_fundInfo-exte... ( 142d3d...cf9459 )
by Bastian
08:28 queued 08:21
created

FundinfoRequestTransformation::transformRequest()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 21
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 21
ccs 0
cts 18
cp 0
rs 9.3142
c 0
b 0
f 0
cc 1
eloc 14
nc 1
nop 2
crap 2
1
<?php
2
/**
3
 * FundinfoRequestTransformation
4
 */
5
6
namespace Graviton\ProxyBundle\Transformation;
7
8
use Symfony\Component\HttpFoundation\Request;
9
10
/**
11
 * Class FundinfoRequestTransformation
12
 *
13
 * @package Graviton\ProxyBundle\Transformation
14
 * @author  List of contributors <https://github.com/libgraviton/graviton/graphs/contributors>
15
 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
16
 * @link    http://swisscom.ch
17
 */
18
class FundinfoRequestTransformation implements RequestTransformationInterface
19
{
20
    /** @var array  */
21
    private $configuration;
22
23
    /**
24
     * FundinfoRequestTransformation constructor.
25
     *
26
     * @param array $configuration
27
     */
28
    public function __construct(array $configuration)
29
    {
30
        $this->configuration = $configuration;
31
    }
32
33
    /**
34
     * @inheritDoc
35
     *
36
     * @param Request $requestIn  Currently incoming request
37
     * @param Request $requestOut Transformed request
38
     *
39
     * @return Request
40
     */
41
    public function transformRequest(Request $requestIn, Request $requestOut)
42
    {
43
        $options = $this->configuration['custom']['fundinfo'];
44
        preg_match("@[^/]+$@", $requestIn->getRequestUri(), $pathItems);
45
46
        $queryString = str_replace("{shareClass}", $pathItems[0], $options['queryStringTemplate']);
47
        $queryString = str_replace("{documentType}", 'KID', $queryString);
48
        $queryString = str_replace("{language}", 'de', $queryString);
49
50
        $url = sprintf(
51
            '%s?%s&%s',
52
            $options['uri'],
53
            'apiKey='.$options['apiKey'],
54
            $queryString
55
        );
56
57
        return Request::create(
58
            $url,
59
            'GET'
60
        );
61
    }
62
}
63