Skip to content

Commit 878bb87

Browse files
committed
Feat: Add MultilineStringToHeredocFixer (part of #94)
1 parent 233022f commit 878bb87

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
@@ -137,6 +137,7 @@
137137
use PhpCsFixer\Fixer\Strict\DeclareStrictTypesFixer;
138138
use PhpCsFixer\Fixer\Strict\StrictComparisonFixer;
139139
use PhpCsFixer\Fixer\Strict\StrictParamFixer;
140+
use PhpCsFixer\Fixer\StringNotation\MultilineStringToHeredocFixer;
140141
use PhpCsFixer\Fixer\StringNotation\SingleQuoteFixer;
141142
use PhpCsFixer\Fixer\Whitespace\ArrayIndentationFixer;
142143
use PhpCsFixer\Fixer\Whitespace\BlankLineBeforeStatementFixer;
@@ -386,6 +387,8 @@
386387
StrictParamFixer::class,
387388
// Comparisons should be strict, `===` or `!==` must be used for comparisons
388389
StrictComparisonFixer::class,
390+
// Convert multiline string to heredoc or nowdoc.
391+
MultilineStringToHeredocFixer::class,
389392
// Convert double quotes to single quotes for simple strings
390393
SingleQuoteFixer::class,
391394
// 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
@@ -63,6 +63,23 @@ class Basic extends AbstractBasic implements InterfaceFromThisNamespace // Fully
6363
$baz = implode(',', ['foo', 'bar']);
6464
}
6565

66+
// HeredocIndentationFixer
67+
$heredoc = <<<HEREDOC
68+
This is a
69+
multiline heredoc string. It contains $foo.
70+
It should be indented, though.
71+
HEREDOC;
72+
// HeredocIndentationFixer
73+
$newdoc = <<<'NEWDOC'
74+
This is a $newdoc, where variables are not expanded.
75+
NEWDOC;
76+
// MultilineStringToHeredocFixer
77+
$multilineString = <<<'EOD'
78+
This string
79+
spans multiple lines
80+
but should be heredoc instead
81+
EOD;
82+
6683
// SingleLineCommentSpacingFixer
6784
// This comment should have space on the beginning
6885
/* 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
@@ -55,6 +55,21 @@ class Basic extends \Some\Other\Namespace\AbstractBasic implements \Lmc\CodingSt
5555
$baz = join(',', ['foo', 'bar']);
5656
}
5757

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

0 commit comments

Comments
 (0)