classes/CodeReview/Analyzer.php
public function processFile($filePath, $functions) {
		$result = array(
			'problems' => array(),
			'fixes' => array(),
		);
		$phpTokens = new PhpFileParser($filePath);
		$changes = 0;
		foreach ($phpTokens as $key => $row) {
			// get non trivial tokens
			if (is_array($row)) {
				list($token, $functionName, $lineNumber) = $row;
				$originalFunctionName = $functionName;

				// prepare normalized version of function name for matching
				$functionName = strtolower($functionName);

				// check for function call
				if ($token == T_STRING
					&& !$phpTokens->isEqualToToken(T_OBJECT_OPERATOR, $key-1) //not method
					&& !$phpTokens->isEqualToToken(T_DOUBLE_COLON, $key-1) //not static method
					&& !$phpTokens->isEqualToToken(T_FUNCTION, $key-2) //not definition
				) {
					// mark function as called
					if (function_exists($functionName) && !in_array($functionName, $this->calledFunctions)) {
						$this->calledFunctions[] = $functionName;
					}
					// is it function we're looking for
					if (isset($functions[$functionName])) {
						$definingFunctionName = $phpTokens->getDefiningFunctionName($key);

						//we're skipping deprecated calls that are in deprecated function itself
						if (!$definingFunctionName || !isset($functions[strtolower($definingFunctionName)])) {
							$result['problems'][] = array($functions[$functionName], $originalFunctionName, $lineNumber);
						}

						//do instant replacement
						if ($this->fixProblems && isset($this->instantReplacements[$functionName])) {
							$phpTokens[$key] = array(T_STRING, $this->instantReplacements[$functionName]);
							$result['fixes'][] = array($originalFunctionName, $this->instantReplacements[$functionName], $lineNumber);
							$changes++;
						}
					}
				}
			}
		}
		if ($changes) {
			try {
				$phpTokens->exportPhp($filePath);
			} catch (\CodeReview\IOException $e) {
				echo '*** Error: ' . $e->getMessage() . " ***\n";
			}
		}
		unset($phpTokens);
		return $result;
	}
public function processFile($filePath, $functions) {
		$result = array(
			'problems' => array(),
			'fixes' => array(),
		);
		$phpTokens = new PhpFileParser($filePath);
		$changes = 0;
		foreach ($phpTokens as $key => $row) {
			// get non trivial tokens
			if (is_array($row)) {
				list($token, $functionName, $lineNumber) = $row;
				$originalFunctionName = $functionName;

				// prepare normalized version of function name for matching
				$functionName = strtolower($functionName);

				// check for function call
				if ($token == T_STRING
					&& !$phpTokens->isEqualToToken(T_OBJECT_OPERATOR, $key-1) //not method
					&& !$phpTokens->isEqualToToken(T_DOUBLE_COLON, $key-1) //not static method
					&& !$phpTokens->isEqualToToken(T_FUNCTION, $key-2) //not definition
				) {
					// mark function as called
					if (function_exists($functionName) && !in_array($functionName, $this->calledFunctions)) {
						$this->calledFunctions[] = $functionName;
					}
					// is it function we're looking for
					if (isset($functions[$functionName])) {
						$definingFunctionName = $phpTokens->getDefiningFunctionName($key);

						//we're skipping deprecated calls that are in deprecated function itself
						if (!$definingFunctionName || !isset($functions[strtolower($definingFunctionName)])) {
							$result['problems'][] = array($functions[$functionName], $originalFunctionName, $lineNumber);
						}

						//do instant replacement
						if ($this->fixProblems && isset($this->instantReplacements[$functionName])) {
							$phpTokens[$key] = array(T_STRING, $this->instantReplacements[$functionName]);
							$result['fixes'][] = array($originalFunctionName, $this->instantReplacements[$functionName], $lineNumber);
							$changes++;
						}
					}
				}
			}
		}
		if ($changes) {
			try {
				$phpTokens->exportPhp($filePath);
			} catch (\CodeReview\IOException $e) {
				echo '*** Error: ' . $e->getMessage() . " ***\n";
			}
		}
		unset($phpTokens);
		return $result;
	}
public function processFile ( $ filePath , $ functions ) { $ result = array ( 'problems' => array ( ) , 'fixes' => array ( ) , ) ; $ phpTokens = new PhpFileParser ( $ filePath ) ; $ changes = 0 ; foreach ( $ phpTokens as $ key => $ row ) { // get non trivial tokens if ( is_array ( $ row ) ) { list ( $ token , $ functionName , $ lineNumber ) = $ row ; $ originalFunctionName = $ functionName ; // prepare normalized version of function name for matching $ functionName = strtolower ( $ functionName ) ; // check for function call if ( $ token == T_STRING && ! $ phpTokens -> isEqualToToken ( T_OBJECT_OPERATOR , $ key - 1 ) //not method && ! $ phpTokens -> isEqualToToken ( T_DOUBLE_COLON , $ key - 1 ) //not static method && ! $ phpTokens -> isEqualToToken ( T_FUNCTION , $ key - 2 ) //not definition ) { // mark function as called if ( function_exists ( $ functionName ) && ! in_array ( $ functionName , $ this -> calledFunctions ) ) { $ this -> calledFunctions [ ] = $ functionName ; } // is it function we're looking for if ( isset ( $ functions [ $ functionName ] ) ) { $ definingFunctionName = $ phpTokens -> getDefiningFunctionName ( $ key ) ; //we're skipping deprecated calls that are in deprecated function itself if ( ! $ definingFunctionName || ! isset ( $ functions [ strtolower ( $ definingFunctionName ) ] ) ) { $ result [ 'problems' ] [ ] = array ( $ functions [ $ functionName ] , $ originalFunctionName , $ lineNumber ) ; } //do instant replacement if ( $ this -> fixProblems && isset ( $ this -> instantReplacements [ $ functionName ] ) ) { $ phpTokens [ $ key ] = array ( T_STRING , $ this -> instantReplacements [ $ functionName ] ) ; $ result [ 'fixes' ] [ ] = array ( $ originalFunctionName , $ this -> instantReplacements [ $ functionName ] , $ lineNumber ) ; $ changes ++ ; } } } } } if ( $ changes ) { try { $ phpTokens -> exportPhp ( $ filePath ) ; } catch ( \ CodeReview \ IOException $ e ) { echo '*** Error: ' . $ e -> getMessage ( ) . " ***\n" ; } } unset ( $ phpTokens ) ; return $ result ; }
Find function calls and extract

@param string $filePath
@param array $functions
@return array
Find function calls and extract