Conditions | 9 |
Paths | 7 |
Total Lines | 24 |
Code Lines | 14 |
Lines | 0 |
Ratio | 0 % |
Changes | 2 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
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 | foreach ($this->structure['content'] as $contentType => $schema) { |
||
28 | if ($contentType === 'application/json') { |
||
29 | if (!isset($schema['schema'])) { |
||
30 | throw new NotMatchedException("Content type " . $contentType . " does not have schema"); |
||
31 | } |
||
32 | return $this->matchSchema($this->name, $schema['schema'], $body) ?? false; |
||
33 | } |
||
34 | } |
||
35 | |||
36 | return true; |
||
37 | } |
||
39 |