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 ( c7ca15...b7663d )
by Jamie
04:26
created

RequestSerializer::parseHeader()   B

Complexity

Conditions 7
Paths 7

Size

Total Lines 15
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 11
CRAP Score 7

Importance

Changes 3
Bugs 0 Features 0
Metric Value
c 3
b 0
f 0
dl 0
loc 15
ccs 11
cts 11
cp 1
rs 8.2222
cc 7
eloc 9
nc 7
nop 3
crap 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
            $this->stockOptions($schema, $paramName, $paramValue, $options);
31 182
        }
32
33 182
        if (!empty($options['json']) && ($key = $operation->getJsonKey())) {
34 36
            $options['json'] = [$key => $options['json']];
35 36
        }
36
37 182
        return $options;
38
    }
39
40 167
    private function stockOptions(Parameter $schema, $paramName, $paramValue, array &$options)
41
    {
42 167
        switch ($schema->getLocation()) {
43 167
            case 'query':
44 11
                $options['query'][$schema->getName()] = $paramValue;
45 11
                break;
46 157
            case 'header':
47 15
                $options['headers'] += $this->parseHeader($schema, $paramName, $paramValue);
48 15
                break;
49 149
            case 'json':
50 62
                $json = isset($options['json']) ? $options['json'] : [];
51 62
                $options['json'] = $this->jsonSerializer->stockJson($schema, $paramValue, $json);
52 62
                break;
53 116
            case 'raw':
54 3
                $options['body'] = $paramValue;
55 3
                break;
56 167
        }
57 167
    }
58
59 15
    private function parseHeader(Parameter $param, $name, $value)
60
    {
61 15
        if ($name == 'metadata' || $name == 'removeMetadata') {
62 9
            $headers = [];
63 9
            foreach ($value as $key => $keyVal) {
64 9
                $schema = $param->getItemSchema() ?: new Parameter(['prefix' => $param->getPrefix(), 'name' => $key]);
65 9
                $headers += $this->parseHeader($schema, $key, $keyVal);
66 9
            }
67 9
            return $headers;
68
        }
69
70 15
        return is_string($value) || is_numeric($value)
71 15
            ? [$param->getPrefix() . $param->getName() => $value]
72 15
            : [];
73
    }
74
}
75