From ce6337c21e2d463890cd988c27d091573e05f679 Mon Sep 17 00:00:00 2001 From: Rasmus Bertell Date: Sun, 4 Feb 2024 16:40:04 +0200 Subject: [PATCH 1/2] feat: allow arbitrary space indentation --- src/WhitespacesFixerConfig.php | 4 ++-- tests/WhitespacesFixerConfigTest.php | 4 +++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/WhitespacesFixerConfig.php b/src/WhitespacesFixerConfig.php index e558fd6b9c5..b84a104f56a 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.']; } } From 45ec3eb2cc2e1d9ab8555da1a6b874b67132cb22 Mon Sep 17 00:00:00 2001 From: Rasmus Bertell Date: Sun, 4 Feb 2024 17:28:19 +0200 Subject: [PATCH 2/2] fix: use Preg::* instead of preg_* --- src/WhitespacesFixerConfig.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/WhitespacesFixerConfig.php b/src/WhitespacesFixerConfig.php index b84a104f56a..d8dd65ba7b9 100644 --- a/src/WhitespacesFixerConfig.php +++ b/src/WhitespacesFixerConfig.php @@ -25,7 +25,7 @@ final class WhitespacesFixerConfig public function __construct(string $indent = ' ', string $lineEnding = "\n") { - if (!preg_match('/^(?: +|\t)$/', $indent)) { + if (!Preg::match('/^(?: +|\t)$/', $indent)) { throw new \InvalidArgumentException('Invalid "indent" param, expected tab or spaces.'); }