Skip to content

Commit 3b6ff9a

Browse files
committed
simplify getReformattedText
1 parent bfa5991 commit 3b6ff9a

File tree

1 file changed

+1
-44
lines changed

1 file changed

+1
-44
lines changed

src/Ast/Comment.php

+1-44
Original file line numberDiff line numberDiff line change
@@ -33,50 +33,7 @@ public function __construct(string $text, int $startLine = -1, int $startIndex =
3333

3434
public function getReformattedText(): ?string
3535
{
36-
$text = trim($this->text);
37-
$newlinePos = strpos($text, "\n");
38-
if ($newlinePos === false) {
39-
// Single line comments don't need further processing
40-
return $text;
41-
} elseif (preg_match('((*BSR_ANYCRLF)(*ANYCRLF)^.*(?:\R\s+\*.*)+$)', $text) === 1) {
42-
// Multi line comment of the type
43-
//
44-
// /*
45-
// * Some text.
46-
// * Some more text.
47-
// */
48-
//
49-
// is handled by replacing the whitespace sequences before the * by a single space
50-
return preg_replace('(^\s+\*)m', ' *', $this->text);
51-
} elseif (preg_match('(^/\*\*?\s*[\r\n])', $text) === 1 && preg_match('(\n(\s*)\*/$)', $text, $matches) === 1) {
52-
// Multi line comment of the type
53-
//
54-
// /*
55-
// Some text.
56-
// Some more text.
57-
// */
58-
//
59-
// is handled by removing the whitespace sequence on the line before the closing
60-
// */ on all lines. So if the last line is " */", then " " is removed at the
61-
// start of all lines.
62-
return preg_replace('(^' . preg_quote($matches[1]) . ')m', '', $text);
63-
} elseif (preg_match('(^/\*\*?\s*(?!\s))', $text, $matches) === 1) {
64-
// Multi line comment of the type
65-
//
66-
// /* Some text.
67-
// Some more text.
68-
// Indented text.
69-
// Even more text. */
70-
//
71-
// is handled by removing the difference between the shortest whitespace prefix on all
72-
// lines and the length of the "/* " opening sequence.
73-
$prefixLen = $this->getShortestWhitespacePrefixLen(substr($text, $newlinePos + 1));
74-
$removeLen = $prefixLen - strlen($matches[0]);
75-
return preg_replace('(^\s{' . $removeLen . '})m', '', $text);
76-
}
77-
78-
// No idea how to format this comment, so simply return as is
79-
return $text;
36+
return trim($this->text);
8037
}
8138

8239
private function getShortestWhitespacePrefixLen(string $str): int

0 commit comments

Comments
 (0)