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::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
            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