ValueObject   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 8
lcom 0
cbo 0
dl 0
loc 33
ccs 12
cts 12
cp 1
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A jsonSerialize() 0 12 5
A emptyObject() 0 4 1
A normalizeOptionalProperties() 0 4 1
A normalizeRequiredProperties() 0 4 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Aweapi\Openapi;
6
7
use stdClass;
8
9
abstract class ValueObject implements Definition
10
{
11 152
    public function jsonSerialize(): ?array
12
    {
13 152
        $properties = $this->normalizeRequiredProperties();
14
15 152
        foreach ($this->normalizeOptionalProperties() as $name => $value) {
16 142
            if ($value !== null && $value !== []) {
17 83
                $properties[$name] = $value;
18
            }
19
        }
20
21 152
        return $properties ?: null;
22
    }
23
24
    /**
25
     * Use this instead of empty maps for required properties to force JSON-object.
26
     */
27 10
    protected static function emptyObject(): stdClass
28
    {
29 10
        return new stdClass();
30
    }
31
32 10
    protected function normalizeOptionalProperties(): array
33
    {
34 10
        return [];
35
    }
36
37 80
    protected function normalizeRequiredProperties(): array
38
    {
39 80
        return [];
40
    }
41
}
42