Test Failed
Pull Request — master (#33)
by Joao
09:10
created

SwaggerRequestBody   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 3
dl 0
loc 30
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B match() 0 17 7
1
<?php
2
3
namespace ByJG\ApiTools\Swagger;
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
use ByJG\ApiTools\Exception\RequiredArgumentNotFound;
12
13
class SwaggerRequestBody extends Body
14
{
15
    /**
16
     * @param $body
17
     * @return bool
18
     * @throws GenericSwaggerException
19
     * @throws InvalidDefinitionException
20
     * @throws InvalidRequestException
21
     * @throws NotMatchedException
22
     * @throws RequiredArgumentNotFound
23
     * @throws DefinitionNotFoundException
24
     */
25
    public function match($body)
26
    {
27
        foreach ($this->structure as $parameter) {
28
            if ($parameter['in'] == "body") {
29
                if (isset($parameter['required']) && $parameter['required'] === true && empty($body)) {
30
                    throw new RequiredArgumentNotFound('The body is required but it is empty');
31
                }
32
                return $this->matchSchema($this->name, $parameter['schema'], $body);
33
            }
34
        }
35
36
        if (!empty($body)) {
37
            throw new InvalidDefinitionException('Body is passed but there is no request body definition');
38
        }
39
40
        return false;
41
    }
42
}
43