src/Alg/UnusedVariableFinder.php
private function parseCodeForMethods( $content )
	{
		$this->methods	= array();																	//  reset list of found methods
		$open		= FALSE;																		//  initial: no method found, yet
		$content	= preg_replace( "@/\*.*\*/@Us", "", $content );									//  remove all slash-star-comments
//		$content	= preg_replace( '@".*"@Us', "", $content );										//  remove all strings
		$content	= preg_replace( "@'.*'@Us", "", $content );										//  remove all strings
		$content	= preg_replace( "@#.+\n@U", "", $content );										//  remove all hash-comments
		$content	= preg_replace( "@\s+\n@U", "\n", $content );									//  trailing white space
		$content	= preg_replace( "@\n\n@U", "\n", $content );									//  remove double line breaks
		$content	= preg_replace( "@//\s*[\w|\s]*\n@U", "\n", $content );							//  remove comment lines
		$matches	= array();																		//  prepare empty matches array
		$count		= 0;																			//  initial: open bracket counter
		foreach( explode( "\n", $content ) as $nr => $line )										//  iterate code lines
		{
			$line	= trim( $line );																//  remove leading and trailing white space
			if( !$open )																			//  if no method found, yet
			{
				$regExp	= '@^(abstract )?(final )?(static )?(protected |private |public )?(static )?function ([\w]+)\((.*)\)(\s*{\s*)?;?\s*$@s';	//  prepare regular expression for method/function signature
				if( preg_match( $regExp, $line ) )													//  line is method/function signature
				{
					$regExp	= "@^.*function ([^(]+) ?\((.*)\).*$@i";								//  prepare regular expression for method/function name and parameters
					$name	= preg_replace( $regExp, "\\1@@\\2", $line );							//  find method/function name and parameters
					$parts	= explode( "@@", $name );												//  split name and parameters
					$open	= trim( $parts[0] );															//  note found method/function
					$matches[$open]['variables']	= array();										//  prepare empty method/function parameter list
					$matches[$open]['lines']		= array();										//  prepare empty method/function line list
					$parts[1]	= preg_replace( '@\(.*\)@U', "", $parts[1] );										//  remove all strings
					if( isset( $parts[1] ) && trim( $parts[1] ) )									//  parameters are defined
					{
						$params	= explode( ",", $parts[1] );										//  split parameters
						foreach( $params as $param )												//  iterate parameters
						{
							$regExp		= '@^([a-z0-9_]+ )?&?\$(.+)(\s?=\s?.*)?$@Ui';				//  prepare regular expression for parameter name
							$param		= preg_replace( $regExp, "\\2", trim( $param ) );			//  get clean parameter name
							$matches[$open]['variables'][$param]	= 0;							//  note parameter in method variable list
						}
					}
					if( preg_match( "/\{$/", $line ) )												//  signature line ends with opening bracket
						$count++;																	//  increase open bracket counter
				}
			}
			else																					//  inside method code lines
			{
				$matches[$open]['lines'][$nr]	= $line;											//  note method code line for inspection
				if( preg_match( "/^\{$/", $line ) || preg_match( "/\{$/", $line ) )					//  line contains opening bracket
					$count++;																		//  increase open bracket counter
				else if( preg_match( "/^\}/", $line ) || preg_match( "/\}$/", $line ) )				//  line contains closing bracket
					if( !( --$count ) )																//  decrease open bracket counter and if all open brackets are closed
						$open	= FALSE;															//  leave method code mode
			}
		}
		$this->methods	= $matches;																	//  note all found methods and their variables
	}
private function parseCodeForMethods( $content )
	{
		$this->methods	= array();																	//  reset list of found methods
		$open		= FALSE;																		//  initial: no method found, yet
		$content	= preg_replace( "@/\*.*\*/@Us", "", $content );									//  remove all slash-star-comments
//		$content	= preg_replace( '@".*"@Us', "", $content );										//  remove all strings
		$content	= preg_replace( "@'.*'@Us", "", $content );										//  remove all strings
		$content	= preg_replace( "@#.+\n@U", "", $content );										//  remove all hash-comments
		$content	= preg_replace( "@\s+\n@U", "\n", $content );									//  trailing white space
		$content	= preg_replace( "@\n\n@U", "\n", $content );									//  remove double line breaks
		$content	= preg_replace( "@//\s*[\w|\s]*\n@U", "\n", $content );							//  remove comment lines
		$matches	= array();																		//  prepare empty matches array
		$count		= 0;																			//  initial: open bracket counter
		foreach( explode( "\n", $content ) as $nr => $line )										//  iterate code lines
		{
			$line	= trim( $line );																//  remove leading and trailing white space
			if( !$open )																			//  if no method found, yet
			{
				$regExp	= '@^(abstract )?(final )?(static )?(protected |private |public )?(static )?function ([\w]+)\((.*)\)(\s*{\s*)?;?\s*$@s';	//  prepare regular expression for method/function signature
				if( preg_match( $regExp, $line ) )													//  line is method/function signature
				{
					$regExp	= "@^.*function ([^(]+) ?\((.*)\).*$@i";								//  prepare regular expression for method/function name and parameters
					$name	= preg_replace( $regExp, "\\1@@\\2", $line );							//  find method/function name and parameters
					$parts	= explode( "@@", $name );												//  split name and parameters
					$open	= trim( $parts[0] );															//  note found method/function
					$matches[$open]['variables']	= array();										//  prepare empty method/function parameter list
					$matches[$open]['lines']		= array();										//  prepare empty method/function line list
					$parts[1]	= preg_replace( '@\(.*\)@U', "", $parts[1] );										//  remove all strings
					if( isset( $parts[1] ) && trim( $parts[1] ) )									//  parameters are defined
					{
						$params	= explode( ",", $parts[1] );										//  split parameters
						foreach( $params as $param )												//  iterate parameters
						{
							$regExp		= '@^([a-z0-9_]+ )?&?\$(.+)(\s?=\s?.*)?$@Ui';				//  prepare regular expression for parameter name
							$param		= preg_replace( $regExp, "\\2", trim( $param ) );			//  get clean parameter name
							$matches[$open]['variables'][$param]	= 0;							//  note parameter in method variable list
						}
					}
					if( preg_match( "/\{$/", $line ) )												//  signature line ends with opening bracket
						$count++;																	//  increase open bracket counter
				}
			}
			else																					//  inside method code lines
			{
				$matches[$open]['lines'][$nr]	= $line;											//  note method code line for inspection
				if( preg_match( "/^\{$/", $line ) || preg_match( "/\{$/", $line ) )					//  line contains opening bracket
					$count++;																		//  increase open bracket counter
				else if( preg_match( "/^\}/", $line ) || preg_match( "/\}$/", $line ) )				//  line contains closing bracket
					if( !( --$count ) )																//  decrease open bracket counter and if all open brackets are closed
						$open	= FALSE;															//  leave method code mode
			}
		}
		$this->methods	= $matches;																	//  note all found methods and their variables
	}
