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\Component\Result; |
11
|
|
|
|
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* Aggregate of ResultSet |
15
|
|
|
* |
16
|
|
|
* @author Jean-François Lépine <https://twitter.com/Halleck45> |
17
|
|
|
*/ |
18
|
|
|
class ResultAggregate implements ExportableInterface, ResultSetInterface { |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* @var string |
22
|
|
|
*/ |
23
|
|
|
private $namespace; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* @var \Hal\Metrics\Mood\Abstractness\Result |
27
|
|
|
*/ |
28
|
|
|
private $abstractness; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @var \Hal\Component\Bounds\Result\BoundsResult; |
32
|
|
|
*/ |
33
|
|
|
private $bounds; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @var \Hal\Metrics\Mood\Instability\Result |
37
|
|
|
*/ |
38
|
|
|
private $instability; |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @var ResultCollection |
42
|
|
|
*/ |
43
|
|
|
private $childs; |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* Constructor |
47
|
|
|
* |
48
|
|
|
*/ |
49
|
|
|
public function __construct($namespace) { |
50
|
|
|
$this->namespace = $namespace; |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* @inheritdoc |
55
|
|
|
*/ |
56
|
|
|
public function getName() { |
57
|
|
|
return $this->namespace; |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* Get depth of result |
62
|
|
|
* |
63
|
|
|
* @return int |
64
|
|
|
*/ |
65
|
|
|
public function getDepth() { |
66
|
|
|
return sizeof(preg_split('!([^\w]+)!', $this->getName()), COUNT_NORMAL); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* @inheritdoc |
71
|
|
|
*/ |
72
|
|
|
public function asArray() { |
73
|
|
|
return |
74
|
|
|
array_merge(array( |
75
|
|
|
'name' => $this->getName() |
76
|
|
|
, 'childs' => $this->getChilds() ? $this->getChilds()->asArray() : array() |
77
|
|
|
, 'depth' => $this->getDepth() |
78
|
|
|
) |
79
|
|
|
,$this->getAbstractness() ? $this->getAbstractness()->asArray() : array() |
80
|
|
|
,$this->getInstability() ? $this->getInstability()->asArray() : array() |
81
|
|
|
,$this->getBounds() ? $this->getBounds()->asArray() : array() |
82
|
|
|
|
83
|
|
|
); |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* @param \Hal\Metrics\Mood\Abstractness\Result $abstractness |
88
|
|
|
* @return ResultAggregate |
89
|
|
|
*/ |
90
|
|
|
public function setAbstractness(\Hal\Metrics\Mood\Abstractness\Result $abstractness) |
91
|
|
|
{ |
92
|
|
|
$this->abstractness = $abstractness; |
93
|
|
|
return $this; |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* @return \Hal\Metrics\Mood\Abstractness\Result |
98
|
|
|
*/ |
99
|
|
|
public function getAbstractness() |
100
|
|
|
{ |
101
|
|
|
return $this->abstractness; |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
/** |
105
|
|
|
* @param \Hal\Component\Bounds\Result\BoundsResult $bounds |
106
|
|
|
* @return ResultAggregate |
107
|
|
|
*/ |
108
|
|
|
public function setBounds(\Hal\Component\Bounds\Result\BoundsResult $bounds) |
109
|
|
|
{ |
110
|
|
|
$this->bounds = $bounds; |
111
|
|
|
return $this; |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
/** |
115
|
|
|
* @return \Hal\Component\Bounds\Result\BoundsResult |
116
|
|
|
*/ |
117
|
|
|
public function getBounds() |
118
|
|
|
{ |
119
|
|
|
return $this->bounds; |
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
/** |
123
|
|
|
* @param \Hal\Metrics\Mood\Instability\Result $instability |
124
|
|
|
* @return ResultAggregate |
125
|
|
|
*/ |
126
|
|
|
public function setInstability($instability) |
127
|
|
|
{ |
128
|
|
|
$this->instability = $instability; |
129
|
|
|
return $this; |
130
|
|
|
} |
131
|
|
|
|
132
|
|
|
/** |
133
|
|
|
* @return \Hal\Metrics\Mood\Instability\Result |
134
|
|
|
*/ |
135
|
|
|
public function getInstability() |
136
|
|
|
{ |
137
|
|
|
return $this->instability; |
138
|
|
|
} |
139
|
|
|
|
140
|
|
|
/** |
141
|
|
|
* @param \Hal\Component\Result\ResultCollection $childs |
142
|
|
|
*/ |
143
|
|
|
public function setChilds($childs) |
144
|
|
|
{ |
145
|
|
|
$this->childs = $childs; |
146
|
|
|
} |
147
|
|
|
|
148
|
|
|
/** |
149
|
|
|
* @return \Hal\Component\Result\ResultCollection |
150
|
|
|
*/ |
151
|
|
|
public function getChilds() |
152
|
|
|
{ |
153
|
|
|
return $this->childs; |
154
|
|
|
} |
155
|
|
|
|
156
|
|
|
} |