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

SwaggerResponseBody::match()   B

Complexity

Conditions 6
Paths 6

Size

Total Lines 20

Duplication

Lines 12
Ratio 60 %

Importance

Changes 0
Metric Value
dl 12
loc 20
rs 8.9777
c 0
b 0
f 0
cc 6
nc 6
nop 1
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