Skip to content

Commit 4def45b

Browse files
committed
bug #4840 LineEndingFixer - T_CLOSE_TAG support, StringLineEndingFixer - T_INLI… (SpacePossum)
This PR was merged into the 2.15 branch. Discussion ---------- LineEndingFixer - T_CLOSE_TAG support, StringLineEndingFixer - T_INLI… …NE_HTML support Fixes #4812 Fixes two issues of the line ending fixers. For reference #2224 and #3452 Commits ------- 522e819 LineEndingFixer - T_CLOSE_TAG support, StringLineEndingFixer - T_INLINE_HTML support
2 parents aa8e45f + 522e819 commit 4def45b

File tree

4 files changed

+26
-20
lines changed

4 files changed

+26
-20
lines changed

src/Fixer/StringNotation/StringLineEndingFixer.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ final class StringLineEndingFixer extends AbstractFixer implements WhitespacesAw
3232
*/
3333
public function isCandidate(Tokens $tokens)
3434
{
35-
return $tokens->isAnyTokenKindsFound([T_CONSTANT_ENCAPSED_STRING, T_ENCAPSED_AND_WHITESPACE]);
35+
return $tokens->isAnyTokenKindsFound([T_CONSTANT_ENCAPSED_STRING, T_ENCAPSED_AND_WHITESPACE, T_INLINE_HTML]);
3636
}
3737

3838
/**
@@ -68,7 +68,7 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens)
6868
$ending = $this->whitespacesConfig->getLineEnding();
6969

7070
foreach ($tokens as $tokenIndex => $token) {
71-
if (!$token->isGivenKind([T_CONSTANT_ENCAPSED_STRING, T_ENCAPSED_AND_WHITESPACE])) {
71+
if (!$token->isGivenKind([T_CONSTANT_ENCAPSED_STRING, T_ENCAPSED_AND_WHITESPACE, T_INLINE_HTML])) {
7272
continue;
7373
}
7474

src/Fixer/Whitespace/LineEndingFixer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens)
8787
continue;
8888
}
8989

90-
if ($token->isGivenKind([T_OPEN_TAG, T_WHITESPACE, T_COMMENT, T_DOC_COMMENT, T_START_HEREDOC])) {
90+
if ($token->isGivenKind([T_CLOSE_TAG, T_COMMENT, T_DOC_COMMENT, T_OPEN_TAG, T_START_HEREDOC, T_WHITESPACE])) {
9191
$tokens[$index] = new Token([
9292
$token->getId(),
9393
Preg::replace(

tests/Fixer/StringNotation/StringLineEndingFixerTest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,10 @@ public function provideFixCases()
9393
sprintf(str_replace('<<<', 'B<<<', $heredocTemplate), $input),
9494
sprintf(str_replace('<<<', 'B<<<', $heredocTemplate), str_replace("\n", "\r\n", $input)),
9595
],
96+
'not T_CLOSE_TAG, do T_INLINE_HTML' => [
97+
"<?php foo(); ?>\r\nA\n\n",
98+
"<?php foo(); ?>\r\nA\r\n\r\n",
99+
],
96100
];
97101
}
98102

tests/Fixer/Whitespace/LineEndingFixerTest.php

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,11 @@ public function provideFixCases()
5050
"<?php \$b = \" \$a \r\n 123\"; \$a = <<<TEST\r\nAAAAA \n |\r\nTEST;\r\n", // both cases
5151
];
5252

53-
// !T_INLINE_HTML
54-
$cases[] = [
55-
"<?php ?>\r\n<?php ?>\r\n",
53+
$cases['T_INLINE_HTML'] = [
54+
"<?php ?>\nZ\r\n<?php ?>\nZ\r\n",
5655
];
5756

58-
// !T_CONSTANT_ENCAPSED_STRING
59-
$cases[] = [
57+
$cases['!T_CONSTANT_ENCAPSED_STRING'] = [
6058
"<?php \$a=\"a\r\n\";",
6159
];
6260

@@ -65,6 +63,16 @@ public function provideFixCases()
6563
"<?php echo 'foo',\r\r\n'bar';",
6664
];
6765

66+
$cases['T_CLOSE_TAG'] = [
67+
"<?php\n?>\n<?php\n",
68+
"<?php\n?>\r\n<?php\n",
69+
];
70+
71+
$cases['T_CLOSE_TAG II'] = [
72+
"<?php\n?>\n<?php\n?>\n<?php\n",
73+
"<?php\n?>\r\n<?php\n?>\r\n<?php\n",
74+
];
75+
6876
return $cases;
6977
}
7078

@@ -103,37 +111,31 @@ public function provideMessyWhitespacesCases()
103111
private function provideCommonCases()
104112
{
105113
return [
106-
// T_OPEN_TAG
107-
[
114+
'T_OPEN_TAG' => [
108115
"<?php\n \$a = 1;",
109116
"<?php\r\n \$a = 1;",
110117
],
111-
// T_WHITESPACE
112-
[
118+
'T_WHITESPACE' => [
113119
"<?php \n \$a\n= 1;\n",
114120
"<?php \r\n \$a\r\n= 1;\r\n",
115121
],
116-
// T_COMMENT
117-
[
122+
'T_COMMENT' => [
118123
"<?php /*\n*/",
119124
"<?php /*\r\n*/",
120125
],
121-
// T_DOC_COMMENT
122-
[
126+
'T_DOC_COMMENT' => [
123127
"<?php /**\n*/",
124128
"<?php /**\r\n*/",
125129
],
126-
// T_START_HEREDOC
127-
[
130+
'T_START_HEREDOC' => [
128131
"<?php \$a = <<<'TEST'\nAA\nTEST;\n",
129132
"<?php \$a = <<<'TEST'\r\nAA\r\nTEST;\r\n",
130133
],
131134
[
132135
"<?php \$a = <<<TEST\nAAA\nTEST;\n",
133136
"<?php \$a = <<<TEST\r\nAAA\r\nTEST;\r\n",
134137
],
135-
// T_ENCAPSED_AND_WHITESPACE
136-
[
138+
'T_ENCAPSED_AND_WHITESPACE' => [
137139
"<?php \$a = <<<'TEST'\nAAAA 1\n \$b\nTEST;\n",
138140
"<?php \$a = <<<'TEST'\r\nAAAA 1\r\n \$b\r\nTEST;\r\n",
139141
],

0 commit comments

Comments
 (0)