/** * Create a new class model from an interface * * @param string $interfaceName * @return ClassModel */ public function make($interfaceName) { $interfaceDataProvider = $this->interfaceDataProviderFactory->make($interfaceName); $namespace = $this->namespacePrefix . '\\' . $interfaceDataProvider->getNamespace(); $classModel = new ClassModel($namespace, $interfaceDataProvider->getName(), $interfaceDataProvider->getFullName()); // dispatch the start event $this->eventDispatcher->dispatch(StartEvent::NAME, new StartEvent($classModel)); $methods = $interfaceDataProvider->getMethods(); foreach ($methods as $methodDataProvider) { $methodModel = $this->methodModelFactory->make($classModel, $methodDataProvider); $annotationCollection = $methodDataProvider->getAnnotations(); // skip methods that don't have any annotations $annotations = $annotationCollection->getAnnotations(); if (empty($annotations)) { continue; } // dispatch the method event $this->eventDispatcher->dispatch(MethodEvent::NAME, new MethodEvent($methodModel, $annotationCollection)); $classModel->addMethod($methodModel); } // dispatch the end event $this->eventDispatcher->dispatch(EndEvent::NAME, new EndEvent($classModel)); return $classModel; }
public function testCanCreateInterfaceDataProvider() { $factory = new InterfaceDataProviderFactory(Mockery::mock(MethodDataProviderFactory::class), Mockery::mock(Reader::class)); $provider = $factory->make(MockInterface::class); $this->assertInstanceOf(InterfaceDataProvider::class, $provider); }