diff --git a/src/WhitespacesFixerConfig.php b/src/WhitespacesFixerConfig.php index e558fd6b9c5..d8dd65ba7b9 100644 --- a/src/WhitespacesFixerConfig.php +++ b/src/WhitespacesFixerConfig.php @@ -25,8 +25,8 @@ final class WhitespacesFixerConfig public function __construct(string $indent = ' ', string $lineEnding = "\n") { - if (!\in_array($indent, [' ', ' ', "\t"], true)) { - throw new \InvalidArgumentException('Invalid "indent" param, expected tab or two or four spaces.'); + if (!Preg::match('/^(?: +|\t)$/', $indent)) { + throw new \InvalidArgumentException('Invalid "indent" param, expected tab or spaces.'); } if (!\in_array($lineEnding, ["\n", "\r\n"], true)) { diff --git a/tests/WhitespacesFixerConfigTest.php b/tests/WhitespacesFixerConfigTest.php index f6e800e89c1..5d5ca914a95 100644 --- a/tests/WhitespacesFixerConfigTest.php +++ b/tests/WhitespacesFixerConfigTest.php @@ -50,12 +50,14 @@ public static function provideFixCases(): iterable yield ["\t", "\n"]; + yield [str_repeat(' ', 12), "\n"]; + yield [' ', "\r\n"]; yield ["\t", "\r\n"]; yield [' ', 'asd', 'Invalid "lineEnding" param, expected "\n" or "\r\n".']; - yield ['std', "\n", 'Invalid "indent" param, expected tab or two or four spaces.']; + yield ['std', "\n", 'Invalid "indent" param, expected tab or spaces.']; } }