private function processComments(array $comments) { $processed = []; $previousLineComment = null; $previousCommentLineNumber = null; foreach ($comments as $comment) { if ($comment instanceof Doc || in_array($comment, $this->seenComments)) { continue; } $this->seenComments[] = $comment; $text = $comment->getReformattedText(); if (0 === strpos($text, '/*')) { $text = substr(substr($text, 0, -2), 2); // remove comment delimiters $processed[] = new Comment($text, $comment->getLine(), $comment->getFilePos()); continue; } $text = substr($text, 2); if (!$previousLineComment) { $previousLineComment = new Comment($text, $comment->getLine(), $comment->getFilePos()); $previousCommentLineNumber = $comment->getLine(); continue; } if ($previousCommentLineNumber !== $comment->getLine() - 1) { // line comments aren't consecutive $processed[] = $previousLineComment; $previousLineComment = new Comment($text, $comment->getLine(), $comment->getFilePos()); $previousCommentLineNumber = $comment->getLine(); continue; } // merge consecutive line comments $previousLineComment = new Comment($previousLineComment->getText() . $text, $previousLineComment->getLine(), $previousLineComment->getFilePos()); $previousCommentLineNumber = $comment->getLine(); } if ($previousLineComment) { $processed[] = $previousLineComment; } return $processed; }