/** * @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; }
/** * @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); }
/** * 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); }
/** * 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(); }