PhpSandbox\ValidatorVisitor::isKeyword PHP Method

isKeyword() protected method

Test the current PhpParser_Node node to see if it is a keyword, and return the name if it is and null if it is not
protected isKeyword ( PhpParser\Node $node ) : string | null
$node PhpParser\Node The sandboxed $node to test
return string | null Return string name of node, or null if it is not a keyword
    protected function isKeyword(Node $node)
    {
        switch ($node->getType()) {
            case 'Expr_Eval':
                return 'eval';
            case 'Expr_Exit':
                return 'exit';
            case 'Expr_Include':
                return 'include';
            case 'Stmt_Echo':
            case 'Expr_Print':
                //for our purposes print is treated as functionally equivalent to echo
                return 'echo';
            case 'Expr_Clone':
                return 'clone';
            case 'Expr_Empty':
                return 'empty';
            case 'Expr_Yield':
                return 'yield';
            case 'Stmt_Goto':
            case 'Stmt_Label':
                //no point in using labels without goto
                return 'goto';
            case 'Stmt_If':
            case 'Stmt_Else':
                //no point in using ifs without else
            //no point in using ifs without else
            case 'Stmt_ElseIf':
                //no point in using ifs without elseif
                return 'if';
            case 'Stmt_Break':
                return 'break';
            case 'Stmt_Switch':
            case 'Stmt_Case':
                //no point in using cases without switch
                return 'switch';
            case 'Stmt_Try':
            case 'Stmt_Catch':
                //no point in using catch without try
            //no point in using catch without try
            case 'Stmt_TryCatch':
                //no point in using try, catch or finally without try
                return 'try';
            case 'Stmt_Throw':
                return 'throw';
            case 'Stmt_Unset':
                return 'unset';
            case 'Stmt_Return':
                return 'return';
            case 'Stmt_Static':
                return 'static';
            case 'Stmt_While':
            case 'Stmt_Do':
                //no point in using do without while
                return 'while';
            case 'Stmt_Declare':
            case 'Stmt_DeclareDeclare':
                //no point in using declare key=>value without declare
                return 'declare';
            case 'Stmt_For':
            case 'Stmt_Foreach':
                //no point in using foreach without for
                return 'for';
            case 'Expr_Instanceof':
                return 'instanceof';
            case 'Expr_Isset':
                return 'isset';
            case 'Expr_List':
                return 'list';
        }
        return null;
    }