classes/CodeReview/PhpFileParser.php
private function computeNestingParentTokens($debug = false) {
		$nesting = 0;
		$parents = array();
		$lastParent = null;
		foreach ($this->tokens as $key => $token) {
			if (is_array($token)) {
				//add info about parent to array
				$parent = $parents ? $parents[count($parents)-1] : null;
				$this->tokens[$key][3] = $parent;
				$this->tokens[$key][4] = $nesting;

				//is current token possible parent in current level?
				if ($this->isEqualToAnyToken(array(T_CLASS, T_INTERFACE, T_FUNCTION), $key)) {
					$lastParent = $key + 2;
				} elseif ($this->isEqualToAnyToken(array(T_CURLY_OPEN, T_DOLLAR_OPEN_CURLY_BRACES), $key)) {
					$nesting++;
					array_push($parents, '');//just a placeholder
					if ($debug) {
						echo "$nesting\{\$\n";
					}
				}
			} else {
				if ($token == '{') {
					$nesting++;
					if ($debug) {
						echo "$nesting{\n";
					}
					array_push($parents, $lastParent);
				} elseif ($token == '}') {
					if ($debug) {
						echo "$nesting}\n";
					}
					$nesting--;
					array_pop($parents);
				}
			}
		}
	}
private function computeNestingParentTokens($debug = false) {
		$nesting = 0;
		$parents = array();
		$lastParent = null;
		foreach ($this->tokens as $key => $token) {
			if (is_array($token)) {
				//add info about parent to array
				$parent = $parents ? $parents[count($parents)-1] : null;
				$this->tokens[$key][3] = $parent;
				$this->tokens[$key][4] = $nesting;

				//is current token possible parent in current level?
				if ($this->isEqualToAnyToken(array(T_CLASS, T_INTERFACE, T_FUNCTION), $key)) {
					$lastParent = $key + 2;
				} elseif ($this->isEqualToAnyToken(array(T_CURLY_OPEN, T_DOLLAR_OPEN_CURLY_BRACES), $key)) {
					$nesting++;
					array_push($parents, '');//just a placeholder
					if ($debug) {
						echo "$nesting\{\$\n";
					}
				}
			} else {
				if ($token == '{') {
					$nesting++;
					if ($debug) {
						echo "$nesting{\n";
					}
					array_push($parents, $lastParent);
				} elseif ($token == '}') {
					if ($debug) {
						echo "$nesting}\n";
					}
					$nesting--;
					array_pop($parents);
				}
			}
		}
	}
private function computeNestingParentTokens ( $ debug = false ) { $ nesting = 0 ; $ parents = array ( ) ; $ lastParent = null ; foreach ( $ this -> tokens as $ key => $ token ) { if ( is_array ( $ token ) ) { //add info about parent to array $ parent = $ parents ? $ parents [ count ( $ parents ) - 1 ] : null ; $ this -> tokens [ $ key ] [ 3 ] = $ parent ; $ this -> tokens [ $ key ] [ 4 ] = $ nesting ; //is current token possible parent in current level? if ( $ this -> isEqualToAnyToken ( array ( T_CLASS , T_INTERFACE , T_FUNCTION ) , $ key ) ) { $ lastParent = $ key + 2 ; } elseif ( $ this -> isEqualToAnyToken ( array ( T_CURLY_OPEN , T_DOLLAR_OPEN_CURLY_BRACES ) , $ key ) ) { $ nesting ++ ; array_push ( $ parents , '' ) ; //just a placeholder if ( $ debug ) { echo "$nesting\{\$\n" ; } } } else { if ( $ token == '{' ) { $ nesting ++ ; if ( $ debug ) { echo "$nesting{\n" ; } array_push ( $ parents , $ lastParent ) ; } elseif ( $ token == '}' ) { if ( $ debug ) { echo "$nesting}\n" ; } $ nesting -- ; array_pop ( $ parents ) ; } } } }
Compute parents of the tokens to easily determine containing methods and classes.

@param bool $debug
Compute parents of the tokens to easily determine containing methods and classes .