NativeArgumentsConverter::convert()   B
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 27
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 17
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 27
ccs 17
cts 17
cp 1
rs 8.8571
cc 2
eloc 16
nc 2
nop 3
crap 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