Skip to content

Commit 5735f5e

Browse files
committed
Remove todos; bugfix for Windows-style newlines
1 parent f9fc69a commit 5735f5e

3 files changed

Lines changed: 28 additions & 8 deletions

File tree

src/BlockString/TokenStream.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public function next(): ?BlockString
7171

7272
private function extractDelimiter(Token $token): string
7373
{
74-
return trim($token->getContent(), "<'\"\n");
74+
return trim($token->getContent(), "<'\"\r\n");
7575
}
7676

7777
private function extractIndentation(Token $token): string

src/Formatter/AbstractCodecFormatter.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,11 +103,11 @@ abstract protected function formatContent(string $original): string;
103103

104104
private function removeIndentation(string $lines, string $indentation): string
105105
{
106-
return substr(str_replace("\n{$indentation}", "\n", $lines), strlen($indentation)); // TODO feels wrong (eol)
106+
return substr(str_replace("\n{$indentation}", "\n", $lines), strlen($indentation));
107107
}
108108

109109
private function applyIndentation(string $lines, string $indentation): string
110110
{
111-
return $indentation . str_replace("\n", "\n{$indentation}", $lines); // TODO feels wrong (eol)
111+
return $indentation . str_replace("\n", "\n{$indentation}", $lines);
112112
}
113113
}

tests/Unit/Fixer/BlockStringFixerTest.php

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public function testConfigurationIsRequired(): void
5252
* @param TFormatterConfig $config
5353
* @dataProvider provideFixCases
5454
*/
55-
final public function testApplyFix(array $config, string $input, string $expected): void
55+
public function testApplyFix(array $config, string $input, string $expected): void
5656
{
5757
$fixer = new BlockStringFixer();
5858
$tokens = Tokens::fromCode($input);
@@ -91,7 +91,7 @@ public static function provideFixCases(): iterable
9191
'HTML' => new class extends AbstractCodecFormatter {
9292
public function __construct()
9393
{
94-
parent::__construct('1.0', null);
94+
parent::__construct('1');
9595
}
9696

9797
protected function formatContent(string $original): string
@@ -133,7 +133,7 @@ protected function formatContent(string $original): string
133133
new class extends AbstractCodecFormatter {
134134
public function __construct()
135135
{
136-
parent::__construct('1.0', null);
136+
parent::__construct('2');
137137
}
138138

139139
protected function formatContent(string $original): string
@@ -144,7 +144,7 @@ protected function formatContent(string $original): string
144144
'HTML' => new class extends AbstractCodecFormatter {
145145
public function __construct()
146146
{
147-
parent::__construct('1.0', null);
147+
parent::__construct('3');
148148
}
149149

150150
protected function formatContent(string $original): string
@@ -180,7 +180,7 @@ protected function formatContent(string $original): string
180180
'HTML' => new class extends AbstractCodecFormatter {
181181
public function __construct()
182182
{
183-
parent::__construct('1.0', new GeneratedTokenCodec());
183+
parent::__construct('4', new GeneratedTokenCodec());
184184
}
185185

186186
protected function formatContent(string $original): string
@@ -203,5 +203,25 @@ protected function formatContent(string $original): string
203203
HTML;
204204
PHP,
205205
];
206+
207+
yield 'Windows-style newlines' => [
208+
'config' => [
209+
'formatters' => [
210+
'HTML' => new class extends AbstractCodecFormatter {
211+
public function __construct()
212+
{
213+
parent::__construct('5');
214+
}
215+
216+
protected function formatContent(string $original): string
217+
{
218+
return strip_tags($original);
219+
}
220+
},
221+
],
222+
],
223+
'input' => "<?php\r\n\r\necho <<<'HTML'\r\n <h1>Hello world!</h1>\r\n HTML;\r\n",
224+
'expected' => "<?php\r\n\r\necho <<<'HTML'\r\n Hello world!\r\n HTML;\r\n",
225+
];
206226
}
207227
}

0 commit comments

Comments
 (0)