/** * Returns class' code inside namespace * * @param ClassReflection $class */ private function dumpClass(ClassReflection $class) { if (array_search($class->getName(), $this->cachedClasses) !== false) { return; } if ($class->isInternal()) { return; } if ($class->getParentClass()) { $this->dumpClass($class->getParentClass()); } foreach ($class->getInterfaces() as $interface) { $this->dumpClass($interface); } if ($class->getTraits()) { foreach ($class->getTraits() as $trait) { $this->dumpClass($trait); } } $classContents = $class->getContents(false); $classFileDir = dirname($class->getFileName()); $classContents = trim(str_replace('__DIR__', sprintf("'%s'", $classFileDir), $classContents)); $uses = implode("\n", $this->codeGenerator->getUseLines($class)); $this->cache[] = "namespace " . $class->getNamespaceName() . " {\n" . ($uses ? $uses . "\n" : '') . $this->codeGenerator->getDeclarationLine($class) . "\n" . $classContents . "\n}\n"; $this->cachedClasses[] = $class->getName(); }
/** * @param $class * @param $expectedLines * @dataProvider provideDataForGetDeclarationLine */ public function testGetDeclarationLine($class, $expectedLines) { $generator = new CodeGenerator(); $lines = $generator->getDeclarationLine(new ClassReflection($class)); $this->assertEquals($expectedLines, $lines); }