Ejemplo n.º 1
0
 /**
  * @param \nochso\Omni\Multiline $lines
  *
  * @return string
  */
 private function extractShortDescription(Multiline $lines)
 {
     $summary = new Multiline();
     $summary->setEol((string) $lines->getEol());
     for (; $this->position < count($lines); $this->position++) {
         $line = $lines[$this->position];
         if (Strings::startsWith($line, '@')) {
             break;
         }
         if (trim($line) === '') {
             $this->position++;
             break;
         }
         $summary->add($line);
         if (Strings::endsWith($line, '.')) {
             $this->position++;
             break;
         }
     }
     return (string) $summary;
 }
Ejemplo n.º 2
0
 /**
  * @dataProvider endsWithProvider
  */
 public function testEndsWith($expected, $subject, $suffix)
 {
     $this->assertSame($expected, Strings::endsWith($subject, $suffix));
 }
Ejemplo n.º 3
0
 /**
  * Pretty prints an array of nodes (statements) and indents them optionally.
  *
  * @param \PhpParser\Node[] $nodes  Array of nodes
  * @param bool   $indent Whether to indent the printed nodes
  *
  * @return string Pretty printed statements
  */
 protected function pStmts(array $nodes, $indent = true)
 {
     if ($this->orderElements) {
         $this->comparer->sort($nodes);
     }
     $this->useSorter->sort($nodes);
     $result = '';
     $prevContext = null;
     /** @var Node $prevNode */
     $prevNode = null;
     foreach ($nodes as $node) {
         $newContext = get_class($node);
         if ($prevContext !== $newContext) {
             if ($prevContext !== null && (in_array($prevContext, $this->separateTypes) || in_array($newContext, $this->separateTypes))) {
                 $result .= "\n";
             }
             $prevContext = $newContext;
         } elseif (in_array($newContext, $this->separateIdenticalTypes)) {
             $result .= "\n";
         }
         /** @var \PhpParser\Comment[] $comments */
         $comments = $node->getAttribute('comments', []);
         if ($comments) {
             // Keep comments on the same line.
             if ($prevNode !== null && $comments[0]->getLine() === $prevNode->getAttribute('endLine')) {
                 $result .= ' ';
             } else {
                 $result .= "\n";
             }
             $result .= $this->pComments($comments);
             if ($node instanceof Stmt\Nop) {
                 $prevNode = $node;
                 continue;
             }
         }
         $prevNode = $node;
         $nodeCode = $this->p($node);
         if (strpos($nodeCode, "\n") !== false) {
             if (Strings::endsWith($nodeCode, '))')) {
                 $nodeCode = substr($nodeCode, 0, -2) . ")\n\t)";
             } elseif (Strings::endsWith($nodeCode, '));')) {
                 $nodeCode = substr($nodeCode, 0, -3) . ")\n\t);";
             }
         }
         $result .= "\n" . $nodeCode . ($node instanceof Node\Expr ? ';' : '');
     }
     if ($indent) {
         return preg_replace('~\\n(?!$|\\n|' . $this->noIndentToken . ')~', "\n" . $this->indentation, $result);
     } else {
         return $result;
     }
 }