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 ( b7663d...658651 )
by Jamie
08:03
created

RequestSerializer::serializeOptions()   B

Complexity

Conditions 5
Paths 6

Size

Total Lines 18
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 11
CRAP Score 5

Importance

Changes 5
Bugs 0 Features 0
Metric Value
c 5
b 0
f 0
dl 0
loc 18
ccs 11
cts 11
cp 1
rs 8.8571
cc 5
eloc 9
nc 6
nop 2
crap 5
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 9
    private function parseMetadataHeaders(Parameter $param, $value)
60
    {
61 9
        $headers = [];
62
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
68 9
        return $headers;
69
    }
70
71 15
    private function parseHeader(Parameter $param, $name, $value)
72
    {
73 15
        if (strpos(strtolower($name), 'metadata') !== false) {
74 9
            return $this->parseMetadataHeaders($param, $value);
75
        }
76
77 15
        return is_string($value) || is_numeric($value)
78 15
            ? [$param->getPrefix() . $param->getName() => $value]
79 15
            : [];
80
    }
81
}
82