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

Mapping   A

Complexity

Total Complexity 20

Size/Duplication

Total Lines 156
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 20
dl 0
loc 156
c 0
b 0
f 0
rs 10

18 Methods

Rating   Name   Duplication   Size   Complexity  
A removeProperty() 0 4 1
A getViews() 0 3 1
A getProperties() 0 3 1
A requestView() 0 6 2
A getDefaultView() 0 3 1
A setProperty() 0 4 1
A getProperty() 0 3 1
A requestViews() 0 3 1
A getView() 0 3 1
A getIgnoredParentProperties() 0 3 1
A setViews() 0 4 1
A requestProperty() 0 6 2
A setProperties() 0 4 1
A setIgnoredParentProperties() 0 4 1
A __construct() 0 3 1
A setView() 0 4 1
A setDefaultView() 0 4 1
A requestProperties() 0 3 1
1
<?php
2
3
namespace AmaTeam\ElasticSearch\API\Entity\Mapping\Structure;
4
5
use AmaTeam\ElasticSearch\API\Entity\Mapping\Property\Mapping as PropertyMapping;
6
use AmaTeam\ElasticSearch\API\Entity\Mapping\Property\MappingInterface as PropertyMappingInterface;
7
8
class Mapping implements MappingInterface
9
{
10
    /**
11
     * @var ViewInterface
12
     */
13
    private $defaultView;
14
    /**
15
     * @var ViewInterface[]
16
     */
17
    private $views = [];
18
    /**
19
     * @var PropertyMappingInterface[]
20
     */
21
    private $properties = [];
22
    /**
23
     * @var string[]
24
     */
25
    private $ignoredParentProperties = [];
26
27
    public function __construct()
28
    {
29
        $this->defaultView = new View();
30
    }
31
32
    /**
33
     * @return ViewInterface
34
     */
35
    public function getDefaultView(): ViewInterface
36
    {
37
        return $this->defaultView;
38
    }
39
40
    /**
41
     * @param ViewInterface $defaultView
42
     * @return $this
43
     */
44
    public function setDefaultView(ViewInterface $defaultView): Mapping
45
    {
46
        $this->defaultView = $defaultView;
47
        return $this;
48
    }
49
50
    /**
51
     * @return ViewInterface[]
52
     */
53
    public function getViews(): array
54
    {
55
        return $this->views;
56
    }
57
58
    /**
59
     * @param ViewInterface[] $views
60
     * @return $this
61
     */
62
    public function setViews(array $views): Mapping
63
    {
64
        $this->views = $views;
65
        return $this;
66
    }
67
68
    public function getView(string $name): ?ViewInterface
69
    {
70
        return $this->views[$name] ?? null;
71
    }
72
73
    public function setView(string $name, ViewInterface $view): Mapping
74
    {
75
        $this->views[$name] = $view;
76
        return $this;
77
    }
78
79
    public function requestView(string $name): ViewInterface
80
    {
81
        if (!isset($this->views[$name])) {
82
            $this->views[$name] = new View();
83
        }
84
        return $this->views[$name];
85
    }
86
87
    /**
88
     * @param string[] ...$names
89
     * @return ViewInterface[]
90
     */
91
    public function requestViews(string ...$names): array
92
    {
93
        return array_map([$this, 'requestView'], $names);
94
    }
95
96
    /**
97
     * @return PropertyMappingInterface[]
98
     */
99
    public function getProperties(): array
100
    {
101
        return $this->properties;
102
    }
103
104
    /**
105
     * @param PropertyMappingInterface[] $properties
106
     * @return $this
107
     */
108
    public function setProperties(array $properties): Mapping
109
    {
110
        $this->properties = $properties;
111
        return $this;
112
    }
113
114
    public function getProperty(string $property): ?PropertyMappingInterface
115
    {
116
        return $this->properties[$property] ?? null;
117
    }
118
119
    public function requestProperty(string $property): PropertyMappingInterface
120
    {
121
        if (!isset($this->properties[$property])) {
122
            $this->properties[$property] = new PropertyMapping();
123
        }
124
        return $this->properties[$property];
125
    }
126
127
    /**
128
     * @param string[] ...$names
129
     * @return PropertyMappingInterface[]
130
     */
131
    public function requestProperties(string ...$names): array
132
    {
133
        return array_map([$this, 'requestProperty'], $names);
134
    }
135
136
    public function setProperty(string $property, PropertyMappingInterface $mapping): Mapping
137
    {
138
        $this->properties[$property] = $mapping;
139
        return $this;
140
    }
141
142
    public function removeProperty(string $property): Mapping
143
    {
144
        unset($this->properties[$property]);
145
        return $this;
146
    }
147
148
    /**
149
     * @return string[]
150
     */
151
    public function getIgnoredParentProperties(): array
152
    {
153
        return $this->ignoredParentProperties;
154
    }
155
156
    /**
157
     * @param string[] $ignoredParentProperties
158
     * @return $this
159
     */
160
    public function setIgnoredParentProperties(array $ignoredParentProperties): Mapping
161
    {
162
        $this->ignoredParentProperties = $ignoredParentProperties;
163
        return $this;
164
    }
165
}
166