public function persist(CallSite $callSite) { // In this case, the call site has already been persisted. if (null !== $callSite->getId()) { return; } $sourceFunctionId = $targetFunctionId = $sourceMethodId = $targetMethodId = null; switch (true) { case $callSite instanceof FunctionToFunctionCallSite: $type = 'f2f'; $sourceFunctionId = $sourceId = $callSite->getSource()->getId(); $targetFunctionId = $targetId = $callSite->getTarget()->getId(); break; case $callSite instanceof FunctionToMethodCallSite: $type = 'f2m'; $sourceFunctionId = $sourceId = $callSite->getSource()->getId(); $targetMethodId = $targetId = $callSite->getTarget()->getId(); break; case $callSite instanceof MethodToFunctionCallSite: $type = 'm2f'; $sourceMethodId = $sourceId = $callSite->getSource()->getId(); $targetFunctionId = $targetId = $callSite->getTarget()->getId(); break; case $callSite instanceof MethodToMethodCallSite: $type = 'm2m'; $sourceMethodId = $sourceId = $callSite->getSource()->getId(); $targetMethodId = $targetId = $callSite->getTarget()->getId(); break; default: throw new \InvalidArgumentException('Unknown call site ' . get_class($callSite)); } // If either target, or source have not yet been persisted, we // simply ignore this call as there will be a second call when // both are complete. if (null === $sourceId || null === $targetId) { return; } $this->insertStmt->bindValue(1, $type); $this->insertStmt->bindValue(2, $sourceFunctionId, $sourceFunctionId ? \PDO::PARAM_INT : \PDO::PARAM_NULL); $this->insertStmt->bindValue(3, $targetFunctionId, $targetFunctionId ? \PDO::PARAM_INT : \PDO::PARAM_NULL); $this->insertStmt->bindValue(4, $targetMethodId, $targetMethodId ? \PDO::PARAM_INT : \PDO::PARAM_NULL); $this->insertStmt->bindValue(5, $sourceMethodId, $sourceMethodId ? \PDO::PARAM_INT : \PDO::PARAM_NULL); $this->insertStmt->execute(); $callSiteId = $this->con->lastInsertId(); $this->idRef->setValue($callSite, $callSiteId); if ("0" == $callSiteId) { throw new \LogicException(sprintf('Could not retrieve id of call-site: ' . json_encode(array('type' => $type, 'source_function_id' => $sourceFunctionId, 'target_function_id' => $targetFunctionId, 'target_method_id' => $targetMethodId, 'source_method_id' => $sourceMethodId)))); } foreach ($callSite->getArgs() as $arg) { $this->argPersister->persist($arg, $callSiteId); } }
public function removeCallSite(CallSite $site) { if ($site->getSource() === $this) { $target = $site->getTarget(); if ($target instanceof Method) { return $this->getOutMethodCallSites()->removeElement($site); } else { if ($target instanceof GlobalFunction) { return $this->getOutFunctionCallSites()->removeElement($site); } } throw new \LogicException('Previous ifs were exhaustive.'); } else { if ($site->getTarget() === $this) { $source = $site->getSource(); if ($source instanceof Method) { return $this->getInMethodCallSites()->removeElement($site); } else { if ($source instanceof GlobalFunction) { return $this->getInFunctionCallSites()->removeElement($site); } } throw new \LogicException('Previous ifs were exhaustive.'); } } throw new \InvalidArgumentException('$site is neither originating, nor targeting this function.'); }