x Sorry, these patches are not available anymore due to data migration. Please run a fresh inspection.
Completed
Push — master ( 935a4f...80b369 )
by Veaceslav
01:53
created

Paths::jsonSerialize()   A

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 Paths extends ValueObject
11
{
12
    use Properties\OptionalExtensions;
13
14
    private $paths = [];
15
16 4
    public function __construct(
17
        iterable $paths,
18
        Extensions $extensions = null
19
    ) {
20 4
        foreach ($paths as $urlPath => $path) {
21 2
            $this->setPath($urlPath, $path);
22
        }
23
24 4
        $this->extensions = $extensions;
25
    }
26
27 1
    public function getPath(string $path): Path
28
    {
29 1
        return $this->paths[$path];
30
    }
31
32
    /**
33
     * @return Path[]
34
     */
35 4
    public function getPaths(): array
36
    {
37 4
        return $this->paths;
38
    }
39
40 1
    public function hasPath(string $path): bool
41
    {
42 1
        return isset($this->paths[$path]);
43
    }
44
45 4
    public function jsonSerialize(): ?array
46
    {
47 4
        return $this->extendedProperties(parent::jsonSerialize());
48
    }
49
50 4
    protected function normalizeOptionalProperties(): array
51
    {
52 4
        $paths = [];
53 4
        foreach ($this->getPaths() as $pathUrl => $path) {
54 2
            $paths[$pathUrl] = $path->jsonSerialize();
55
        }
56
57 4
        return $paths;
58
    }
59
60 2
    private function setPath(string $urlPath, Path $path): void
61
    {
62 2
        $this->paths[$urlPath] = $path;
63
    }
64
}
65