Completed
Push — master ( 6ebd1c...df9bae )
by John
10:14
created

SwaggerBundleResponseFixer::process()   C

Complexity

Conditions 10
Paths 192

Size

Total Lines 49
Code Lines 31

Duplication

Lines 24
Ratio 48.98 %

Importance

Changes 3
Bugs 1 Features 0
Metric Value
c 3
b 1
f 0
dl 24
loc 49
rs 5.2413
cc 10
eloc 31
nc 192
nop 1

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
 * This file is part of the KleijnWeb\SwaggerBundle package.
4
 *
5
 * For the full copyright and license information, please view the LICENSE
6
 * file that was distributed with this source code.
7
 */
8
9
namespace KleijnWeb\SwaggerBundle\Dev\DocumentFixer\Fixers;
10
11
use KleijnWeb\SwaggerBundle\Dev\DocumentFixer\Fixer;
12
use KleijnWeb\SwaggerBundle\Document\SwaggerDocument;
13
14
class SwaggerBundleResponseFixer extends Fixer
15
{
16
    /**
17
     * @param SwaggerDocument $document
18
     *
19
     * @return void
20
     */
21
    public function process(SwaggerDocument $document)
22
    {
23
        $definition = $document->getDefinition();
24
25
        if (!isset($definition->responses)) {
26
            $definition->responses = [];
0 ignored issues
show
Bug introduced by
The property responses does not seem to exist in ArrayObject.

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
27
        }
28 View Code Duplication
        if (!isset($definition->responses['ServerError'])) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
29
            $definition->responses['ServerError'] = [
30
                'description' => 'Server Error',
31
                'schema'      => ['$ref' => '#/definitions/VndError']
32
            ];
33
        }
34 View Code Duplication
        if (!isset($definition->responses['InputError'])) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
35
            $definition->responses['InputError'] = [
36
                'description' => 'Input Error',
37
                'schema'      => ['$ref' => '#/definitions/VndError']
38
            ];
39
        }
40
        if (!isset($definition->definitions)) {
41
            $definition->definitions = [];
0 ignored issues
show
Bug introduced by
The property definitions does not seem to exist in ArrayObject.

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
42
        }
43
        if (!isset($definition->definitions['VndError'])) {
44
            $definition->definitions['VndError'] = [
45
                'type'       => 'object',
46
                'required'   => ['message', 'logref'],
47
                'properties' => [
48
                    'message' => ['type' => 'string'],
49
                    'logref'  => ['type' => 'string']
50
                ]
51
            ];
52
        }
53
        foreach ($definition->paths as &$operations) {
0 ignored issues
show
Bug introduced by
The property paths does not seem to exist in ArrayObject.

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
54
            foreach ($operations as &$operation) {
55 View Code Duplication
                if (!isset($operation['responses']['500'])) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
56
                    $operation['responses']['500'] = [
57
                        'description' => 'Generic server error',
58
                        'schema'      => ['$ref' => '#/responses/ServerError']
59
                    ];
60
                }
61 View Code Duplication
                if (!isset($operation['responses']['400'])) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
62
                    $operation['responses']['400'] = [
63
                        'description' => 'Client input error',
64
                        'schema'      => ['$ref' => '#/responses/InputError']
65
                    ];
66
                }
67
            }
68
        }
69
    }
70
}
71