예제 #1
0
 function isVariadic()
 {
     foreach ($this->method->getParams() as $param) {
         if ($param->variadic) {
             return true;
         }
     }
     if ($this->method instanceof ParserFunction || $this->method instanceof \PhpParser\Node\Stmt\ClassMethod) {
         return VariadicCheckVisitor::isVariadic($this->method->getStmts());
     }
     return false;
 }
    function testMissingBreak()
    {
        $code = '<?
			if(true) {
				func_get_args();
			}
		';
        $code1 = '<?
			func_num_args();
		';
        $code2 = '<?
			func_get_arg(1);
		';
        $code3 = '<?
			safe_func();
		';
        $this->assertTrue(\Guardrail\NodeVisitors\VariadicCheckVisitor::isVariadic(self::parseText($code)), "Nested call not detected");
        $this->assertTrue(\Guardrail\NodeVisitors\VariadicCheckVisitor::isVariadic(self::parseText($code1)), "Top level func_num_args() call not detected");
        $this->assertTrue(\Guardrail\NodeVisitors\VariadicCheckVisitor::isVariadic(self::parseText($code2)), "Top level func_get_arg() call not detected");
        $this->assertFalse(\Guardrail\NodeVisitors\VariadicCheckVisitor::isVariadic(self::parseText($code3)), "Clean code not detected variadic");
    }