Skip to content
Snippets Groups Projects
Commit fa639636 authored by Jared Hancock's avatar Jared Hancock
Browse files

test: implement static funcions and catch blocks

Allow the php source analyzer scan for $this in static functions as well as
properly handle the exception variable inside catch blocks.
parent c44a7ec0
No related branches found
No related tags found
No related merge requests found
...@@ -26,6 +26,7 @@ class SourceAnalyzer extends Test { ...@@ -26,6 +26,7 @@ class SourceAnalyzer extends Test {
$class = array('line'=>$line); $class = array('line'=>$line);
$token = false; $token = false;
$blocks = 0; $blocks = 0;
$func_options = array('allow_this'=>true);
while (list($i,$token) = each($this->tokens)) { while (list($i,$token) = each($this->tokens)) {
switch ($token[0]) { switch ($token[0]) {
case '{': case '{':
...@@ -42,7 +43,14 @@ class SourceAnalyzer extends Test { ...@@ -42,7 +43,14 @@ class SourceAnalyzer extends Test {
case T_FUNCTION: case T_FUNCTION:
$this->traverseFunction( $this->traverseFunction(
array($token[2], $line[1]), array($token[2], $line[1]),
array('allow_this'=>true)); $func_options);
// Continue to reset $func_options
case ';':
// Reset function options
$func_options = array('allow_this'=>true);
break;
case T_STATIC:
$func_options['allow_this'] = false;
break; break;
case T_VAR: case T_VAR:
// var $variable // var $variable
...@@ -94,7 +102,7 @@ class SourceAnalyzer extends Test { ...@@ -94,7 +102,7 @@ class SourceAnalyzer extends Test {
break; break;
case '}': case '}':
if (--$blocks == 0) if (--$blocks == 0)
return; return $scope;
break; break;
case T_VARIABLE: case T_VARIABLE:
// Look-ahead for assignment // Look-ahead for assignment
...@@ -286,6 +294,24 @@ class SourceAnalyzer extends Test { ...@@ -286,6 +294,24 @@ class SourceAnalyzer extends Test {
} }
} }
break; break;
case T_CATCH:
// catch (Exception $var) {
while (list(,$token) = each($this->tokens)) {
if ($token == '{')
break;
elseif ($token[0] == T_VARIABLE)
$variable = $token[1];
}
$scope[$variable] = 1;
$scope = $this->checkVariableUsage($function, $scope, 1,
$options);
// Variable is no longer in scope; however, other variables
// defined in the catch {} block remain in scope.
// (Technically, the variable is in scope, but we will
// consider it bad coding practice to deal with an exception
// outisde the catch block
unset($scope[$variable]);
break;
case T_DOLLAR_OPEN_CURLY_BRACES: case T_DOLLAR_OPEN_CURLY_BRACES:
case T_CURLY_OPEN: case T_CURLY_OPEN:
// "{$a .. }" // "{$a .. }"
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment