Created
December 10, 2014 21:22
-
-
Save ockham/bffdf72507facf56c328 to your computer and use it in GitHub Desktop.
ForbiddenPHPFunctionsCheck.php
This file contains hidden or 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
<?php | |
/** | |
* Checks for the usage of forbidden PHP functions. | |
*/ | |
class ForbiddenPHPFunctionsCheck extends CodeCheck { | |
protected static $forbidden_php_functions = array( | |
'popen', | |
'proc_open', | |
'exec', | |
'shell_exec', | |
'system', | |
'passthru', | |
'base64_decode', | |
'base64_encode', | |
'uudecode', | |
'str_rot13', | |
'ini_set', | |
'create_function', | |
'extract', | |
); | |
function __construct() { | |
$checks = array( | |
'eval' => array( | |
'slug' => 'forbidden-php', | |
'level' => 'blocker', | |
'note' => sprintf( 'The PHP function %s was found. Themes cannot use this function.', '<code>eval()</code>' ), | |
'fn' => function( $node ) { | |
return ( $node instanceof PhpParser\Node\Expr\Eval_ ); | |
} | |
) | |
); | |
foreach( self::$forbidden_php_functions as $function ) { | |
$checks[ $function ] = array( | |
'slug' => 'forbidden-php', | |
'level' => 'blocker', | |
'note' => sprintf( 'The PHP function %s was found. Themes cannot use this function.', '<code>' . $function. '()</code>' ), | |
'fn' => function( $node ) use( $function ) { | |
if ( $node instanceof PhpParser\Node\Expr\FuncCall ) { | |
return $node->name->toString() === $function; | |
} | |
return false; | |
} | |
); | |
} | |
$visitor = new FlexibleCheckVisitor( $checks ); | |
parent::__construct( $visitor ); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment