WhitespacesFixerConfig.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. <?php
  2. declare(strict_types=1);
  3. /*
  4. * This file is part of PHP CS Fixer.
  5. *
  6. * (c) Fabien Potencier <fabien@symfony.com>
  7. * Dariusz Rumiński <dariusz.ruminski@gmail.com>
  8. *
  9. * This source file is subject to the MIT license that is bundled
  10. * with this source code in the file LICENSE.
  11. */
  12. namespace PhpCsFixer;
  13. /**
  14. * @author Dariusz Rumiński <dariusz.ruminski@gmail.com>
  15. */
  16. final class WhitespacesFixerConfig
  17. {
  18. /** @var non-empty-string */
  19. private string $indent;
  20. /** @var non-empty-string */
  21. private string $lineEnding;
  22. /**
  23. * @param non-empty-string $indent
  24. * @param non-empty-string $lineEnding
  25. */
  26. public function __construct(string $indent = ' ', string $lineEnding = "\n")
  27. {
  28. if (!\in_array($indent, [' ', ' ', "\t"], true)) {
  29. throw new \InvalidArgumentException('Invalid "indent" param, expected tab or two or four spaces.');
  30. }
  31. if (!\in_array($lineEnding, ["\n", "\r\n"], true)) {
  32. throw new \InvalidArgumentException('Invalid "lineEnding" param, expected "\n" or "\r\n".');
  33. }
  34. $this->indent = $indent;
  35. $this->lineEnding = $lineEnding;
  36. }
  37. /**
  38. * @return non-empty-string
  39. */
  40. public function getIndent(): string
  41. {
  42. return $this->indent;
  43. }
  44. /**
  45. * @return non-empty-string
  46. */
  47. public function getLineEnding(): string
  48. {
  49. return $this->lineEnding;
  50. }
  51. }