private function inferTypeForParameter(AbstractFunction $function, Parameter $param)
 {
     $builder = new UnionTypeBuilder($this->typeRegistry);
     $index = $param->getIndex();
     foreach ($function->getInCallSites() as $site) {
         $args = $site->getArgs();
         if (!isset($args[$index])) {
             continue;
         }
         $builder->addAlternate($args[$index]->getPhpType());
     }
     $newType = $builder->build();
     if (!$newType->isNoType() && !$newType->isUnknownType()) {
         $param->setPhpType($newType);
     }
 }
 public function persist(Parameter $param, AbstractFunction $function)
 {
     switch (true) {
         case $function instanceof GlobalFunction:
             $stmt = $this->fStmt;
             break;
         case $function instanceof Method:
             $stmt = $this->mStmt;
             break;
         default:
             throw new \InvalidArgumentException('Unsupported AbstractFunction implementation ' . get_class($function));
     }
     $stmt->bindValue(1, $function->getId(), \PDO::PARAM_INT);
     $stmt->bindValue(2, $param->getName());
     $stmt->bindValue(3, $this->phpType->convertToDatabaseValue($param->getPhpType(), $this->platform));
     $stmt->bindValue(4, $param->getIndex(), \PDO::PARAM_INT);
     $stmt->bindValue(5, $param->isPassedByRef() ? 1 : 0, \PDO::PARAM_INT);
     $stmt->bindValue(6, $param->isOptional() ? 1 : 0, \PDO::PARAM_INT);
     $stmt->execute();
 }
 private function inferTypesForParameter(Parameter $param, AbstractFunction $function, Clazz $clazz = null)
 {
     if (($type = $param->getPhpType()) && !$type->isUnknownType() && !$type->isNullType() && !$type->isFalse() && !$type->isAllType()) {
         return;
     }
     $allowsNull = $type && $type->isNullType();
     if (null !== ($node = $param->getAstNode())) {
         $type = $this->parser->getTypeFromParamAnnotation($node, $param->getName());
         // Check whether we can use the type of a overridden method.
         // We only do this if we find a parent method that has been defined
         // on an interface (I), or if we find an abstract method (II).
         if (null === $type && $function instanceof Method && null !== $clazz) {
             foreach ($this->findOverriddenMethodsForDocInheritance($function->getName(), $clazz) as $parentMethod) {
                 if (null !== ($docType = $parentMethod->getParamDocType($param->getIndex()))) {
                     $type = $this->parser->getType($docType);
                     break;
                 }
             }
         }
     }
     if (null === $type) {
         $type = $this->registry->getNativeType('unknown');
     } else {
         if ($allowsNull) {
             $type = $this->registry->createNullableType($type);
         }
     }
     $param->setPhpType($type);
     if ($node) {
         $node->setAttribute('type', $type);
     }
 }
 private function inferTypeForParameter(AbstractFunction $function, \Scrutinizer\PhpAnalyzer\Model\Parameter $param)
 {
     $index = $param->getIndex();
     $types = array();
     foreach ($function->getInCallSites() as $site) {
         $args = $site->getArgs();
         if (!isset($args[$index])) {
             continue;
         }
         $argType = $args[$index]->getPhpType();
         if ($argType->isUnknownType() || $argType->isNoType()) {
             continue;
         }
         $types[] = $argType;
     }
     if (null !== ($astNode = $param->getAstNode()) && null !== $astNode->default) {
         $defaultType = $astNode->default->getAttribute('type');
         // The default type might be null for example if a constant is assigned
         // as a default value, and we could not determine the value of that constant.
         if (null !== $defaultType) {
             $types[] = $defaultType;
         }
     }
     return $this->refineTypeForAnnotation($this->registry->createUnionType($types));
 }
 public function addParameter(Parameter $parameter)
 {
     $parameter->setFunction($this);
     $this->parameters->set($parameter->getName(), $parameter);
 }