MediaType   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 55
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 9
lcom 1
cbo 5
dl 0
loc 55
ccs 19
cts 19
cp 1
rs 10
c 0
b 0
f 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 11 1
A getEncodings() 0 4 1
A getSchema() 0 4 1
A hasEncodings() 0 4 1
A hasSchema() 0 4 1
A jsonSerialize() 0 4 1
A normalizeOptionalProperties() 0 8 3
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Aweapi\Openapi\Objects;
6
7
use Aweapi\Openapi\Extensions;
8
use Aweapi\Openapi\ValueObject;
9
10
final class MediaType extends ValueObject
11
{
12
    use Properties\OptionalExamples;
13
    use Properties\OptionalExtensions;
14
15
    private $encodings;
16
17
    private $schema;
18
19 10
    public function __construct(
20
        SchemaAggregate $schema = null,
21
        Examples $examples = null,
22
        Encodings $encodings = null,
23
        Extensions $extensions = null
24
    ) {
25 10
        $this->schema = $schema;
26 10
        $this->examples = $examples;
27 10
        $this->encodings = $encodings;
28 10
        $this->extensions = $extensions;
29
    }
30
31 2
    public function getEncodings(): Encodings
32
    {
33 2
        return $this->encodings;
34
    }
35
36 7
    public function getSchema(): SchemaAggregate
37
    {
38 7
        return $this->schema;
39
    }
40
41 9
    public function hasEncodings(): bool
42
    {
43 9
        return isset($this->encodings);
44
    }
45
46 9
    public function hasSchema(): bool
47
    {
48 9
        return isset($this->schema);
49
    }
50
51 9
    public function jsonSerialize(): ?array
52
    {
53 9
        return $this->extendedProperties(parent::jsonSerialize());
54
    }
55
56 9
    protected function normalizeOptionalProperties(): array
57
    {
58
        return [
59 9
            'schema' => $this->hasSchema() ? $this->getSchema()->jsonSerialize() : null,
60 9
            'examples' => $this->getNormalizedExamples(),
61 9
            'encoding' => $this->hasEncodings() ? $this->getEncodings()->jsonSerialize() : null,
62
        ];
63
    }
64
}
65