Completed
Push — master ( 483f95...829c8a )
by Julien
08:25
created

ClassMetadata::getIdentifierAttribute()   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 0
1
<?php
2
3
namespace Mapado\RestClientSdk\Mapping;
4
5
/**
6
 * Class ClassMetadata
7
 * @author Julien Deniau <[email protected]>
8
 */
9
class ClassMetadata
10
{
11
    /**
12
     * modelName
13
     *
14
     * @var string
15
     * @access private
16
     */
17
    private $modelName;
18
19
    /**
20
     * key
21
     *
22
     * @var string
23
     * @access private
24
     */
25
    private $key;
26
27
    /**
28
     * repositoryName
29
     *
30
     * @var string
31
     * @access private
32
     */
33
    private $repositoryName;
34
35
    /**
36
     * attributeList
37
     *
38
     * @var array<Attribute>
39
     * @access private
40
     */
41
    private $attributeList;
42
43
    /**
44
     * relationList
45
     *
46
     * @var array<Relation>
47
     * @access private
48
     */
49
    private $relationList;
50
51
    /**
52
     * identifierAttribute
53
     *
54
     * @var Attribute
55
     * @access private
56
     */
57
    private $identifierAttribute;
58
59
    /**
60
     * __construct
61
     *
62
     * @param string $key
63
     * @param string $modelName
64
     * @access public
65
     */
66
    public function __construct($key, $modelName, $repositoryName)
67
    {
68
        $this->key = $key;
69
        $this->modelName = $modelName;
70
        $this->repositoryName = $repositoryName;
71
    }
72
73
    /**
74
     * Getter for modelName
75
     *
76
     * return string
77
     */
78
    public function getModelName()
79
    {
80
        return $this->modelName;
81
    }
82
83
    /**
84
     * Setter for modelName
85
     *
86
     * @param string $modelName
87
     * @return ClassMetadata
88
     */
89
    public function setModelName($modelName)
90
    {
91
        $this->modelName = $modelName;
92
        return $this;
93
    }
94
95
    /**
96
     * Getter for key
97
     *
98
     * return string
99
     */
100
    public function getKey()
101
    {
102
        return $this->key;
103
    }
104
105
    /**
106
     * Setter for key
107
     *
108
     * @param string $key
109
     * @return ClassMetadata
110
     */
111
    public function setKey($key)
112
    {
113
        $this->key = $key;
114
        return $this;
115
    }
116
117
    /**
118
     * getAttribute
119
     *
120
     * @param string $name
121
     * @access public
122
     * @return Attribute
123
     */
124
    public function getAttribute($name)
125
    {
126
        return isset($this->attributeList[$name]) ? $this->attributeList[$name] : null;
127
    }
128
129
    /**
130
     * getIdentifierAttribute
131
     *
132
     * @access public
133
     * @return Attribute
134
     */
135
    public function getIdentifierAttribute()
136
    {
137
        return $this->identifierAttribute;
138
    }
139
140
    /**
141
     * Getter for attributeList
142
     *
143
     * return array<Attribute>
144
     */
145
    public function getAttributeList()
146
    {
147
        return $this->attributeList;
148
    }
149
150
    /**
151
     * Setter for attributeList
152
     *
153
     * @param array<Attribute> $attributeList
154
     * @return ClassMetadata
155
     */
156
    public function setAttributeList($attributeList)
157
    {
158
        $this->attributeList = [];
159
        foreach ($attributeList as $attribute) {
160
            $this->attributeList[$attribute->getSerializedKey()] = $attribute;
161
162
            if ($attribute->isIdentifier()) {
163
                $this->identifierAttribute = $attribute;
164
            }
165
        }
166
        return $this;
167
    }
168
169
    /**
170
     * Getter for relationList
171
     *
172
     * return array<Relation>
173
     */
174
    public function getRelationList()
175
    {
176
        return $this->relationList;
177
    }
178
179
    /**
180
     * Setter for relationList
181
     *
182
     * @param array<Relation> $relationList
183
     * @return ClassMetadata
184
     */
185
    public function setRelationList($relationList)
186
    {
187
        $this->relationList = $relationList;
188
        return $this;
189
    }
190
191
    /**
192
     * getRelation
193
     *
194
     * @param string $key
195
     * @access public
196
     * @return Relation|null
197
     */
198
    public function getRelation($key)
199
    {
200
        if (!empty($this->relationList)) {
201
            foreach ($this->relationList as $relation) {
202
                if ($relation->getSerializedKey() == $key) {
203
                    return $relation;
204
                }
205
            }
206
        }
207
    }
208
209
    /**
210
     * Getter for repositoryName
211
     *
212
     * return string
213
     */
214
    public function getRepositoryName()
215
    {
216
        return $this->repositoryName;
217
    }
218
219
    /**
220
     * Setter for repositoryName
221
     *
222
     * @param string $repositoryName
223
     * @return ClassMetadata
224
     */
225
    public function setRepositoryName($repositoryName)
226
    {
227
        $this->repositoryName = $repositoryName;
228
        return $this;
229
    }
230
}
231