1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* (c) Jean-François Lépine <https://twitter.com/Halleck45> |
5
|
|
|
* |
6
|
|
|
* For the full copyright and license information, please view the LICENSE |
7
|
|
|
* file that was distributed with this source code. |
8
|
|
|
*/ |
9
|
|
|
|
10
|
|
|
namespace Hal\Metrics\Complexity\Text\Halstead; |
11
|
|
|
use Hal\Component\Result\ExportableInterface; |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* Representation of Halstead complexity |
15
|
|
|
* |
16
|
|
|
* @author Jean-François Lépine <https://twitter.com/Halleck45> |
17
|
|
|
*/ |
18
|
|
|
class Result implements ExportableInterface { |
19
|
|
|
/** |
20
|
|
|
* Length of a program |
21
|
|
|
* |
22
|
|
|
* @var integer |
23
|
|
|
*/ |
24
|
|
|
private $length; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* Vocabulary |
28
|
|
|
* |
29
|
|
|
* @var integer |
30
|
|
|
*/ |
31
|
|
|
private $vocabulary; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* Volume |
35
|
|
|
* |
36
|
|
|
* @var integer |
37
|
|
|
*/ |
38
|
|
|
private $volume; |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* Difficulty |
42
|
|
|
* |
43
|
|
|
* @var float |
44
|
|
|
*/ |
45
|
|
|
private $difficulty; |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* Effort |
49
|
|
|
* |
50
|
|
|
* @var float |
51
|
|
|
*/ |
52
|
|
|
private $effort; |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* Bugs expected |
56
|
|
|
* |
57
|
|
|
* @var float |
58
|
|
|
*/ |
59
|
|
|
private $bugs; |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* Time |
63
|
|
|
* |
64
|
|
|
* @var integer |
65
|
|
|
*/ |
66
|
|
|
private $time; |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* Intelligent content |
70
|
|
|
* |
71
|
|
|
* @var integer |
72
|
|
|
*/ |
73
|
|
|
private $intelligentContent; |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* @var |
77
|
|
|
*/ |
78
|
|
|
private $level; |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* @var |
82
|
|
|
*/ |
83
|
|
|
private $numberOfOperators; |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* @var |
87
|
|
|
*/ |
88
|
|
|
private $numberOfUniqueOperators; |
89
|
|
|
|
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* @var |
93
|
|
|
*/ |
94
|
|
|
private $numberOfOperands; |
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* @var |
98
|
|
|
*/ |
99
|
|
|
private $numberOfUniqueOperands; |
100
|
|
|
/** |
101
|
|
|
* @inheritdoc |
102
|
|
|
*/ |
103
|
|
|
public function asArray() { |
104
|
|
|
return array( |
105
|
|
|
'volume' => $this->getVolume() |
106
|
|
|
,'length' => $this->getLength() |
107
|
|
|
,'vocabulary' => $this->getVocabulary() |
108
|
|
|
,'effort' => $this->getEffort() |
109
|
|
|
,'difficulty' => (string) $this->getDifficulty() |
110
|
|
|
,'time' => $this->getTime() |
111
|
|
|
,'bugs' => round($this->getBugs(), 2) |
112
|
|
|
,'intelligentContent' => $this->getIntelligentContent() |
113
|
|
|
); |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
/** |
117
|
|
|
* @param float $bugs |
118
|
|
|
* @return $this |
119
|
|
|
*/ |
120
|
|
|
public function setBugs($bugs) |
121
|
|
|
{ |
122
|
|
|
$this->bugs = $bugs; |
123
|
|
|
return $this; |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
/** |
127
|
|
|
* @return float |
128
|
|
|
*/ |
129
|
|
|
public function getBugs() |
130
|
|
|
{ |
131
|
|
|
return $this->bugs; |
132
|
|
|
} |
133
|
|
|
|
134
|
|
|
/** |
135
|
|
|
* @param float $difficulty |
136
|
|
|
* @return $this |
137
|
|
|
*/ |
138
|
|
|
public function setDifficulty($difficulty) |
139
|
|
|
{ |
140
|
|
|
$this->difficulty = $difficulty; |
141
|
|
|
return $this; |
142
|
|
|
} |
143
|
|
|
|
144
|
|
|
/** |
145
|
|
|
* @return float |
146
|
|
|
*/ |
147
|
|
|
public function getDifficulty() |
148
|
|
|
{ |
149
|
|
|
return $this->difficulty; |
150
|
|
|
} |
151
|
|
|
|
152
|
|
|
/** |
153
|
|
|
* @param float $effort |
154
|
|
|
* @return $this |
155
|
|
|
*/ |
156
|
|
|
public function setEffort($effort) |
157
|
|
|
{ |
158
|
|
|
$this->effort = $effort; |
159
|
|
|
return $this; |
160
|
|
|
} |
161
|
|
|
|
162
|
|
|
/** |
163
|
|
|
* @return float |
164
|
|
|
*/ |
165
|
|
|
public function getEffort() |
166
|
|
|
{ |
167
|
|
|
return $this->effort; |
168
|
|
|
} |
169
|
|
|
|
170
|
|
|
/** |
171
|
|
|
* @param int $length |
172
|
|
|
* @return $this |
173
|
|
|
*/ |
174
|
|
|
public function setLength($length) |
175
|
|
|
{ |
176
|
|
|
$this->length = $length; |
177
|
|
|
return $this; |
178
|
|
|
} |
179
|
|
|
|
180
|
|
|
/** |
181
|
|
|
* @return int |
182
|
|
|
*/ |
183
|
|
|
public function getLength() |
184
|
|
|
{ |
185
|
|
|
return $this->length; |
186
|
|
|
} |
187
|
|
|
|
188
|
|
|
/** |
189
|
|
|
* @param int $time |
190
|
|
|
* @return $this |
191
|
|
|
*/ |
192
|
|
|
public function setTime($time) |
193
|
|
|
{ |
194
|
|
|
$this->time = $time; |
195
|
|
|
return $this; |
196
|
|
|
} |
197
|
|
|
|
198
|
|
|
/** |
199
|
|
|
* @return int |
200
|
|
|
*/ |
201
|
|
|
public function getTime() |
202
|
|
|
{ |
203
|
|
|
return $this->time; |
204
|
|
|
} |
205
|
|
|
|
206
|
|
|
/** |
207
|
|
|
* @param int $vocabulary |
208
|
|
|
* @return $this |
209
|
|
|
*/ |
210
|
|
|
public function setVocabulary($vocabulary) |
211
|
|
|
{ |
212
|
|
|
$this->vocabulary = $vocabulary; |
213
|
|
|
return $this; |
214
|
|
|
} |
215
|
|
|
|
216
|
|
|
/** |
217
|
|
|
* @return int |
218
|
|
|
*/ |
219
|
|
|
public function getVocabulary() |
220
|
|
|
{ |
221
|
|
|
return $this->vocabulary; |
222
|
|
|
} |
223
|
|
|
|
224
|
|
|
/** |
225
|
|
|
* @param int $volume |
226
|
|
|
* @return $this |
227
|
|
|
*/ |
228
|
|
|
public function setVolume($volume) |
229
|
|
|
{ |
230
|
|
|
$this->volume = $volume; |
231
|
|
|
return $this; |
232
|
|
|
} |
233
|
|
|
|
234
|
|
|
/** |
235
|
|
|
* @return int |
236
|
|
|
*/ |
237
|
|
|
public function getVolume() |
238
|
|
|
{ |
239
|
|
|
return $this->volume; |
240
|
|
|
} |
241
|
|
|
|
242
|
|
|
/** |
243
|
|
|
* @return integer |
244
|
|
|
*/ |
245
|
|
|
public function getIntelligentContent() { |
246
|
|
|
return $this->intelligentContent; |
247
|
|
|
} |
248
|
|
|
|
249
|
|
|
/** |
250
|
|
|
* @param float $intelligentContent |
251
|
|
|
* @return $this |
252
|
|
|
*/ |
253
|
|
|
public function setIntelligentContent($intelligentContent) |
254
|
|
|
{ |
255
|
|
|
$this->intelligentContent = $intelligentContent; |
|
|
|
|
256
|
|
|
return $this; |
257
|
|
|
} |
258
|
|
|
|
259
|
|
|
/** |
260
|
|
|
* @param int $numberOfOperands |
261
|
|
|
* @return $this |
262
|
|
|
*/ |
263
|
|
|
public function setNumberOfOperands($numberOfOperands) |
264
|
|
|
{ |
265
|
|
|
$this->numberOfOperands = (int) $numberOfOperands; |
266
|
|
|
return $this; |
267
|
|
|
} |
268
|
|
|
|
269
|
|
|
/** |
270
|
|
|
* @return int |
271
|
|
|
*/ |
272
|
|
|
public function getNumberOfOperands() |
273
|
|
|
{ |
274
|
|
|
return $this->numberOfOperands; |
275
|
|
|
} |
276
|
|
|
|
277
|
|
|
/** |
278
|
|
|
* @param int $numberOfOperators |
279
|
|
|
* @return $this |
280
|
|
|
*/ |
281
|
|
|
public function setNumberOfOperators($numberOfOperators) |
282
|
|
|
{ |
283
|
|
|
$this->numberOfOperators = (int) $numberOfOperators; |
284
|
|
|
return $this; |
285
|
|
|
} |
286
|
|
|
|
287
|
|
|
/** |
288
|
|
|
* @return int |
289
|
|
|
*/ |
290
|
|
|
public function getNumberOfOperators() |
291
|
|
|
{ |
292
|
|
|
return $this->numberOfOperators; |
293
|
|
|
} |
294
|
|
|
|
295
|
|
|
/** |
296
|
|
|
* @param int $numberOfUniqueOperands |
297
|
|
|
* @return $this |
298
|
|
|
*/ |
299
|
|
|
public function setNumberOfUniqueOperands($numberOfUniqueOperands) |
300
|
|
|
{ |
301
|
|
|
$this->numberOfUniqueOperands = (int) $numberOfUniqueOperands; |
302
|
|
|
return $this; |
303
|
|
|
} |
304
|
|
|
|
305
|
|
|
/** |
306
|
|
|
* @return int |
307
|
|
|
*/ |
308
|
|
|
public function getNumberOfUniqueOperands() |
309
|
|
|
{ |
310
|
|
|
return $this->numberOfUniqueOperands; |
311
|
|
|
} |
312
|
|
|
|
313
|
|
|
/** |
314
|
|
|
* @param int $numberOfUniqueOperators |
315
|
|
|
* @return $this |
316
|
|
|
*/ |
317
|
|
|
public function setNumberOfUniqueOperators($numberOfUniqueOperators) |
318
|
|
|
{ |
319
|
|
|
$this->numberOfUniqueOperators = $numberOfUniqueOperators; |
320
|
|
|
return $this; |
321
|
|
|
} |
322
|
|
|
|
323
|
|
|
/** |
324
|
|
|
* @return int |
325
|
|
|
*/ |
326
|
|
|
public function getNumberOfUniqueOperators() |
327
|
|
|
{ |
328
|
|
|
return $this->numberOfUniqueOperators; |
329
|
|
|
} |
330
|
|
|
|
331
|
|
|
/** |
332
|
|
|
* @param double $level |
333
|
|
|
* @return $this |
334
|
|
|
*/ |
335
|
|
|
public function setLevel($level) |
336
|
|
|
{ |
337
|
|
|
$this->level = $level; |
338
|
|
|
return $this; |
339
|
|
|
} |
340
|
|
|
|
341
|
|
|
/** |
342
|
|
|
* @return double |
343
|
|
|
*/ |
344
|
|
|
public function getLevel() |
345
|
|
|
{ |
346
|
|
|
return $this->level; |
347
|
|
|
} |
348
|
|
|
|
349
|
|
|
|
350
|
|
|
|
351
|
|
|
} |
This check looks for assignments to scalar types that may be of the wrong type.
To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.