Completed
Push — master ( 030216...a4fd38 )
by Christian
02:05
created

Definition::getExtensions()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 4
ccs 0
cts 0
cp 0
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 2
1
<?php
2
3
/*
4
 * This file is part of the xAPI package.
5
 *
6
 * (c) Christian Flothmann <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Xabbuh\XApi\Model;
13
14
/**
15
 * Definition of an {@link Activity}.
16
 *
17
 * A number of derived classes exists each of them covering a specialized
18
 * type of user interaction:
19
 *
20
 * <ul>
21
 *   <li>ChoiceInteractionDefinition</li>
22
 *   <li>FillInteractionDefinition</li>
23
 *   <li>LikertInteractionDefinition</li>
24
 *   <li>LongFillInInteractionDefinition</li>
25
 *   <li>MatchingInteractionDefinition</li>
26
 *   <li>NumericInteractionDefinition</li>
27
 *   <li>PerformanceInteractionDefinition</li>
28
 *   <li>OtherInteractionDefinition</li>
29
 *   <li>SequencingInteractionDefinition</li>
30
 *   <li>TrueFalseInteractionDefinition</li>
31
 * </ul>
32
 *
33
 * @author Christian Flothmann <[email protected]>
34
 */
35
class Definition
36
{
37
    /**
38
     * The human readable activity name
39
     * @var LanguageMap|null
40
     */
41
    private $name;
42
43
    /**
44
     * The human readable activity description
45
     * @var LanguageMap|null
46
     */
47
    private $description;
48
49
    /**
50
     * @var IRI|null The type of the {@link Activity}
51
     */
52
    private $type;
53
54
    /**
55
     * An IRL where human-readable information describing the {@link Activity} can be found.
56
     *
57
     * @var IRL|null
58
     */
59
    private $moreInfo;
60
61
    /**
62
     * Extensions associated with the {@link Activity}.
63
     *
64
     * @var Extensions|null
65
     */
66
    private $extensions;
67
68
    /**
69
     * @param LanguageMap|null $name
70
     * @param LanguageMap|null $description
71
     * @param IRI|null         $type
72
     * @param IRL|null         $moreInfo
73
     * @param Extensions|null  $extensions
74
     */
75
    public function __construct(LanguageMap $name = null, LanguageMap $description = null, IRI $type = null, IRL $moreInfo = null, Extensions $extensions = null)
76
    {
77
        $this->name = $name;
78
        $this->description = $description;
79
        $this->type = $type;
80
        $this->moreInfo = $moreInfo;
81
        $this->extensions = $extensions;
82
    }
83
84
    public function withName(LanguageMap $name = null)
85
    {
86
        $definition = clone $this;
87
        $definition->name = $name;
88
89
        return $definition;
90
    }
91
92
    public function withDescription(LanguageMap $description = null)
93
    {
94
        $definition = clone $this;
95
        $definition->description = $description;
96
97
        return $definition;
98
    }
99
100
    /**
101
     * @param IRI|null $type
102
     *
103
     * @return static
104
     */
105
    public function withType(IRI $type = null)
106
    {
107
        $definition = clone $this;
108
        $definition->type = $type;
109
110
        return $definition;
111
    }
112
113
    /**
114
     * @param IRL|null $moreInfo
115
     *
116
     * @return static
117
     */
118
    public function withMoreInfo(IRL $moreInfo = null)
119
    {
120
        $definition = clone $this;
121
        $definition->moreInfo = $moreInfo;
122
123
        return $definition;
124
    }
125
126
    public function withExtensions(Extensions $extensions)
127
    {
128
        $definition = clone $this;
129
        $definition->extensions = $extensions;
130
131
        return $definition;
132
    }
133
134
    /**
135
     * Returns the human readable names.
136
     *
137
     * @return LanguageMap|null The name language map
138
     */
139
    public function getName()
140
    {
141
        return $this->name;
142
    }
143
144
    /**
145
     * Returns the human readable descriptions.
146
     *
147
     * @return LanguageMap|null The description language map
148
     */
149
    public function getDescription()
150
    {
151
        return $this->description;
152
    }
153
154
    /**
155
     * Returns the {@link Activity} type.
156
     *
157
     * @return IRI|null The type
158
     */
159
    public function getType()
160
    {
161
        return $this->type;
162
    }
163
164
    /**
165
     * Returns an IRL where human-readable information about the activity can be found.
166
     *
167
     * @return IRL|null
168
     */
169
    public function getMoreInfo()
170
    {
171
        return $this->moreInfo;
172
    }
173
174
    public function getExtensions()
175
    {
176
        return $this->extensions;
177
    }
178
179
    /**
180
     * Checks if another definition is equal.
181
     *
182
     * Two definitions are equal if and only if all of their properties are equal.
183
     *
184
     * @param Definition $definition The definition to compare with
185
     *
186
     * @return bool True if the definitions are equal, false otherwise
187
     */
188
    public function equals(Definition $definition)
189
    {
190
        if (get_class($this) !== get_class($definition)) {
191
            return false;
192
        }
193
194
        if (null !== $this->type xor null !== $definition->type) {
195
            return false;
196
        }
197
198
        if (null !== $this->type && null !== $definition->type && !$this->type->equals($definition->type)) {
199
            return false;
200
        }
201
202
        if (null !== $this->moreInfo xor null !== $definition->moreInfo) {
203
            return false;
204
        }
205
206
        if (null !== $this->moreInfo && null !== $definition->moreInfo && !$this->moreInfo->equals($definition->moreInfo)) {
207
            return false;
208
        }
209
210
        if (null !== $this->extensions xor null !== $definition->extensions) {
211
            return false;
212
        }
213
214
        if (count($this->name) !== count($definition->name)) {
215
            return false;
216
        }
217
218
        if (count($this->description) !== count($definition->description)) {
219
            return false;
220
        }
221
222
        if (!is_array($this->name) xor !is_array($definition->name)) {
223
            return false;
224
        }
225
226
        if (!is_array($this->description) xor !is_array($definition->description)) {
227
            return false;
228
        }
229
230
        if (is_array($this->name)) {
231
            foreach ($this->name as $language => $value) {
232
                if (!isset($definition->name[$language])) {
233
                    return false;
234
                }
235
236
                if ($value !== $definition->name[$language]) {
237
                    return false;
238
                }
239
            }
240
        }
241
242
        if (is_array($this->description)) {
243
            foreach ($this->description as $language => $value) {
244
                if (!isset($definition->description[$language])) {
245
                    return false;
246
                }
247
248
                if ($value !== $definition->description[$language]) {
249
                    return false;
250
                }
251
            }
252
        }
253
254
        if (null !== $this->extensions && null !== $definition->extensions && !$this->extensions->equals($definition->extensions)) {
255
            return false;
256
        }
257
258
        return true;
259
    }
260
}
261