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'); }
/** * 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()); }