Code

Reverted 7503
[gosa.git] / include / functions_test.inc
index 713ba63899fe1e1a093c852c97d345692c5529d3..afb6c84dc7ad0b7bd2f9e4e93e159c5192de3b8c 100644 (file)
@@ -1,7 +1,7 @@
-<?
+<?php
 /*
  * This code is part of GOsa (https://gosa.gonicus.de)
- * Copyright (C) 2003 Cajus Pollmeier
+ * Copyright (C) 2005 Jan Wenzel
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -49,7 +49,7 @@ function cmd_test_functions($path) {
 }
 
 /**
- * Scans files in $path an checks for calls of functions.
+ * Scans files in $path and checks for calls of functions.
  * @param $path Path to search for files in (default: "./")
  * @param $pattern RegEx-Pattern for matching PHP-Files (default: "/.+\.(php[34]?$)|(inc$)/")
  * @param $skip_dirs RegEx-Pattern for directories to ignore (default: ".svn")
@@ -57,16 +57,15 @@ function cmd_test_functions($path) {
  */
 function test_defined_functions($path="",$pattern="",$skip_dirs="") {
   global $debug,$verbose;
+  $verbose= true;
 
-  // Check for empty parameters
+  // Check for empty parameters. If empty, set default.
   if(strlen($path)==0) {
     $path= "./";
   }
-  
   if(strlen($pattern)==0) {
     $pattern= "/.+\.(php[34]?$)|(inc$)/";
   }
-
   if(strlen($skip_dirs)==0) {
     $skip_dirs= ".svn";
   }
@@ -74,8 +73,11 @@ function test_defined_functions($path="",$pattern="",$skip_dirs="") {
   // Create file-list
   $array= read_php_files($path,$pattern,$skip_dirs);
 
+  // Needed arrays
   $functions= array();
-  $user_functions= array();
+  
+  // We need to include our own function here, because PHP seems to lock the current executed function
+  $user_functions= array('test_defined_functions');
   
   // Scan files for used defined functions
   foreach($array as $file) {
@@ -108,7 +110,7 @@ function test_defined_functions($path="",$pattern="",$skip_dirs="") {
 }
 
 /**
- * Scans files in $path an checks for calls of functions that are undefined.
+ * Scans files in $path and checks for calls of functions that are undefined.
  * Edit $debug and $verbose to control output. Default is 'false' for both to disallow
  * console functionality.
  * @param $path Path to search for files in (default: "./")
@@ -198,16 +200,20 @@ function test_functions($path="",$pattern="",$skip_dirs="") {
 }
 
 /**
- * @see
+ * Reads $path for files matching $pattern but not in $skip_dirs.
+ * @param $path Path to search for files in (default: "./")
+ * @param $pattern RegEx-Pattern for matching PHP-Files (default: "/.+\.(php[34]?$)|(inc$)/")
+ * @param $skip_dirs RegEx-Pattern for directories to ignore (default: ".svn")
  * @return array of content from PHP-Files scanned
  */
 function read_php_files($path,$pattern,$skip_dirs) {
+  global $debug,$verbose;
   $result= array();
   
   if(is_file($path)) {
     $file= $path;
-
-    $php_content= "";
+    
+    $php_content="";
     
     // Open Filehandle to process
     $fh= popen("`which php` -w $file", 'r');
@@ -255,6 +261,10 @@ function filter_meta_functions ($function) {
   return $result;
 }
 
+/**
+ * Returns true if $function is a known php-function, false otherwise.
+ * @return true if $function is a known php-function, false otherwise.
+ */
 function check_function($function) {
   $result= false;
   if(is_keyword($function)) {
@@ -267,7 +277,9 @@ function check_function($function) {
   return $result;
 }
 
-/** @return true if $function is meta-function, false otherwise */
+/** Returns true if $function is meta-function, false otherwise.
+ * @return true if $function is meta-function, false otherwise.
+ */
 function is_meta_function($function) {
   $meta_functions= array(
       "print","array","isset","exit","unset",
@@ -276,7 +288,9 @@ function is_meta_function($function) {
   return(in_array($function,$meta_functions));
 }
 
-/** @return true if $param is keyword, false otherwise */
+/** Returns true if $function is keyword, false otherwise.
+ * @return true if $function is keyword, false otherwise.
+ */
 function is_keyword($function) {
   $keywords= array(
      "if","else","elseif","while","do","case",
@@ -286,9 +300,14 @@ function is_keyword($function) {
     "try","catch"
   );
 
-    return(in_array($function,$keywords));
+  return(in_array($function,$keywords));
 }
 
+/**
+ * Returns array of called functions.
+ * @param $string PHP-Code
+ * @return array of called functions.
+ */
 function extract_php_functions($string) {
   // Function names have to be A-z or _ for the first letter
   // plus 0-9, +, - for the following letters
@@ -307,8 +326,9 @@ function extract_php_functions($string) {
   array_shift($result);
 
 
-  // We need to check if "function" is actual a class created by new operator
-  // negative lookbehind isn't possible with php yet
+  // We need to check if "function" is actual a class created by new operator,
+  // but negative lookbehind isn't possible with php yet.
+  // So we must scan the array again and remove the found keys later (not while we're walking through).
   $classes= array();
   foreach($result[0] as $key => $function) {
     $match= array();
@@ -331,9 +351,9 @@ function extract_php_functions($string) {
 }
 
 /**
- * Extracts function-calls in php-code
- * @param $string php-code to extract function calls from
- * @return array of functions called
+ * Extracts function-definitions from php-code
+ * @param $string php-code to extract function definitions from
+ * @return array of functions defined
  */
 function extract_user_functions($string) {
   $rx_name="[A-Za-z_][A-Za-z0-9_+-]*";
@@ -350,7 +370,8 @@ function extract_user_functions($string) {
 }
 
 /**
- * @return php-code without <?php ... markers
+ * Returns php-code without <?php ... markers.
+ * @return php-code without <?php ... markers.
  */
 function get_php_code($string) {
   $array= array();
@@ -368,11 +389,12 @@ function get_php_code($string) {
 }
 
 /**
+ * Removes all double and single quotes strings from sourcecode.
  * Returns 'print ();' for 'print ("hello world!\n");'
  * AND:
- * Returns '$message= sprintf(_()...); for
- *  $message= sprintf(_("Command '%s', specified as POSTREMOVE for plugin '%s' doesn't seem to exist.")...);
- * Note the "doesn't"
+ * Returns '$message= sprintf(_()$foo,$bar); for
+ *  $message= sprintf(_("Command '%s', specified as POSTREMOVE for plugin '%s' doesn't seem to exist.")$foo,$bar);
+ * (Note the "doesn't")
  * @param $string code with strings
  * @return code with strings removed
  */
@@ -424,7 +446,7 @@ function remove_strings($string) {
 }
 
 /** 
- * Iteratively scans directory $dir for files (filenames) matching regular expression $pattern
+ * Scans directory $dir for files (filenames) matching regular expression $pattern
  * @param $dir Initial Directory to start scan
  * @param $pattern Regex-Pattern to match on files to scan
  * @param $skip_dirs Regex-Patten to match on directories to skip
@@ -451,6 +473,9 @@ function list_directory($dir, $pattern, $skip_dirs) {
   return $file_list;
 }
 
+/**
+ * 'Flats' a multi-dimensional array. Keys are newly (incrementally) created by PHP.
+ */
 function array_values_recursive($array) {
   $arrayValues = array();