GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Passed
Push — master ( 307cce...27531d )
by Jamie
04:17 queued 15s
created

RequestSerializer   A

Complexity

Total Complexity 19

Size/Duplication

Total Lines 58
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 5
Bugs 1 Features 0
Metric Value
wmc 19
c 5
b 1
f 0
lcom 1
cbo 3
dl 0
loc 58
ccs 39
cts 39
cp 1
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 2
D serializeOptions() 0 32 10
B parseHeader() 0 15 7
1
<?php
2
3
namespace OpenStack\Common\Transport;
4
5
use function GuzzleHttp\uri_template;
6
use function GuzzleHttp\Psr7\build_query;
7
use function GuzzleHttp\Psr7\modify_request;
8
9
use OpenStack\Common\Api\Operation;
10
use OpenStack\Common\Api\Parameter;
11
12
class RequestSerializer
13
{
14
    private $jsonSerializer;
15
16 182
    public function __construct(JsonSerializer $jsonSerializer = null)
17
    {
18 182
        $this->jsonSerializer = $jsonSerializer ?: new JsonSerializer();
19 182
    }
20
21 182
    public function serializeOptions(Operation $operation, array $userValues = [])
22
    {
23 182
        $options = ['headers' => []];
24
25 182
        foreach ($userValues as $paramName => $paramValue) {
26 168
            if (null === ($schema = $operation->getParam($paramName))) {
27 1
                continue;
28
            }
29
30 167
            switch ($schema->getLocation()) {
31 167
                case 'query':
32 11
                    $options['query'][$schema->getName()] = $paramValue;
33 11
                    break;
34 157
                case 'header':
35 15
                    $options['headers'] += $this->parseHeader($schema, $paramName, $paramValue);
36 15
                    break;
37 149
                case 'json':
38 62
                    $json = isset($options['json']) ? $options['json'] : [];
39 62
                    $options['json'] = $this->jsonSerializer->stockJson($schema, $paramValue, $json);
40 62
                    break;
41 116
                case 'raw':
42 3
                    $options['body'] = $paramValue;
43 3
                    break;
44 167
            }
45 182
        }
46
47 182
        if (!empty($options['json']) && ($key = $operation->getJsonKey())) {
48 36
            $options['json'] = [$key => $options['json']];
49 36
        }
50
51 182
        return $options;
52
    }
53
54 15
    private function parseHeader(Parameter $param, $name, $value)
55
    {
56 15
        if ($name == 'metadata' || $name == 'removeMetadata') {
57 9
            $headers = [];
58 9
            foreach ($value as $key => $keyVal) {
59 9
                $schema = $param->getItemSchema() ?: new Parameter(['prefix' => $param->getPrefix(), 'name' => $key]);
60 9
                $headers += $this->parseHeader($schema, $key, $keyVal);
61 9
            }
62 9
            return $headers;
63
        }
64
65 15
        return is_string($value) || is_numeric($value)
66 15
            ? [$param->getPrefix() . $param->getName() => $value]
67 15
            : [];
68
    }
69
}
70