Passed
Push — feature/initial-implementation ( 4684a2...a02498 )
by Fike
01:36
created

DefaultContext::setIgnoreUnknownParameters()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

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