Completed
Push — master ( a12959...164d8d )
by Mario
03:20
created

NativeArgumentsConverter   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 2
c 1
b 0
f 0
lcom 0
cbo 2
dl 0
loc 33
ccs 17
cts 17
cp 1
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
B convert() 0 27 2
1
<?php
2
3
namespace Marek\Toggable\Http\Converter;
4
5
use Marek\Toggable\API\Security\TokenInterface;
6
use Marek\Toggable\API\Http\Request\RequestInterface;
7
8
/**
9
 * Class NativeArgumentsConverter
10
 * @package Marek\Toggable\Http\Converter
11
 */
12
class NativeArgumentsConverter implements ArgumentsConverterInterface
13
{
14
    /**
15
     * @inheritDoc
16
     */
17 1
    public function convert(RequestInterface $request, TokenInterface $token, $uri)
18
    {
19
        $opts = array(
20
            'http' => array(
21 1
                'method' => $request->getMethod(),
22
                'header' => array(
23 1
                    'Content-type: application/json',
24 1
                ),
25 1
            ),
26 1
        );
27
28 1
        $auth = $token->getAuthentication();
29 1
        $auth = $auth[0] . ':' . $auth[1];
30 1
        $auth = base64_encode($auth);
31 1
        $opts['http']['header'][] = 'Authorization: Basic ' . $auth;
32
33 1
        if (!empty($request->getData())) {
34 1
            $opts['http']['content'] = json_encode($request);
35 1
        }
36
37 1
        $uri = $uri . '/' . $request->getUri();
38
39
        return array(
40 1
            'uri' => $uri,
41 1
            'options' => $opts,
42 1
        );
43
    }
44
}
45