Example #1
0
 /**
  * Constructor.
  *
  * @param bool $raw
  */
 public function generate($raw = false)
 {
     $writer = new Writer();
     $writer->writeln('<?php')->newline();
     array_map([$writer, 'writeln'], $this->contents);
     $writer->appendln(PHP_EOL);
     return $raw ? $writer : $writer->dump();
 }
Example #2
0
 /**
  * {@inheritdoc}
  */
 public function generate($raw = false)
 {
     $this->getDoc($writer = new Writer())->writeln(sprintf('%s%s $%s', $this->visibility, $this->prefix, $this->name));
     if (null !== $this->value) {
         $writer->appendln(' = ' . $this->value);
     }
     $writer->appendln(';')->setOutputIndentation(1);
     return $raw ? $writer : $writer->dump();
 }
Example #3
0
 /**
  * getDocBlock
  *
  * @return Writer|string
  */
 protected final function getDoc(Writer $writer, $asString = false)
 {
     $this->prepareAnnotations($block = clone $this->docBlock);
     $writer->writeln($block);
     return $asString ? $writer->dump() : $writer;
 }
Example #4
0
 /**
  * {@inheritdoc}
  */
 public function generate($raw = false)
 {
     $writer = new Writer();
     $prefix = $this->isReference ? '&' : '';
     $prefix .= $this->isVariadic ? '...' : '';
     $type = null === $this->type || in_array($this->type, array_merge(self::$silent, self::$primitives)) ? '' : $this->type . ' ';
     if (null !== $this->default) {
         $line = sprintf('%s%s$%s = %s', $type, $prefix, $this->name, $this->default);
     } else {
         $line = sprintf('%s%s$%s', $type, $prefix, $this->name);
     }
     $writer->writeln($line);
     return $raw ? $writer : $writer->dump();
 }
Example #5
0
 /** @test */
 public function itShouldAddNoExtraSpace()
 {
     $wr = new Writer();
     $wr->writeln('foo')->writeln('bar')->indent()->replaceln('', 1)->writeln('baz');
     $this->assertSame("foo\n\n    baz", $wr->dump());
 }
Example #6
0
 /**
  * getBody
  *
  * @return string
  */
 protected function getBody()
 {
     if (null === $this->body) {
         return;
     }
     if ($this->body instanceof Writer) {
         $body = $this->body;
     } else {
         $body = new Writer();
         $body->writeln($this->body);
     }
     $body->setOutputIndentation(0);
     return $body->dump();
 }