ValueObject::normalizeOptionalProperties()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 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