Passed
Pull Request — master (#33)
by Joao
08:26
created

OpenApiResponseBody::match()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 10

Duplication

Lines 6
Ratio 60 %

Importance

Changes 0
Metric Value
dl 6
loc 10
rs 9.9332
c 0
b 0
f 0
cc 3
nc 3
nop 1
1
<?php
2
3
namespace ByJG\ApiTools\OpenApi;
4
5
use ByJG\ApiTools\Base\Body;
6
use ByJG\ApiTools\Exception\DefinitionNotFoundException;
7
use ByJG\ApiTools\Exception\GenericSwaggerException;
8
use ByJG\ApiTools\Exception\InvalidDefinitionException;
9
use ByJG\ApiTools\Exception\InvalidRequestException;
10
use ByJG\ApiTools\Exception\NotMatchedException;
11
12
class OpenApiResponseBody extends Body
13
{
14
    /**
15
     * @param $body
16
     * @return bool
17
     * @throws GenericSwaggerException
18
     * @throws InvalidRequestException
19
     * @throws NotMatchedException
20
     * @throws DefinitionNotFoundException
21
     * @throws InvalidDefinitionException
22
     */
23
    public function match($body)
24
    {
25 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...
26
            if (!empty($body)) {
27
                throw new NotMatchedException("Expected empty body for " . $this->name);
28
            }
29
            return true;
30
        }
31
        return $this->matchSchema($this->name, $this->structure['content'][key($this->structure['content'])]['schema'], $body);
32
    }
33
}
34