1 | <?php |
||
28 | class Collection implements \Countable, \IteratorAggregate, \JsonSerializable |
||
29 | { |
||
30 | /** |
||
31 | * Result instances that are part of this collection |
||
32 | * |
||
33 | * @var \Pvra\AnalysisResult[] |
||
34 | */ |
||
35 | private $results = []; |
||
36 | /** |
||
37 | * The targetId of the currently highest demanding result |
||
38 | * |
||
39 | * @var string |
||
40 | */ |
||
41 | private $highestDemand; |
||
42 | |||
43 | /** |
||
44 | * Add a result to this collection |
||
45 | * |
||
46 | * @param \Pvra\AnalysisResult $result The result to be added |
||
47 | * @param bool $ignoreIfExists Do not add+override an already existing result with the same targetId. |
||
48 | * @return $this |
||
49 | */ |
||
50 | 34 | public function add(AnalysisResult $result, $ignoreIfExists = true) |
|
68 | |||
69 | /** |
||
70 | * Remove a result from the collection |
||
71 | * |
||
72 | * Removes a result, which is identified by its analysis target id from |
||
73 | * the current collection. |
||
74 | * |
||
75 | * @param string|AnalysisResult $result |
||
76 | * @return true |
||
77 | */ |
||
78 | 4 | public function remove($result) |
|
108 | |||
109 | /** |
||
110 | * Recalculates the highest demanding result of this collection |
||
111 | * |
||
112 | * This can be expensive. Only do this if really necessary. |
||
113 | */ |
||
114 | 2 | private function recalculateHighestDemandingResult() |
|
131 | |||
132 | /** |
||
133 | * Checks whether a given result is part of this collection |
||
134 | * |
||
135 | * @param string|\Pvra\AnalysisResult $result Analysis target Id or instance of Analysis Result |
||
136 | * @return bool |
||
137 | */ |
||
138 | 36 | public function has($result) |
|
148 | |||
149 | /** |
||
150 | * Get the currently highest demanding result |
||
151 | * |
||
152 | * @return null|\Pvra\AnalysisResult |
||
153 | */ |
||
154 | 20 | public function getHighestDemandingResult() |
|
162 | |||
163 | /** |
||
164 | * Retrieve an external iterator |
||
165 | * |
||
166 | * @link http://php.net/manual/en/iteratoraggregate.getiterator.php |
||
167 | * @return Traversable|AnalysisResult[] |
||
168 | */ |
||
169 | 12 | public function getIterator() |
|
173 | |||
174 | /** |
||
175 | * Count attached results |
||
176 | * |
||
177 | * @link http://php.net/manual/en/countable.count.php |
||
178 | * @return int The custom count as an integer. |
||
179 | * The return value is cast to an integer. |
||
180 | */ |
||
181 | 20 | public function count() |
|
185 | |||
186 | /** |
||
187 | * Specify data which should be serialized to JSON |
||
188 | * |
||
189 | * @link http://php.net/manual/en/jsonserializable.jsonserialize.php |
||
190 | * @return mixed data which can be serialized by json_encode, |
||
191 | * which is a value of any type other than a resource. |
||
192 | */ |
||
193 | 6 | public function jsonSerialize() |
|
206 | } |
||
207 |