Completed
Pull Request — master (#29)
by Joao
07:15
created

SwaggerResponseBody   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 32
Duplicated Lines 37.5 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 3
dl 12
loc 32
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B match() 12 20 6

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
namespace ByJG\Swagger;
4
5
use ByJG\Swagger\Exception\NotMatchedException;
6
7
class SwaggerResponseBody extends SwaggerBody
8
{
9
    /**
10
     * @param $body
11
     * @return bool
12
     * @throws Exception\DefinitionNotFoundException
13
     * @throws Exception\GenericSwaggerException
14
     * @throws Exception\InvalidDefinitionException
15
     * @throws Exception\InvalidRequestException
16
     * @throws NotMatchedException
17
     */
18
    public function match($body)
19
    {
20
        if ($this->swaggerSchema->getSpecificationVersion() === '3') {
21 View Code Duplication
            if (!isset($this->structure['content'])) {
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...
22
                if (!empty($body)) {
23
                    throw new NotMatchedException("Expected empty body for " . $this->name);
24
                }
25
                return true;
26
            }
27
            return $this->matchSchema($this->name, $this->structure['content'][key($this->structure['content'])]['schema'], $body);
28
        }
29
30 View Code Duplication
        if (!isset($this->structure['schema'])) {
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...
31
            if (!empty($body)) {
32
                throw new NotMatchedException("Expected empty body for " . $this->name);
33
            }
34
            return true;
35
        }
36
        return $this->matchSchema($this->name, $this->structure['schema'], $body);
37
    }
38
}
39