Пример #1
0
 /**
  * @param Namespace_ $node
  * @param File       $target
  */
 public function handleNamespace(Namespace_ $node, File $target)
 {
     $name = $node->name;
     $namespace = $this->codeFactory->buildNamespace($name);
     $target->addNamespace($namespace);
     $this->parse($node->stmts, $namespace);
 }
Пример #2
0
 /**
  * Generates code
  */
 function it_generates_code(File $file, PrettyPrinterAbstract $printer)
 {
     $factory = new BuilderFactory();
     $file->getNamespaces()->willReturn([new PHPNamespace('test')]);
     $printer->prettyPrintFile([$factory->namespace('test')->getNode()])->willReturn('foo')->shouldBeCalled();
     $this->generate($file)->shouldReturn('foo');
 }
Пример #3
0
 /**
  * Passes the namespace instead of the file when handling non namespace node
  */
 function it_passes_the_namespace_instead_of_the_file_when_handling_non_namespace_node(File $file, PHPNamespace $namespace, CodeFactoryContract $codeFactory, PHPClass $class)
 {
     $file->getCurrentNamespace()->willReturn($namespace);
     $classNode = new Class_('Foo');
     $codeFactory->buildClass('Foo', 0)->willReturn($class)->shouldBeCalled();
     $namespace->addClass($class)->shouldBeCalled();
     $this->parse([$classNode], $file);
 }
Пример #4
0
 /**
  * @param File $file
  *
  * @return mixed
  */
 public function generate(File $file)
 {
     $nodes = [];
     $namespaces = $file->getNamespaces();
     foreach ($namespaces as $namespace) {
         $nodes[] = $this->generateNamespace($namespace);
     }
     return $this->printer->prettyPrintFile($nodes);
 }