Skip to content

Commit 05fe5f7

Browse files
committed
Feat: Add MultilineStringToHeredocFixer (part of #94)
1 parent 646c1ef commit 05fe5f7

File tree

3 files changed

+35
-0
lines changed

3 files changed

+35
-0
lines changed

Diff for: ecs.php

+3
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@
136136
use PhpCsFixer\Fixer\Semicolon\SpaceAfterSemicolonFixer;
137137
use PhpCsFixer\Fixer\Strict\DeclareStrictTypesFixer;
138138
use PhpCsFixer\Fixer\Strict\StrictParamFixer;
139+
use PhpCsFixer\Fixer\StringNotation\MultilineStringToHeredocFixer;
139140
use PhpCsFixer\Fixer\StringNotation\SingleQuoteFixer;
140141
use PhpCsFixer\Fixer\Whitespace\ArrayIndentationFixer;
141142
use PhpCsFixer\Fixer\Whitespace\BlankLineBeforeStatementFixer;
@@ -383,6 +384,8 @@
383384
DeclareStrictTypesFixer::class,
384385
// Functions should be used with `$strict` param set to `true`
385386
StrictParamFixer::class,
387+
// Convert multiline string to heredoc or nowdoc.
388+
MultilineStringToHeredocFixer::class,
386389
// Convert double quotes to single quotes for simple strings
387390
SingleQuoteFixer::class,
388391
// Each element of an array must be indented exactly once.

Diff for: tests/Integration/Fixtures/Basic.correct.php.inc

+17
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,23 @@ class Basic extends AbstractBasic implements InterfaceFromThisNamespace // Fully
6161
$baz = implode(',', ['foo', 'bar']);
6262
}
6363

64+
// HeredocIndentationFixer
65+
$heredoc = <<<HEREDOC
66+
This is a
67+
multiline heredoc string. It contains $foo.
68+
It should be indented, though.
69+
HEREDOC;
70+
// HeredocIndentationFixer
71+
$newdoc = <<<'NEWDOC'
72+
This is a $newdoc, where variables are not expanded.
73+
NEWDOC;
74+
// MultilineStringToHeredocFixer
75+
$multilineString = <<<'EOD'
76+
This string
77+
spans multiple lines
78+
but should be heredoc instead
79+
EOD;
80+
6481
// SingleLineCommentSpacingFixer
6582
// This comment should have space on the beginning
6683
/* So should this one, also with space on the end */

Diff for: tests/Integration/Fixtures/Basic.wrong.php.inc

+15
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,21 @@ class Basic extends \Some\Other\Namespace\AbstractBasic implements \Lmc\CodingSt
5353
$baz = join(',', ['foo', 'bar']);
5454
}
5555

56+
// HeredocIndentationFixer
57+
$heredoc = <<<HEREDOC
58+
This is a
59+
multiline heredoc string. It contains $foo.
60+
It should be indented, though.
61+
HEREDOC;
62+
// HeredocIndentationFixer
63+
$newdoc = <<<'NEWDOC'
64+
This is a $newdoc, where variables are not expanded.
65+
NEWDOC;
66+
// MultilineStringToHeredocFixer
67+
$multilineString = 'This string
68+
spans multiple lines
69+
but should be heredoc instead';
70+
5671
// SingleLineCommentSpacingFixer
5772
//This comment should have space on the beginning
5873
/*So should this one, also with space on the end*/

0 commit comments

Comments
 (0)