private function parseCodeForMethods ( $ content ) { $ this -> methods = array ( ) ; //  reset list of found methods
 $ open = FALSE ; //  initial: no method found, yet
 $ content = preg_replace ( "@/\*.*\*/@Us" , "" , $ content ) ; //  remove all slash-star-comments
 //		$content	= preg_replace( '@".*"@Us', "", $content );										//  remove all strings
 $ content = preg_replace ( "@'.*'@Us" , "" , $ content ) ; //  remove all strings
 $ content = preg_replace ( "@#.+\n@U" , "" , $ content ) ; //  remove all hash-comments
 $ content = preg_replace ( "@\s+\n@U" , "\n" , $ content ) ; //  trailing white space
 $ content = preg_replace ( "@\n\n@U" , "\n" , $ content ) ; //  remove double line breaks
 $ content = preg_replace ( "@//\s*[\w|\s]*\n@U" , "\n" , $ content ) ; //  remove comment lines
 $ matches = array ( ) ; //  prepare empty matches array
 $ count = 0 ; //  initial: open bracket counter
 foreach ( explode ( "\n" , $ content ) as $ nr => $ line ) //  iterate code lines
 { $ line = trim ( $ line ) ; //  remove leading and trailing white space
 if ( ! $ open ) //  if no method found, yet
 { $ regExp = '@^(abstract )?(final )?(static )?(protected |private |public )?(static )?function ([\w]+)\((.*)\)(\s*{\s*)?;?\s*$@s' ; //  prepare regular expression for method/function signature
 if ( preg_match ( $ regExp , $ line ) ) //  line is method/function signature
 { $ regExp = "@^.*function ([^(]+) ?\((.*)\).*$@i" ; //  prepare regular expression for method/function name and parameters
 $ name = preg_replace ( $ regExp , "\\1@@\\2" , $ line ) ; //  find method/function name and parameters
 $ parts = explode ( "@@" , $ name ) ; //  split name and parameters
 $ open = trim ( $ parts [ 0 ] ) ; //  note found method/function
 $ matches [ $ open ] [ 'variables' ] = array ( ) ; //  prepare empty method/function parameter list
 $ matches [ $ open ] [ 'lines' ] = array ( ) ; //  prepare empty method/function line list
 $ parts [ 1 ] = preg_replace ( '@\(.*\)@U' , "" , $ parts [ 1 ] ) ; //  remove all strings
 if ( isset ( $ parts [ 1 ] ) && trim ( $ parts [ 1 ] ) ) //  parameters are defined
 { $ params = explode ( "," , $ parts [ 1 ] ) ; //  split parameters
 foreach ( $ params as $ param ) //  iterate parameters
 { $ regExp = '@^([a-z0-9_]+ )?&?\$(.+)(\s?=\s?.*)?$@Ui' ; //  prepare regular expression for parameter name
 $ param = preg_replace ( $ regExp , "\\2" , trim ( $ param ) ) ; //  get clean parameter name
 $ matches [ $ open ] [ 'variables' ] [ $ param ] = 0 ; //  note parameter in method variable list
 } } if ( preg_match ( "/\{$/" , $ line ) ) //  signature line ends with opening bracket
 $ count ++ ; //  increase open bracket counter
 } } else //  inside method code lines
 { $ matches [ $ open ] [ 'lines' ] [ $ nr ] = $ line ; //  note method code line for inspection
 if ( preg_match ( "/^\{$/" , $ line ) || preg_match ( "/\{$/" , $ line ) ) //  line contains opening bracket
 $ count ++ ; //  increase open bracket counter
 else if ( preg_match ( "/^\}/" , $ line ) || preg_match ( "/\}$/" , $ line ) ) //  line contains closing bracket
 if ( ! ( -- $ count ) ) //  decrease open bracket counter and if all open brackets are closed
 $ open = FALSE ; //  leave method code mode
 } } $ this -> methods = $ matches ; //  note all found methods and their variables
 }
Parse a Class File and collects Methods and their Parameters and Lines.
@access		private
@param		string		$content		PHP code string
@return		void
Parse a Class File and collects Methods and their Parameters and Lines .