/** * Remove a result from the collection * * Removes a result, which is identified by its analysis target id from * the current collection. * * @param string|AnalysisResult $result * @return true */ public function remove($result) { if ($result instanceof AnalysisResult) { $id = $result->getAnalysisTargetId(); } elseif (is_string($result)) { $id = $result; if (isset($this->results[$id])) { $result = $this->results[$id]; } else { return true; } } else { throw new \InvalidArgumentException('The result argument has to be an instance of AnalysisResult or a string.'); } $needRecalc = false; if ($this->highestDemand !== null && $result->getAnalysisTargetId() === $this->getHighestDemandingResult()->getAnalysisTargetId()) { $needRecalc = true; } unset($this->results[$id]); if ($needRecalc) { $this->recalculateHighestDemandingResult(); } return true; }
/** * Attach a (new) ResultInstance to this analyser * * Set a new result instance to this analyser. If a result was already attached or the to be attached result is * already sealed an exception is thrown. * * @param \Pvra\AnalysisResult $result The `AnalysisResult` to be * attached to this analyser * @return $this Returns the current instance to allow method chaining * @throws \Exception Thrown in case that the given result is sealed or an Result instance was already attached. * * @see RequirementAnalysisResult::setAnalysisTargetId() Method that is called on the attached result instance */ public function setResultInstance(AnalysisResult $result) { if ($this->result !== null) { throw new \Exception('A result instance was already set. Overriding it may lead to data loss.'); } elseif ($result->isSealed()) { throw new \LogicException('The attached Result instance is already sealed.'); } $this->result = $result; $this->result->setAnalysisTargetId($this->createAnalysisTargetId()); return $this; }