/**
  * Analyzes this file.
  */
 protected function analyze_file()
 {
     // Load the contents of the file
     if (is_null($this->filecontents) || !$this->filecontents) {
         $this->filecontents = file_get_contents($this->filepath);
     }
     if (false === $this->filecontents) {
         return;
     }
     // Parse the tokens
     require_once VIP_SCANNER_DIR . '/class-token-parser.php';
     $parser = new TokenParser();
     $items = $parser->parse_contents($this->filecontents);
     // Parse the items
     $this->hierarchy_elements = array();
     $this->parse_token_results($items);
 }
예제 #2
0
 function parse_function_call($properties = array())
 {
     $properties = array_merge(array('type' => 'function_call', 'name' => '', 'args' => array(), 'path' => $this->get_current_path_str(), 'line' => $this->line), $properties);
     $levels = array('(' => 0, '{' => 0, 'path' => array());
     $state = self::POTENTIAL_FUNCTION_CALL;
     $current_arg = '';
     for (; $this->index < $this->token_count; ++$this->index) {
         $this->get_token($token, $token_contents);
         $this->maybe_toggle_double_quoted_string($token);
         $this->parse_contents_line_breaks($token_contents);
         if (T_WHITESPACE === $token) {
             continue;
         }
         // Checks for an unexpected closing block
         if ($this->closes_block($token, $levels, true)) {
             if ($state === self::FUNCTION_CALL_ARGS) {
                 break;
             } else {
                 if (true === $this->is_inside_double_quoted_string()) {
                     break;
                 } else {
                     $this->index -= 1;
                     return;
                 }
             }
         }
         switch ($state) {
             case self::POTENTIAL_FUNCTION_CALL:
                 switch ($token) {
                     case T_VARIABLE:
                         $properties['name'] .= substr($token_contents, 1);
                         break;
                     case T_STRING:
                     case T_EVAL:
                     case T_EMPTY:
                     case T_EXIT:
                     case T_HALT_COMPILER:
                     case T_INCLUDE:
                     case T_INCLUDE_ONCE:
                     case T_REQUIRE:
                     case T_REQUIRE_ONCE:
                     case T_ISSET:
                     case T_LIST:
                     case T_PRINT:
                     case T_UNSET:
                         $properties['name'] .= $token_contents;
                         break;
                     case T_DOUBLE_COLON:
                     case T_OBJECT_OPERATOR:
                         $properties['name'] .= self::PATH_SEPERATOR;
                         break;
                     case '(':
                         $state = self::FUNCTION_CALL_ARGS;
                         break;
                     default:
                         // This doesn't look like a proper function call. Get out.
                         return;
                 }
                 break;
             case self::FUNCTION_CALL_ARGS:
                 switch ($token) {
                     case ')':
                         if (0 === $levels['(']) {
                             break 3;
                         } elseif ($levels['('] < 0) {
                             break 3;
                         }
                         $current_arg .= $token_contents;
                         break;
                     case '(':
                         $current_arg .= $token_contents;
                         break;
                     default:
                         if (0 === $levels['(']) {
                             if (is_string($token)) {
                                 break 3;
                             }
                         }
                         // Check if this is a new argument
                         if (1 === $levels['('] && ',' === $token) {
                             $properties['args'][] = $current_arg;
                             $current_arg = '';
                             break;
                         }
                         $current_arg .= $token_contents;
                 }
                 break;
         }
     }
     if (!empty($current_arg)) {
         $properties['args'][] .= $current_arg;
     }
     $parser = new TokenParser();
     foreach ($properties['args'] as $arg) {
         if (!empty($properties['path'])) {
             $parser->add_to_path($properties['path']);
         }
         $parser->line = $this->line;
         foreach ($parser->parse_contents("<?php {$arg}") as $element) {
             $this->elements[] = $element;
         }
         $this->line = $parser->line;
         $parser->reset();
     }
     return $properties;
 }