Skip to content

Commit

Permalink
Feat: Add MultilineStringToHeredocFixer (part of #94)
Browse files Browse the repository at this point in the history
  • Loading branch information
OndraM committed May 23, 2024
1 parent 6399ba0 commit a65d4db
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 0 deletions.
3 changes: 3 additions & 0 deletions ecs.php
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@
use PhpCsFixer\Fixer\Strict\DeclareStrictTypesFixer;
use PhpCsFixer\Fixer\Strict\StrictComparisonFixer;
use PhpCsFixer\Fixer\Strict\StrictParamFixer;
use PhpCsFixer\Fixer\StringNotation\MultilineStringToHeredocFixer;
use PhpCsFixer\Fixer\StringNotation\SingleQuoteFixer;
use PhpCsFixer\Fixer\Whitespace\ArrayIndentationFixer;
use PhpCsFixer\Fixer\Whitespace\BlankLineBeforeStatementFixer;
Expand Down Expand Up @@ -386,6 +387,8 @@
StrictParamFixer::class,
// Comparisons should be strict, `===` or `!==` must be used for comparisons
StrictComparisonFixer::class,
// Convert multiline string to heredoc or nowdoc.
MultilineStringToHeredocFixer::class,
// Convert double quotes to single quotes for simple strings
SingleQuoteFixer::class,
// Each element of an array must be indented exactly once.
Expand Down
17 changes: 17 additions & 0 deletions tests/Integration/Fixtures/Basic.correct.php.inc
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,23 @@ class Basic extends AbstractBasic implements InterfaceFromThisNamespace // Fully
$baz = implode(',', ['foo', 'bar']);
}

// HeredocIndentationFixer
$heredoc = <<<HEREDOC
This is a
multiline heredoc string. It contains $foo.
It should be indented, though.
HEREDOC;
// HeredocIndentationFixer
$newdoc = <<<'NEWDOC'
This is a $newdoc, where variables are not expanded.
NEWDOC;
// MultilineStringToHeredocFixer
$multilineString = <<<'EOD'
This string
spans multiple lines
but should be heredoc instead
EOD;

// SingleLineCommentSpacingFixer
// This comment should have space on the beginning
/* So should this one, also with space on the end */
Expand Down
15 changes: 15 additions & 0 deletions tests/Integration/Fixtures/Basic.wrong.php.inc
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,21 @@ class Basic extends \Some\Other\Namespace\AbstractBasic implements \Lmc\CodingSt
$baz = join(',', ['foo', 'bar']);
}

// HeredocIndentationFixer
$heredoc = <<<HEREDOC
This is a
multiline heredoc string. It contains $foo.
It should be indented, though.
HEREDOC;
// HeredocIndentationFixer
$newdoc = <<<'NEWDOC'
This is a $newdoc, where variables are not expanded.
NEWDOC;
// MultilineStringToHeredocFixer
$multilineString = 'This string
spans multiple lines
but should be heredoc instead';

// SingleLineCommentSpacingFixer
//This comment should have space on the beginning
/*So should this one, also with space on the end*/
Expand Down

0 comments on commit a65d4db

Please sign in to comment.