Passed
Push — feature/initial-implementation ( fae671...591f29 )
by Fike
02:37
created

Mapping::getDefaultView()   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\Entity\Mapping\Property;
4
5
class Mapping implements MappingInterface
6
{
7
    /**
8
     * @var string
9
     */
10
    private $name;
11
    /**
12
     * @var string
13
     */
14
    private $originalName;
15
    /**
16
     * @var ViewInterface
17
     */
18
    private $defaultView;
19
    /**
20
     * @var ViewInterface[]
21
     */
22
    private $views = [];
23
24
    public function __construct()
25
    {
26
        $this->defaultView = new View();
27
    }
28
29
    /**
30
     * @return string
31
     */
32
    public function getName(): string
33
    {
34
        return $this->name;
35
    }
36
37
    /**
38
     * @param string $name
39
     * @return $this
40
     */
41
    public function setName(string $name): Mapping
42
    {
43
        $this->name = $name;
44
        return $this;
45
    }
46
47
    /**
48
     * @return string
49
     */
50
    public function getOriginalName(): string
51
    {
52
        return $this->originalName;
53
    }
54
55
    /**
56
     * @param string $originalName
57
     * @return $this
58
     */
59
    public function setOriginalName(string $originalName): Mapping
60
    {
61
        $this->originalName = $originalName;
62
        return $this;
63
    }
64
65
    /**
66
     * @return ViewInterface
67
     */
68
    public function getDefaultView(): ViewInterface
69
    {
70
        return $this->defaultView;
71
    }
72
73
    /**
74
     * @param ViewInterface $defaultView
75
     * @return $this
76
     */
77
    public function setDefaultView(ViewInterface $defaultView): Mapping
78
    {
79
        $this->defaultView = $defaultView;
80
        return $this;
81
    }
82
83
    /**
84
     * @return ViewInterface[]
85
     */
86
    public function getViews(): array
87
    {
88
        return $this->views;
89
    }
90
91
    public function getView(string $name): ?ViewInterface
92
    {
93
        return $this->views[$name] ?? null;
94
    }
95
96
    public function requestView(string $name): ViewInterface
97
    {
98
        if (!isset($this->views[$name])) {
99
            $this->views[$name] = new View();
100
        }
101
        return $this->views[$name];
102
    }
103
104
    /**
105
     * @param string[] ...$names
106
     * @return ViewInterface[]
107
     */
108
    public function requestViews(string ...$names): array
109
    {
110
        return array_map([$this, 'requestView'], $names);
111
    }
112
113
    /**
114
     * @param ViewInterface[] $views
115
     * @return $this
116
     */
117
    public function setViews(array $views): Mapping
118
    {
119
        $this->views = $views;
120
        return $this;
121
    }
122
123
    public function setView(string $name, ViewInterface $view): Mapping
124
    {
125
        $this->views[$name] = $view;
126
        return $this;
127
    }
128
}
129