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::serializeOptions()   D

Complexity

Conditions 10
Paths 16

Size

Total Lines 32
Code Lines 22

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 25
CRAP Score 10

Importance

Changes 4
Bugs 0 Features 0
Metric Value
c 4
b 0
f 0
dl 0
loc 32
ccs 25
cts 25
cp 1
rs 4.8197
cc 10
eloc 22
nc 16
nop 2
crap 10

How to fix   Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

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