Completed
Pull Request — master (#6)
by Veaceslav
11:19
created

PathsBuilder::getPaths()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 4
Ratio 100 %

Importance

Changes 0
Metric Value
dl 4
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Aweapi\Openapi\Builders;
6
7
use Aweapi\Openapi\Objects;
8
9 View Code Duplication
final class PathsBuilder implements Objects\PathsFactory
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
10
{
11
    use Properties\OptionalExtensions;
12
13
    private $paths = [];
14
15
    public function addPaths(iterable $paths): self
16
    {
17
        foreach ($paths as $urlPath => $path) {
18
            $this->setPath($urlPath, $path);
19
        }
20
21
        return $this;
22
    }
23
24
    public function createPaths(): Objects\Paths
25
    {
26
        return new Objects\Paths(
27
            array_map(
28
                static function (Objects\PathFactory $factory): Objects\Path {
29
                    return $factory->createPath();
30
                },
31
                $this->getPaths()
32
            ),
33
            $this->getExtensions()
34
        );
35
    }
36
37
    public function setPath(string $urlPath, Objects\PathFactory $path): self
38
    {
39
        $this->paths[$urlPath] = $path;
40
41
        return $this;
42
    }
43
44
    private function getPaths(): array
45
    {
46
        return $this->paths;
47
    }
48
}
49