Passed
Push — feature/initial-implementation ( 0c2c6c...79751f )
by Fike
01:54
created

PropertyMapping::setProperty()   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\Mapping;
6
7
use AmaTeam\ElasticSearch\API\Mapping\PropertyMappingInterface;
8
use AmaTeam\ElasticSearch\API\Mapping\PropertyMappingViewInterface;
9
10
class PropertyMapping implements PropertyMappingInterface
11
{
12
    /**
13
     * @var string
14
     */
15
    private $parent;
16
    /**
17
     * @var string
18
     */
19
    private $property;
20
    /**
21
     * @var PropertyMappingView[]
22
     */
23
    private $views;
24
    /**
25
     * @var PropertyMappingView
26
     */
27
    private $defaultView;
28
    /**
29
     * @var string|null
30
     */
31
    private $forcedViewName;
32
33
    public function __construct(string $parent = null, string $property = null)
34
    {
35
        $this->parent = $parent;
36
        $this->property = $property;
37
        $this->defaultView = new PropertyMappingView();
38
    }
39
40
    /**
41
     * @return string
42
     */
43
    public function getParent(): string
44
    {
45
        return $this->parent;
46
    }
47
48
    /**
49
     * @param string $parent
50
     * @return $this
51
     */
52
    public function setParent(string $parent)
53
    {
54
        $this->parent = $parent;
55
        return $this;
56
    }
57
58
    /**
59
     * @return string
60
     */
61
    public function getProperty(): string
62
    {
63
        return $this->property;
64
    }
65
66
    /**
67
     * @param string $property
68
     * @return $this
69
     */
70
    public function setProperty(string $property)
71
    {
72
        $this->property = $property;
73
        return $this;
74
    }
75
76
    /**
77
     * @return PropertyMappingView[]
78
     */
79
    public function getViews(): array
80
    {
81
        return $this->views;
82
    }
83
84
    /**
85
     * @param PropertyMappingView[] $views
86
     * @return $this
87
     */
88
    public function setViews(array $views)
89
    {
90
        $this->views = $views;
91
        return $this;
92
    }
93
94
    public function getView(string $name): ?PropertyMappingViewInterface
95
    {
96
        return $this->views[$name] ?? null;
97
    }
98
99
    public function requestView(string $name): PropertyMappingView
100
    {
101
        if (!isset($this->views[$name])) {
102
            $this->views[$name] = new PropertyMappingView();
103
        }
104
        return $this->views[$name];
105
    }
106
107
    /**
108
     * @param string[] ...$views
109
     * @return PropertyMappingView[]
110
     */
111
    public function requestViews(string ...$views): array
112
    {
113
        return array_map([$this, 'requestView'], $views);
114
    }
115
116
    public function setView(string $name, PropertyMappingView $view): PropertyMapping
117
    {
118
        $this->views[$name] = $view;
119
        return $this;
120
    }
121
122
    public function getDefaultView(): PropertyMappingViewInterface
123
    {
124
        return $this->defaultView;
125
    }
126
127
    /**
128
     * @param PropertyMappingView $defaultView
129
     * @return $this
130
     */
131
    public function setDefaultView(PropertyMappingView $defaultView)
132
    {
133
        $this->defaultView = $defaultView;
134
        return $this;
135
    }
136
137
    /**
138
     * @return null|string
139
     */
140
    public function getForcedViewName(): ?string
141
    {
142
        return $this->forcedViewName;
143
    }
144
145
    /**
146
     * @param null|string $forcedViewName
147
     * @return $this
148
     */
149
    public function setForcedViewName($forcedViewName)
150
    {
151
        $this->forcedViewName = $forcedViewName;
152
        return $this;
153
    }
154
}
155