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

Mapping   A

Complexity

Total Complexity 14

Size/Duplication

Total Lines 122
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 14
dl 0
loc 122
c 0
b 0
f 0
rs 10

13 Methods

Rating   Name   Duplication   Size   Complexity  
A getName() 0 3 1
A __construct() 0 3 1
A requestView() 0 6 2
A setOriginalName() 0 4 1
A getDefaultView() 0 3 1
A getOriginalName() 0 3 1
A setViews() 0 4 1
A setView() 0 4 1
A getView() 0 3 1
A getViews() 0 3 1
A setName() 0 4 1
A requestViews() 0 3 1
A setDefaultView() 0 4 1
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