From b610b9219bf9e3d62064921f23beaee9868c105b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kuba=20Wer=C5=82os?= Date: Wed, 15 Dec 2021 19:24:52 +0100 Subject: [PATCH] Do not support array of patterns in Preg methods --- src/Preg.php | 13 ++----------- tests/PregTest.php | 12 +----------- 2 files changed, 3 insertions(+), 22 deletions(-) diff --git a/src/Preg.php b/src/Preg.php index f238e11f3e4..6216e01e078 100644 --- a/src/Preg.php +++ b/src/Preg.php @@ -65,15 +65,11 @@ public static function matchAll(string $pattern, string $subject, ?array &$match } /** - * @param string|string[] $pattern - * @param string|string[] $replacement * @param string|string[] $subject * * @throws PregException - * - * @return string|string[] */ - public static function replace($pattern, $replacement, $subject, int $limit = -1, ?int &$count = null) + public static function replace(string $pattern, string $replacement, $subject, int $limit = -1, ?int &$count = null): string { $result = @preg_replace(self::addUtf8Modifier($pattern), $replacement, $subject, $limit, $count); if (null !== $result && PREG_NO_ERROR === preg_last_error()) { @@ -89,14 +85,9 @@ public static function replace($pattern, $replacement, $subject, int $limit = -1 } /** - * @param string|string[] $pattern - * @param string|string[] $subject - * * @throws PregException - * - * @return string|string[] */ - public static function replaceCallback($pattern, callable $callback, $subject, int $limit = -1, ?int &$count = null) + public static function replaceCallback(string $pattern, callable $callback, string $subject, int $limit = -1, ?int &$count = null): string { $result = @preg_replace_callback(self::addUtf8Modifier($pattern), $callback, $subject, $limit, $count); if (null !== $result && PREG_NO_ERROR === preg_last_error()) { diff --git a/tests/PregTest.php b/tests/PregTest.php index e78e18fe2db..3a96911ff13 100644 --- a/tests/PregTest.php +++ b/tests/PregTest.php @@ -125,7 +125,7 @@ public function testPatternsValidation(string $pattern, ?int $expected = null, ? try { $buffer = "The quick brown \xFF\x00\\xXX jumps over the lazy dog\n"; - $actual = $buffer !== Preg::replace((array) $pattern, 'abc', $buffer); + $actual = $buffer !== Preg::replace($pattern, 'abc', $buffer); } catch (\Exception $ex) { $setup(); @@ -176,7 +176,6 @@ public function testReplaceFailing(): void * @param string|string[] $subject * * @dataProvider provideCommonCases - * @dataProvider provideArrayOfPatternsCases */ public function testReplace($pattern, $subject): void { @@ -199,7 +198,6 @@ public function testReplaceCallbackFailing(): void * @param string|string[] $subject * * @dataProvider provideCommonCases - * @dataProvider provideArrayOfPatternsCases */ public function testReplaceCallback($pattern, $subject): void { @@ -222,14 +220,6 @@ public function provideCommonCases(): array ]; } - public function provideArrayOfPatternsCases(): array - { - return [ - [['/à/', '/í/'], 'Tàíl'], - [['/'.\chr(174).'/', '/'.\chr(224).'/'], 'foo'], - ]; - } - public function testSplitFailing(): void { $this->expectException(PregException::class);