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);
     }
 }
 private function assertInCallSites(AbstractFunction $function, array $inMethods, array $inFunctions)
 {
     $this->assertSame(count($inMethods) + count($inFunctions), count($function->getInCallSites()));
     $this->assertSame(count($inMethods), count($function->getInMethodCallSites()));
     $this->assertSame(count($inFunctions), count($function->getInFunctionCallSites()));
     $i = 0;
     foreach ($function->getInMethodCallSites() as $site) {
         $this->assertTrue(isset($inMethods[$i]), 'Index ' . $i . ' not expected');
         $this->assertSame($function, $site->getTarget());
         $this->assertSame($inMethods[$i], $site->getSource());
         $i += 1;
     }
     $i = 0;
     foreach ($function->getInFunctionCallSites() as $site) {
         $this->assertTrue(isset($inFunctions[$i]));
         $this->assertSame($function, $site->getTarget());
         $this->assertSame($inFunctions[$i], $site->getSource());
         $i += 1;
     }
 }
 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));
 }
 private function copyInCallSites(AbstractFunction $function, AbstractFunction $nonCachedFunction)
 {
     foreach ($function->getInCallSites() as $site) {
         $source = $site->getSource();
         $args = $site->getArgs()->getValues();
         $args = array_map(function ($arg) {
             return clone $arg;
         }, $args);
         $source->removeCallSite($site);
         CallSite::create($source, $nonCachedFunction, $args);
     }
 }