Passed
Push — feature/initial-implementation ( 70fbec...2d1ee1 )
by Fike
02:35
created

DefaultContext::getViews()   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
rs 10
c 0
b 0
f 0
cc 1
eloc 1
nc 1
nop 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace AmaTeam\ElasticSearch\API\Mapping\Conversion;
6
7
class DefaultContext implements ContextInterface
8
{
9
    /**
10
     * @var string[]
11
     */
12
    private $views = [];
13
    /**
14
     * @var bool
15
     */
16
    private $validate = true;
17
    /**
18
     * @var bool
19
     */
20
    private $strictMode = false;
21
    /**
22
     * @var bool
23
     */
24
    private $rootMapping = true;
25
26
    /**
27
     * @return bool
28
     */
29
    public function isRootMapping(): bool
30
    {
31
        return $this->rootMapping;
32
    }
33
34
    /**
35
     * @param bool $rootMapping
36
     * @return $this
37
     */
38
    public function setRootMapping(bool $rootMapping)
39
    {
40
        $this->rootMapping = $rootMapping;
41
        return $this;
42
    }
43
    /**
44
     * @inheritDoc
45
     */
46
    public function useStrictMode(): bool
47
    {
48
        return $this->strictMode;
49
    }
50
51
    public function setStrictMode(bool $value): DefaultContext
52
    {
53
        $this->strictMode = $value;
54
        return $this;
55
    }
56
57
    /**
58
     * @inheritDoc
59
     */
60
    public function useValidation(): bool
61
    {
62
        return $this->validate;
63
    }
64
65
    public function setValidation(bool $value): DefaultContext
66
    {
67
        $this->validate = $value;
68
        return $this;
69
    }
70
71
    /**
72
     * @param string[] $views
73
     * @return $this
74
     */
75
    public function setViews(array $views)
76
    {
77
        $this->views = $views;
78
        return $this;
79
    }
80
81
    /**
82
     * @inheritDoc
83
     */
84
    public function getViews(): array
85
    {
86
        return $this->views;
87
    }
88
89
    public static function from(ContextInterface $context): DefaultContext
90
    {
91
        return (new DefaultContext())
92
            ->setStrictMode($context->useStrictMode())
93
            ->setValidation($context->useValidation())
94
            ->setRootMapping($context->isRootMapping())
95
            ->setViews($context->getViews());
96
    }
97
}
98