WhitespacesFixerConfig.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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. * @readonly
  17. */
  18. final class WhitespacesFixerConfig
  19. {
  20. /** @var non-empty-string */
  21. private string $indent;
  22. /** @var non-empty-string */
  23. private string $lineEnding;
  24. /**
  25. * @param non-empty-string $indent
  26. * @param non-empty-string $lineEnding
  27. */
  28. public function __construct(string $indent = ' ', string $lineEnding = "\n")
  29. {
  30. if (!\in_array($indent, [' ', ' ', "\t"], true)) {
  31. throw new \InvalidArgumentException('Invalid "indent" param, expected tab or two or four spaces.');
  32. }
  33. if (!\in_array($lineEnding, ["\n", "\r\n"], true)) {
  34. throw new \InvalidArgumentException('Invalid "lineEnding" param, expected "\n" or "\r\n".');
  35. }
  36. $this->indent = $indent;
  37. $this->lineEnding = $lineEnding;
  38. }
  39. /**
  40. * @return non-empty-string
  41. */
  42. public function getIndent(): string
  43. {
  44. return $this->indent;
  45. }
  46. /**
  47. * @return non-empty-string
  48. */
  49. public function getLineEnding(): string
  50. {
  51. return $this->lineEnding;
  52. }
  53. }