Callback::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
rs 10
1
<?php
2
3
4
namespace Apie\OpenapiSchema\Spec;
5
6
use Apie\OpenapiSchema\ValueObjects\SpecificationExtension;
7
use Apie\ValueObjects\ValueObjectInterface;
8
9
class Callback implements ValueObjectInterface
10
{
11
    /**
12
     * @var PathItem[]
13
     */
14
    private $paths = [];
15
    /**
16
     * @var SpecificationExtension
17
     */
18
    private $specificationExtension;
19
20
    public function __construct()
21
    {
22
        $this->specificationExtension = new SpecificationExtension([]);
23
    }
24
25
    public static function fromNative($value)
26
    {
27
        $res = new Callback();
28
        foreach ($value as $key => $itemValue) {
29
            if (stripos($key, 'x-') === false) {
30
                $res->paths[$key] = PathItem::fromNative($itemValue);
31
            } else {
32
                $res->specificationExtension = $res->specificationExtension->withField($key, $value);
33
            }
34
        }
35
        return $res;
36
    }
37
38
    public function toNative()
39
    {
40
        $res = $this->specificationExtension->toNative();
41
        foreach ($this->paths as $key => $pathItem) {
42
            $res[$key] = $pathItem->toNative();
43
        }
44
        return $res;
45
    }
46
}
47