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

DocumentMapping   A

Complexity

Total Complexity 15

Size/Duplication

Total Lines 142
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 15
dl 0
loc 142
rs 10
c 0
b 0
f 0

14 Methods

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