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   A

Complexity

Total Complexity 20

Size/Duplication

Total Lines 63
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 6
Bugs 1 Features 0
Metric Value
wmc 20
c 6
b 1
f 0
lcom 1
cbo 3
dl 0
loc 63
ccs 42
cts 42
cp 1
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 2
B serializeOptions() 0 18 5
B stockOptions() 0 18 6
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
            $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