StringUtils: Clarify that isValidRegex is for PCRE regexps
authorDaimona Eaytoy <daimona.wiki@gmail.com>
Thu, 19 Sep 2019 09:55:19 +0000 (11:55 +0200)
committerKrinkle <krinklemail@gmail.com>
Sat, 28 Sep 2019 19:05:29 +0000 (19:05 +0000)
As suggested in c14571ba26e (I257a096319f1e).

Change-Id: Ia91d037f2f4bf8a1bad4eac65fecb1d3e2679d2d

includes/libs/StringUtils.php
tests/phpunit/includes/libs/StringUtilsTest.php

index 19dd8fe..7303d9b 100644 (file)
@@ -316,6 +316,23 @@ class StringUtils {
                return $text;
        }
 
+       /**
+        * Utility function to check if the given string is a valid PCRE regex. Avoids
+        * manually calling suppressWarnings and restoreWarnings, and provides a
+        * one-line solution without the need to use @.
+        *
+        * @since 1.34
+        * @param string $string The string you want to check being a valid regex
+        * @return bool
+        */
+       public static function isValidPCRERegex( $string ) {
+               AtEase::suppressWarnings();
+               // @phan-suppress-next-line PhanParamSuspiciousOrder False positive
+               $isValid = preg_match( $string, '' );
+               AtEase::restoreWarnings();
+               return $isValid !== false;
+       }
+
        /**
         * Escape a string to make it suitable for inclusion in a preg_replace()
         * replacement parameter.
@@ -343,21 +360,4 @@ class StringUtils {
                        return new ArrayIterator( explode( $separator, $subject ) );
                }
        }
-
-       /**
-        * Utility function to check if the given string is a valid regex. Avoids
-        * manually calling suppressWarnings and restoreWarnings, and provides a
-        * one-line solution without the need to use @.
-        *
-        * @since 1.34
-        * @param string $string The string you want to check being a valid regex
-        * @return bool
-        */
-       public static function isValidRegex( $string ) {
-               AtEase::suppressWarnings();
-               // @phan-suppress-next-line PhanParamSuspiciousOrder False positive
-               $isValid = preg_match( $string, '' );
-               AtEase::restoreWarnings();
-               return $isValid !== false;
-       }
 }
index 79d5788..66b04ad 100644 (file)
@@ -130,14 +130,15 @@ class StringUtilsTest extends PHPUnit\Framework\TestCase {
         * @param strin $input
         * @param bool $expected
         * @dataProvider provideRegexps
-        * @covers StringUtils::isValidRegex
+        * @covers StringUtils::isValidPCRERegex
         */
-       public function testIsValidRegex( $input, $expected ) {
-               $this->assertSame( $expected, StringUtils::isValidRegex( $input ) );
+       public function testIsValidPCRERegex( $input, $expected ) {
+               $this->assertSame( $expected, StringUtils::isValidPCRERegex( $input ) );
        }
 
        /**
-        * Data provider for testValidRegex
+        * Data provider for testIsValidPCRERegex
+        * @return array
         */
        public static function provideRegexps() {
                return [