Completed
Push — master ( 41ceaa...00d5e1 )
by Christian
03:03
created

Definition   A

Complexity

Total Complexity 25

Size/Duplication

Total Lines 189
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 25
c 1
b 0
f 1
lcom 1
cbo 0
dl 0
loc 189
ccs 0
cts 47
cp 0
rs 10

10 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
A withName() 0 7 1
A withDescription() 0 7 1
A withType() 0 7 1
A withMoreInfo() 0 7 1
A getName() 0 4 1
A getDescription() 0 4 1
A getType() 0 4 1
A getMoreInfo() 0 4 1
C equals() 0 56 16
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
     * The type of the {@link Activity}
51
     * @var string|null
52
     */
53
    private $type;
54
55
    /**
56
     * An IRL where human-readable information describing the {@link Activity} can be found.
57
     *
58
     * @var string|null
59
     */
60
    private $moreInfo;
61
62
    /**
63
     * @param LanguageMap|null $name
64
     * @param LanguageMap|null $description
65
     * @param string|null      $type
66
     * @param string|null      $moreInfo
67
     */
68
    public function __construct(LanguageMap $name = null, LanguageMap $description = null, $type = null, $moreInfo = null)
69
    {
70
        $this->name = $name;
71
        $this->description = $description;
72
        $this->type = $type;
73
        $this->moreInfo = $moreInfo;
74
    }
75
76
    public function withName(LanguageMap $name = null)
77
    {
78
        $definition = clone $this;
79
        $definition->name = $name;
80
81
        return $definition;
82
    }
83
84
    public function withDescription(LanguageMap $description = null)
85
    {
86
        $definition = clone $this;
87
        $definition->description = $description;
88
89
        return $definition;
90
    }
91
92
    /**
93
     * @param string|null $type
94
     *
95
     * @return static
96
     */
97
    public function withType($type)
98
    {
99
        $definition = clone $this;
100
        $definition->type = $type;
101
102
        return $definition;
103
    }
104
105
    /**
106
     * @param string|null $moreInfo
107
     *
108
     * @return static
109
     */
110
    public function withMoreInfo($moreInfo)
111
    {
112
        $definition = clone $this;
113
        $definition->moreInfo = $moreInfo;
114
115
        return $definition;
116
    }
117
118
    /**
119
     * Returns the human readable names.
120
     *
121
     * @return LanguageMap|null The name language map
122
     */
123
    public function getName()
124
    {
125
        return $this->name;
126
    }
127
128
    /**
129
     * Returns the human readable descriptions.
130
     *
131
     * @return LanguageMap|null The description language map
132
     */
133
    public function getDescription()
134
    {
135
        return $this->description;
136
    }
137
138
    /**
139
     * Returns the {@link Activity} type.
140
     *
141
     * @return string|null The type
142
     */
143
    public function getType()
144
    {
145
        return $this->type;
146
    }
147
148
    /**
149
     * Returns an IRL where human-readable information about the activity can be found.
150
     *
151
     * @return string|null
152
     */
153
    public function getMoreInfo()
154
    {
155
        return $this->moreInfo;
156
    }
157
158
    /**
159
     * Checks if another definition is equal.
160
     *
161
     * Two definitions are equal if and only if all of their properties are equal.
162
     *
163
     * @param Definition $definition The definition to compare with
164
     *
165
     * @return bool True if the definitions are equal, false otherwise
166
     */
167
    public function equals(Definition $definition)
168
    {
169
        if (get_class($this) !== get_class($definition)) {
170
            return false;
171
        }
172
173
        if ($this->type !== $definition->type) {
174
            return false;
175
        }
176
177
        if ($this->moreInfo !== $definition->moreInfo) {
178
            return false;
179
        }
180
181
        if (count($this->name) !== count($definition->name)) {
182
            return false;
183
        }
184
185
        if (count($this->description) !== count($definition->description)) {
186
            return false;
187
        }
188
189
        if (!is_array($this->name) xor !is_array($definition->name)) {
190
            return false;
191
        }
192
193
        if (!is_array($this->description) xor !is_array($definition->description)) {
194
            return false;
195
        }
196
197
        if (is_array($this->name)) {
198
            foreach ($this->name as $language => $value) {
199
                if (!isset($definition->name[$language])) {
200
                    return false;
201
                }
202
203
                if ($value !== $definition->name[$language]) {
204
                    return false;
205
                }
206
            }
207
        }
208
209
        if (is_array($this->description)) {
210
            foreach ($this->description as $language => $value) {
211
                if (!isset($definition->description[$language])) {
212
                    return false;
213
                }
214
215
                if ($value !== $definition->description[$language]) {
216
                    return false;
217
                }
218
            }
219
        }
220
221
        return true;
222
    }
223
}
224