diff --git a/WordPress-Core/ruleset.xml b/WordPress-Core/ruleset.xml index b4e973a70f..2835d85cb4 100644 --- a/WordPress-Core/ruleset.xml +++ b/WordPress-Core/ruleset.xml @@ -116,7 +116,8 @@ - + + diff --git a/WordPress/Sniffs/PHP/DiscouragedFunctionsSniff.php b/WordPress/Sniffs/PHP/DiscouragedFunctionsSniff.php index 806247a124..34068bd57e 100644 --- a/WordPress/Sniffs/PHP/DiscouragedFunctionsSniff.php +++ b/WordPress/Sniffs/PHP/DiscouragedFunctionsSniff.php @@ -31,13 +31,6 @@ class WordPress_Sniffs_PHP_DiscouragedFunctionsSniff extends Generic_Sniffs_PHP_ * @var array(string => string|null) */ public $forbiddenFunctions = array( - // Deprecated. - 'ereg_replace' => 'preg_replace', - 'ereg' => null, - 'eregi_replace' => 'preg_replace', - 'split' => null, - 'spliti' => null, - // Development. 'print_r' => null, 'debug_print_backtrace' => null, diff --git a/WordPress/Sniffs/PHP/POSIXFunctionsSniff.php b/WordPress/Sniffs/PHP/POSIXFunctionsSniff.php new file mode 100644 index 0000000000..2ab56a9a99 --- /dev/null +++ b/WordPress/Sniffs/PHP/POSIXFunctionsSniff.php @@ -0,0 +1,69 @@ + + */ +class WordPress_Sniffs_PHP_POSIXFunctionsSniff extends WordPress_AbstractFunctionRestrictionsSniff { + + /** + * Groups of functions to restrict. + * + * Example: groups => array( + * 'lambda' => array( + * 'type' => 'error' | 'warning', + * 'message' => 'Use anonymous functions instead please!', + * 'functions' => array( 'eval', 'create_function' ), + * ) + * ) + * + * @return array + */ + public function getGroups() { + return array( + 'ereg' => array( + 'type' => 'error', + 'message' => '%s has been deprecated since PHP 5.3 and removed in PHP 7.0, please use preg_match() instead.', + 'functions' => array( + 'ereg', + 'eregi', + 'sql_regcase', + ), + ), + + 'ereg_replace' => array( + 'type' => 'error', + 'message' => '%s has been deprecated since PHP 5.3 and removed in PHP 7.0, please use preg_replace() instead.', + 'functions' => array( + 'ereg_replace', + 'eregi_replace', + ), + ), + + 'split' => array( + 'type' => 'error', + 'message' => '%s has been deprecated since PHP 5.3 and removed in PHP 7.0, please use explode(), str_split() or preg_split() instead.', + 'functions' => array( + 'split', + 'spliti', + ), + ), + + ); + } // end getGroups() + +} // end class diff --git a/WordPress/Sniffs/VIP/RestrictedFunctionsSniff.php b/WordPress/Sniffs/VIP/RestrictedFunctionsSniff.php index 72111b816a..50ccb710ec 100644 --- a/WordPress/Sniffs/VIP/RestrictedFunctionsSniff.php +++ b/WordPress/Sniffs/VIP/RestrictedFunctionsSniff.php @@ -285,38 +285,6 @@ public function getGroups() { ), ), - 'ereg' => array( - 'type' => 'error', - 'message' => '%s is prohibited, please use preg_match() instead. See http://php.net/manual/en/function.ereg.php', - 'functions' => array( - 'ereg', - ), - ), - - 'eregi' => array( - 'type' => 'error', - 'message' => '%s is prohibited, please use preg_match() with i modifier instead. See http://php.net/manual/en/function.eregi.php', - 'functions' => array( - 'eregi', - ), - ), - - 'ereg_replace' => array( - 'type' => 'error', - 'message' => '%s is prohibited, please use preg_replace() instead. See http://php.net/manual/en/function.ereg-replace.php', - 'functions' => array( - 'ereg_replace', - ), - ), - - 'split' => array( - 'type' => 'error', - 'message' => '%s is prohibited, please use explode() or preg_split() instead. See http://php.net/manual/en/function.split.php', - 'functions' => array( - 'split', - ), - ), - 'runtime_configuration' => array( 'type' => 'error', 'message' => '%s is prohibited, changing configuration at runtime is not allowed on VIP Production.', diff --git a/WordPress/Tests/PHP/DiscouragedFunctionsUnitTest.inc b/WordPress/Tests/PHP/DiscouragedFunctionsUnitTest.inc index 2852bfcd72..0c1733e3b7 100644 --- a/WordPress/Tests/PHP/DiscouragedFunctionsUnitTest.inc +++ b/WordPress/Tests/PHP/DiscouragedFunctionsUnitTest.inc @@ -9,24 +9,6 @@ var_dump( $post_id ); // Bad, forbidden use print_r( $post_ID ); // Bad, forbidden use -// DEPRECATED PHP FUNCTIONS -// ------------------------ - -$title = get_the_title(); - -$title = ereg_replace( 'cool', 'not cool', get_the_title() ); // Bad, ereg_replace has been deprecated. Use preg_replace instead. -$title = preg_replace( 'cool', 'not cool', get_the_title() ); // Good - -if ( ereg( '[A-Za-z]+', $title, $regs ) ) // Bad, ereg also deprecated. Use preg_match instead. - die( $regs ); - -$title = eregi_replace( 'cool', 'not cool', get_the_title() ); // Bad, eregi_replace also deprecated. Use preg_replace instead. - -list( $year, $month, $day ) = split( ':', $date ); // Bad, split has been deprecated. Use preg_split or explode instead. - -$title_parts = spliti( ' ', get_the_title(), 4 ); // Bad, spliti also deprecated. Use preg_split instead. - - // DEPRECATED WORDPRESS FUNCTIONS // ------------------------------ diff --git a/WordPress/Tests/PHP/DiscouragedFunctionsUnitTest.php b/WordPress/Tests/PHP/DiscouragedFunctionsUnitTest.php index 4ef3e1e383..e59a7cc11e 100644 --- a/WordPress/Tests/PHP/DiscouragedFunctionsUnitTest.php +++ b/WordPress/Tests/PHP/DiscouragedFunctionsUnitTest.php @@ -49,28 +49,23 @@ public function getWarningList() { return array( 8 => 1, 9 => 1, + 15 => 1, 17 => 1, - 20 => 1, + 19 => 1, + 21 => 1, 23 => 1, 25 => 1, 27 => 1, + 29 => 1, + 31 => 1, 33 => 1, 35 => 1, 37 => 1, 39 => 1, - 41 => 1, - 43 => 1, 45 => 1, 47 => 1, - 49 => 1, - 51 => 1, - 53 => 1, - 55 => 1, - 57 => 1, - 63 => 1, - 65 => 1, - 70 => 1, - 72 => 1, + 52 => 1, + 54 => 1, ); } // end getWarningList() diff --git a/WordPress/Tests/PHP/POSIXFunctionsUnitTest.inc b/WordPress/Tests/PHP/POSIXFunctionsUnitTest.inc new file mode 100644 index 0000000000..bad1dd5372 --- /dev/null +++ b/WordPress/Tests/PHP/POSIXFunctionsUnitTest.inc @@ -0,0 +1,26 @@ + + * @author Greg Sherwood + * @author Marc McIntyre + * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence + * @version Release: @package_version@ + * @link http://pear.php.net/package/PHP_CodeSniffer + */ +class WordPress_Tests_PHP_POSIXFunctionsUnitTest extends AbstractSniffUnitTest { + + /** + * Returns the lines where errors should occur. + * + * The key of the array should represent the line number and the value + * should represent the number of errors that should occur on that line. + * + * @return array(int => int) + */ + public function getErrorList() { + return array( + 13 => 1, + 16 => 1, + 18 => 1, + 20 => 1, + 22 => 1, + 24 => 1, + 26 => 1, + ); + + } // end getErrorList() + + /** + * Returns the lines where warnings should occur. + * + * The key of the array should represent the line number and the value + * should represent the number of warnings that should occur on that line. + * + * @return array(int => int) + */ + public function getWarningList() { + return array(); + + } // end getWarningList() + +} // end class