function it_supports_type_hint_index_method_data_retrieval()
 {
     $this->typeHintIndex->lookup(SignatureClass::class, 'type_hint_index_resolved_class', '$parameter')->willReturn(TypeHintClass::class . 'Factory')->shouldBeCalled();
     $this->addGenerator(Generator\Factory::class, Generator\Factory::ENTITY_TYPE)->shouldReturn($this);
     $functionReflection = $this->classReflection->getMethod('type_hint_index_resolved_class');
     $this->validate($functionReflection)->shouldReturn($this);
     $this->shouldCreateFile($this->vfs->url() . '/spec/EcomDev/PHPSpec/MagentoDiAdapter/Fixture/TypeHintClassFactory.php');
 }
 /**
  * @param array $tokens
  * @param integer $index
  * @param array $token
  */
 private function extractTypehints(&$tokens, $index, $token)
 {
     $typehint = '';
     for ($i = $index - 1; in_array($tokens[$i][0], $this->typehintTokens); $i--) {
         $typehint = $tokens[$i][1] . $typehint;
         unset($tokens[$i]);
     }
     if ($typehint = trim($typehint)) {
         $class = $this->namespaceResolver->resolve($this->currentClass);
         try {
             $typehintFcqn = $this->namespaceResolver->resolve($typehint);
             $this->typeHintIndex->add($class, trim($this->currentFunction), $token[1], $typehintFcqn);
         } catch (DisallowedScalarTypehintException $e) {
             $this->typeHintIndex->addInvalid($class, trim($this->currentFunction), $token[1], $e);
         }
     }
 }
 /**
  * Reflection parameter
  *
  * @param \ReflectionParameter $parameter
  *
  * @return $this
  */
 private function validateParameter(\ReflectionParameter $parameter)
 {
     $catcher = function ($className) {
         $generator = $this->generator($className);
         if ($generator) {
             include $generator->generate();
         }
     };
     if (($reflectionClass = $parameter->getDeclaringClass()) && ($reflectionMethod = $parameter->getDeclaringFunction())) {
         $type = $this->typeHintIndex->lookup($reflectionClass->getName(), $reflectionMethod->getName(), '$' . $parameter->getName());
         if ($type && !class_exists($type) && !interface_exists($type)) {
             $catcher($type);
             return $this;
         }
     }
     spl_autoload_register($catcher);
     try {
         $parameter->getClass();
     } catch (\ReflectionException $e) {
         // Ignore reflection exception, as it is an intended behaviour for our catcher
     }
     spl_autoload_unregister($catcher);
     return $this;
 }
 /**
  * @param \ReflectionClass $classRefl
  * @param \ReflectionParameter $parameter
  *
  * @return string
  */
 private function getParameterTypeFromIndex(\ReflectionClass $classRefl, \ReflectionParameter $parameter)
 {
     return $this->typeHintIndex->lookup($classRefl->getName(), $parameter->getDeclaringFunction()->getName(), '$' . $parameter->getName());
 }
    function it_indexes_invalid_typehints(TypeHintIndex $typeHintIndex, NamespaceResolver $namespaceResolver)
    {
        $e = new DisallowedScalarTypehintException();
        $namespaceResolver->analyse(Argument::any())->shouldBeCalled();
        $namespaceResolver->resolve('Foo')->willReturn('Foo');
        $namespaceResolver->resolve('int')->willThrow($e);
        $this->rewrite('
        <?php

        class Foo
        {
            public function bar(int $bar)
            {
            }
        }

        ');
        $typeHintIndex->addInvalid('Foo', 'bar', '$bar', $e)->shouldHaveBeenCalled();
        $typeHintIndex->add('Foo', 'bar', '$bar', Argument::any())->shouldNotHaveBeenCalled();
    }