예제 #1
0
 /**
  * @param string $contents
  *
  * @return File
  */
 public function build($contents)
 {
     $file = new File($this->codeFactory->buildNamespace());
     $nodes = $this->PHPParser->parse($contents);
     $this->parser->parse($nodes, $file);
     return $file;
 }
예제 #2
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);
 }
예제 #3
0
 /**
  * Handles namespaces
  */
 function it_handles_namespaces(File $file, CodeFactoryContract $codeFactory, PHPNamespace $namespace)
 {
     $namespaceNode = new Namespace_(new Name('A\\B'));
     $codeFactory->buildNamespace('A\\B')->willReturn($namespace)->shouldBeCalled();
     $file->addNamespace($namespace)->shouldBeCalled();
     $this->parse([$namespaceNode], $file);
 }
예제 #4
0
 /**
  * Build a file
  */
 function it_build_a_file(CodeFactoryContract $codeFactory, PHPNamespace $namespace, Parser $PHPParser, ParserContract $parser)
 {
     $codeFactory->buildNamespace()->willReturn($namespace)->shouldBeCalled();
     $PHPParser->parse('foo')->willReturn([]);
     $file = $this->build('foo');
     $file->shouldBeAnInstanceOf('FileModifier\\File\\File');
     $parser->parse([], $file)->shouldHaveBeenCalled();
 }