Skip to content

Commit

Permalink
Do not support array of patterns in Preg methods
Browse files Browse the repository at this point in the history
  • Loading branch information
kubawerlos committed Dec 16, 2021
1 parent b4b6d13 commit b610b92
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 22 deletions.
13 changes: 2 additions & 11 deletions src/Preg.php
Expand Up @@ -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()) {
Expand All @@ -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()) {
Expand Down
12 changes: 1 addition & 11 deletions tests/PregTest.php
Expand Up @@ -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();

Expand Down Expand Up @@ -176,7 +176,6 @@ public function testReplaceFailing(): void
* @param string|string[] $subject
*
* @dataProvider provideCommonCases
* @dataProvider provideArrayOfPatternsCases
*/
public function testReplace($pattern, $subject): void
{
Expand All @@ -199,7 +198,6 @@ public function testReplaceCallbackFailing(): void
* @param string|string[] $subject
*
* @dataProvider provideCommonCases
* @dataProvider provideArrayOfPatternsCases
*/
public function testReplaceCallback($pattern, $subject): void
{
Expand All @@ -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);
Expand Down

0 comments on commit b610b92

Please sign in to comment.