Contact::jsonSerialize()   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\Objects;
6
7
use Aweapi\Openapi\Extensions;
8
use Aweapi\Openapi\ValueObject;
9
10
final class Contact extends ValueObject
11
{
12
    use Properties\OptionalExtensions;
13
    use Properties\OptionalUrl;
14
15
    private $email;
16
17
    private $name;
18
19 6
    public function __construct(
20
        string $name = null,
21
        string $url = null,
22
        string $email = null,
23
        Extensions $extensions = null
24
    ) {
25 6
        $this->name = $name;
26 6
        $this->url = $url;
27 6
        $this->email = $email;
28 6
        $this->extensions = $extensions;
29
    }
30
31 2
    public function getEmail(): string
32
    {
33 2
        return $this->email;
34
    }
35
36 4
    public function getName(): string
37
    {
38 4
        return $this->name;
39
    }
40
41 6
    public function hasEmail(): bool
42
    {
43 6
        return isset($this->email);
44
    }
45
46 6
    public function hasName(): bool
47
    {
48 6
        return isset($this->name);
49
    }
50
51 6
    public function jsonSerialize(): ?array
52
    {
53 6
        return $this->extendedProperties(parent::jsonSerialize());
54
    }
55
56 6
    protected function normalizeOptionalProperties(): array
57
    {
58
        return [
59 6
            'name' => $this->hasName() ? $this->getName() : null,
60 6
            'url' => $this->getNormalizedUrl(),
61 6
            'email' => $this->hasEmail() ? $this->getEmail() : null,
62
        ];
63
    }
64
}
65