OpenApiResponseBody   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 20
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 6
eloc 10
c 2
b 0
f 0
dl 0
loc 20
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A match() 0 15 6
1
<?php
2
3
namespace ByJG\ApiTools\OpenApi;
4
5
use ByJG\ApiTools\Base\Body;
6
use ByJG\ApiTools\Exception\NotMatchedException;
7
8
class OpenApiResponseBody extends Body
9
{
10
    /**
11
     * @inheritDoc
12
     */
13
    public function match(mixed $body): bool
14
    {
15
        if (empty($this->structure['content']) && !isset($this->structure['$ref'])) {
16
            if (!empty($body)) {
17
                throw new NotMatchedException("Expected empty body for " . $this->name);
18
            }
19
            return true;
20
        }
21
        
22
        if(!isset($this->structure['content']) && isset($this->structure['$ref'])){
23
            $definition = $this->schema->getDefinition($this->structure['$ref']);
24
            return $this->matchSchema($this->name, $definition, $body) ?? false;
25
        }
26
        
27
        return $this->matchSchema($this->name, $this->structure['content'][key($this->structure['content'])]['schema'], $body) ?? false;
28
    }
29
}
30