multiline_string_to_heredoc.rst 993 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. ====================================
  2. Rule ``multiline_string_to_heredoc``
  3. ====================================
  4. Convert multiline string to ``heredoc`` or ``nowdoc``.
  5. Examples
  6. --------
  7. Example #1
  8. ~~~~~~~~~~
  9. .. code-block:: diff
  10. --- Original
  11. +++ New
  12. <?php
  13. -$a = 'line1
  14. -line2';
  15. +$a = <<<'EOD'
  16. +line1
  17. +line2
  18. +EOD;
  19. Example #2
  20. ~~~~~~~~~~
  21. .. code-block:: diff
  22. --- Original
  23. +++ New
  24. <?php
  25. -$a = "line1
  26. -{$obj->getName()}";
  27. +$a = <<<EOD
  28. +line1
  29. +{$obj->getName()}
  30. +EOD;
  31. References
  32. ----------
  33. - Fixer class: `PhpCsFixer\\Fixer\\StringNotation\\MultilineStringToHeredocFixer <./../../../src/Fixer/StringNotation/MultilineStringToHeredocFixer.php>`_
  34. - Test class: `PhpCsFixer\\Tests\\Fixer\\StringNotation\\MultilineStringToHeredocFixerTest <./../../../tests/Fixer/StringNotation/MultilineStringToHeredocFixerTest.php>`_
  35. The test class defines officially supported behaviour. Each test case is a part of our backward compatibility promise.