Exemplo n.º 1
0
 /**
  * TODO remove this fix backport CG lib version > 1.0.0
  *
  * {@inheritdoc}
  * @SuppressWarnings(PHPMD.NPathComplexity)
  */
 public function startVisitingClass(PhpClass $class)
 {
     if ($namespace = $class->getNamespace()) {
         $this->getWriter()->write('namespace ' . $namespace . ';' . "\n\n");
     }
     if ($files = $class->getRequiredFiles()) {
         foreach ($files as $file) {
             $this->getWriter()->writeln('require_once ' . var_export($file, true) . ';');
         }
         $this->getWriter()->write("\n");
     }
     if ($useStatements = $class->getUseStatements()) {
         foreach ($useStatements as $alias => $namespace) {
             $this->getWriter()->write('use ' . $namespace);
             if (substr($namespace, strrpos($namespace, '\\') + 1) !== $alias) {
                 $this->getWriter()->write(' as ' . $alias);
             }
             $this->getWriter()->write(";\n");
         }
         $this->getWriter()->write("\n");
     }
     if ($docblock = $class->getDocblock()) {
         $this->getWriter()->write($docblock);
     }
     if ($class->isAbstract()) {
         $this->getWriter()->write('abstract ');
     }
     if ($class->isFinal()) {
         $this->getWriter()->write('final ');
     }
     $this->getWriter()->write('class ' . $class->getShortName());
     if ($parentClassName = $class->getParentClassName()) {
         $this->getWriter()->write(' extends ' . ('\\' . ltrim($parentClassName, '\\')));
     }
     $interfaceNames = $class->getInterfaceNames();
     if (!empty($interfaceNames)) {
         $interfaceNames = array_unique($interfaceNames);
         $interfaceNames = array_map(function ($name) {
             if ('\\' === $name[0]) {
                 return $name;
             }
             return '\\' . $name;
         }, $interfaceNames);
         $this->getWriter()->write(' implements ' . implode(', ', $interfaceNames));
     }
     $this->getWriter()->write("\n{\n")->indent();
 }
Exemplo n.º 2
0
 public function testSetGetInterfaceNames()
 {
     $class = new PhpClass();
     $this->assertEquals(array(), $class->getInterfaceNames());
     $this->assertSame($class, $class->setInterfaceNames(array('foo', 'bar')));
     $this->assertEquals(array('foo', 'bar'), $class->getInterfaceNames());
     $this->assertSame($class, $class->addInterfaceName('stdClass'));
     $this->assertEquals(array('foo', 'bar', 'stdClass'), $class->getInterfaceNames());
 }