EofEndingFixer.php 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. <?php
  2. /*
  3. * This file is part of the PHP CS utility.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. *
  7. * This source file is subject to the MIT license that is bundled
  8. * with this source code in the file LICENSE.
  9. */
  10. namespace Symfony\CS\Fixer\PSR2;
  11. use Symfony\CS\FixerInterface;
  12. /**
  13. * @author Fabien Potencier <fabien@symfony.com>
  14. */
  15. class EofEndingFixer implements FixerInterface
  16. {
  17. /**
  18. * {@inheritdoc}
  19. */
  20. public function fix(\SplFileInfo $file, $content)
  21. {
  22. // [Structure] A file must always end with a linefeed character
  23. $content = rtrim($content);
  24. if (strlen($content)) {
  25. return $content."\n";
  26. }
  27. return $content;
  28. }
  29. /**
  30. * {@inheritdoc}
  31. */
  32. public function getLevel()
  33. {
  34. return FixerInterface::PSR2_LEVEL;
  35. }
  36. /**
  37. * {@inheritdoc}
  38. */
  39. public function getPriority()
  40. {
  41. // must run last to be sure the file is properly formatted before it runs
  42. return -50;
  43. }
  44. /**
  45. * {@inheritdoc}
  46. */
  47. public function supports(\SplFileInfo $file)
  48. {
  49. return true;
  50. }
  51. /**
  52. * {@inheritdoc}
  53. */
  54. public function getName()
  55. {
  56. return 'eof_ending';
  57. }
  58. /**
  59. * {@inheritdoc}
  60. */
  61. public function getDescription()
  62. {
  63. return 'A file must always end with an empty line feed.';
  64. }
  65. }