-
-
Notifications
You must be signed in to change notification settings - Fork 493
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Checking callbacks for restricted functions #843
Closed
grappler
wants to merge
7
commits into
WordPress:develop
from
grappler:feature/611-restricted-callbacks
Closed
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
a3fbe27
Start checking callbacks for restricted functions
grappler 41087d2
Improve how the Sniff is checked for
grappler 943804e
Correct documentation and use strip_quotes only when needed
grappler f28de3f
Update for PHPCS 3.0+
grappler fa2ca4d
Temporarily disable the prelim check to pass tests
grappler c68ce05
Fix coding standards issues
grappler 5394278
Run preliminary check if not callback function
grappler File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
WordPress/Tests/Functions/FunctionRestrictionsUnitTest.inc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?php | ||
|
||
// Warnings. | ||
add_filter( '', 'foobar' ); | ||
add_action( '', 'foobar' ); | ||
call_user_func( 'foobar' ); | ||
call_user_func_array( 'foobar' ); | ||
forward_static_call( 'foobar' ); | ||
forward_static_call_array( 'foobar' ); | ||
array_diff_uassoc( '', '', 'foobar' ); | ||
array_diff_ukey( '', '', 'foobar' ); | ||
array_filter( '', 'foobar' ); | ||
array_intersect_uassoc( '', 'foobar' ); | ||
array_intersect_ukey( '', 'foobar' ); | ||
array_map( 'foobar' ); | ||
array_reduce( '', 'foobar' ); | ||
array_udiff_assoc( array(), 'foobar' ); | ||
array_udiff_uassoc( array(), 'foobar', 'barfoo' ); | ||
array_udiff( '', 'foobar' ); | ||
array_uintersect_assoc( '', 'foobar' ); | ||
array_uintersect_uassoc( '', 'foobar', 'barfoo' ); | ||
array_uintersect( '', 'foobar' ); | ||
array_walk( '', 'foobar' ); | ||
array_walk_recursive( '', 'foobar' ); | ||
iterator_apply( '', 'foobar' ); | ||
usort( '', 'foobar' ); | ||
uasort( '', 'foobar' ); | ||
uksort( '', 'foobar' ); | ||
preg_replace_callback( '', 'foobar' ); | ||
mb_ereg_replace_callback( '', 'foobar' ); | ||
header_register_callback( 'foobar' ); | ||
ob_start( 'foobar' ); | ||
set_error_handler( 'foobar' ); | ||
set_exception_handler( 'foobar' ); | ||
register_shutdown_function( 'foobar' ); | ||
register_tick_function( 'foobar' ); |
66 changes: 66 additions & 0 deletions
66
WordPress/Tests/Functions/FunctionRestrictionsUnitTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
<?php | ||
/** | ||
* Unit test class for WordPress Coding Standard. | ||
* | ||
* @package WPCS\WordPressCodingStandards | ||
* @link https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards | ||
* @license https://opensource.org/licenses/MIT MIT | ||
*/ | ||
|
||
namespace WordPress\Tests\Functions; | ||
|
||
use PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest; | ||
use WordPress\AbstractFunctionRestrictionsSniff; | ||
|
||
/** | ||
* Unit test class for the FunctionRestrictions sniff. | ||
* | ||
* @package WPCS\WordPressCodingStandards | ||
* @since 0.10.0 | ||
*/ | ||
class FunctionRestrictionsUnitTest extends AbstractSniffUnitTest { | ||
|
||
/** | ||
* Add a number of extra restricted functions to unit test the abstract | ||
* FunctionRestrictions class. | ||
* | ||
* Note: as that class extends the abstract FunctionRestrictions class, that's | ||
* where we are passing the parameters to. | ||
*/ | ||
protected function setUp() { | ||
parent::setUp(); | ||
|
||
AbstractFunctionRestrictionsSniff::$unittest_groups = array( | ||
'test' => array( | ||
'type' => 'warning', | ||
'message' => 'Detected usage of %s.', | ||
'functions' => array( | ||
'foobar', | ||
'barfoo', | ||
), | ||
), | ||
); | ||
} | ||
|
||
/** | ||
* Returns the lines where errors should occur. | ||
* | ||
* @return array <int line number> => <int number of errors> | ||
*/ | ||
public function getErrorList() { | ||
return array(); | ||
} | ||
|
||
/** | ||
* Returns the lines where warnings should occur. | ||
* | ||
* @return array <int line number> => <int number of warnings> | ||
*/ | ||
public function getWarningList() { | ||
$array = array_fill( 4, 33, 1 ); | ||
$array[18] = 2; | ||
$array[21] = 2; | ||
return $array; | ||
} | ||
|
||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need for the
array()
wrapper here.