Passed
Push — dev ( 40f0b5...3a2e98 )
by Fike
02:50
created

Context::shouldPreserveUnknownParameters()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 3
c 0
b 0
f 0
rs 10
cc 1
eloc 1
nc 1
nop 0
1
<?php
2
3
namespace AmaTeam\ElasticSearch\API\Mapping\Validation;
4
5
class Context implements ContextInterface
6
{
7
    /**
8
     * @var string[]
9
     */
10
    private $path = [];
11
    /**
12
     * @var bool
13
     */
14
    private $preserveUnknownParameters = false;
15
16
    /**
17
     * @return string[]
18
     */
19
    public function getPath(): array
20
    {
21
        return $this->path;
22
    }
23
24
    /**
25
     * @param string[] $path
26
     * @return $this
27
     */
28
    public function setPath(array $path): Context
29
    {
30
        $this->path = $path;
31
        return $this;
32
    }
33
34
    public function withAppendedPath(string ...$segments): Context
35
    {
36
        return static::from($this)->setPath(array_merge($this->path, $segments));
37
    }
38
39
    /**
40
     * @return bool
41
     */
42
    public function shouldPreserveUnknownParameters(): bool
43
    {
44
        return $this->preserveUnknownParameters;
45
    }
46
47
    /**
48
     * @param bool $preserveUnknownParameters
49
     * @return $this
50
     */
51
    public function setPreserveUnknownParameters(bool $preserveUnknownParameters): Context
52
    {
53
        $this->preserveUnknownParameters = $preserveUnknownParameters;
54
        return $this;
55
    }
56
    
57
    public static function from(ContextInterface $context): Context
58
    {
59
        return (new Context())
60
            ->setPath($context->getPath())
61
            ->setPreserveUnknownParameters($context->shouldPreserveUnknownParameters());
62
    }
63
}
64