[ Index ] |
|
Code source de Symfony 1.0.0 |
1 <?php 2 require_once 'phing/Task.php'; 3 4 /** 5 * ZendCodeAnalyzerTask analyze PHP source code using the ZendCodeAnalyzer included in Zend Studio 5.1 6 * 7 * Available warnings: 8 * <b>zend-error</b> - %s(line %d): %s 9 * <b>oneline-comment</b> - One-line comment ends with ?> tag. 10 * <b>bool-assign</b> - Assignment seen where boolean expression is expected. Did you mean '==' instead of '='? 11 * <b>bool-print</b> - Print statement used when boolean expression is expected. 12 * <b>bool-array</b> - Array used when boolean expression is expected. 13 * <b>bool-object</b> - Object used when boolean expression is expected. 14 * <b>call-time-ref</b> - Call-time reference is deprecated. Define function as accepting parameter by reference instead. 15 * <b>if-if-else</b> - In if-if-else construction else relates to the closest if. Use braces to make the code clearer. 16 * <b>define-params</b> - define() requires two or three parameters. 17 * <b>define-const</b> - First parameter for define() should be string. Maybe you forgot quotes? 18 * <b>break-var</b> - Break/continue with variable is dangerous - break level can be out of scope. 19 * <b>break-depth</b> - Break/continue with depth more than current nesting level. 20 * <b>var-once</b> - Variable '%s' encountered only once. May be a typo? 21 * <b>var-arg-unused</b> - Function argument '%s' is never used. 22 * <b>var-global-unused</b> - Global variable '%s' is defined but never used. 23 * <b>var-use-before-def</b> - Variable '%s' is used before it was assigned. 24 * <b>var-use-before-def-global</b> - Global variable '%s' is used without being assigned. You are probably relying on register_globals feature of PHP. Note that this feature is off by default. 25 * <b>var-no-global</b> - PHP global variable '%s' is used as local. Maybe you wanted to define '%s' as global? 26 * <b>var-value-unused</b> - Value assigned to variable '%s' is never used 27 * <b>var-ref-notmodified</b> - Function parameter '%s' is passed by reference but never modified. Consider passing by value. 28 * <b>return-empty-val</b> - Function '%s' has both empty return and return with value. 29 * <b>return-empty-used</b> - Function '%s' has empty return but return value is used. 30 * <b>return-noref</b> - Function '%s' returns reference but the value is not assigned by reference. Maybe you meant '=&' instead of '='? 31 * <b>return-end-used</b> - Control reaches the end of function '%s'(file %s, line %d) but return value is used. 32 * <b>sprintf-miss-args</b> - Missing arguments for sprintf: format reqires %d arguments but %d are supplied. 33 * <b>sprintf-extra-args</b> - Extra arguments for sprintf: format reqires %d arguments but %d are supplied. 34 * <b>unreach-code</b> - Unreachable code in function '%s'. 35 * <b>include-var</b> - include/require with user-accessible variable can be dangerous. Consider using constant instead. 36 * <b>non-object</b> - Variable '%s' used as object, but has different type. 37 * <b>bad-escape</b> - Bad escape sequence: \%c, did you mean \\%c? 38 * <b>empty-cond</b> - Condition without a body 39 * <b>expr-unused</b> - Expression result is never used 40 * 41 * @author Knut Urdalen <knut.urdalen@telio.no> 42 * @package phing.tasks.ext 43 */ 44 class ZendCodeAnalyzerTask extends Task { 45 46 protected $analyzerPath = ""; // Path to ZendCodeAnalyzer binary 47 protected $file = ""; // the source file (from xml attribute) 48 protected $filesets = array(); // all fileset objects assigned to this task 49 protected $warnings = array(); 50 protected $counter = 0; 51 protected $disable = array(); 52 protected $enable = array(); 53 54 /** 55 * File to be analyzed 56 * 57 * @param PhingFile $file 58 */ 59 public function setFile(PhingFile $file) { 60 $this->file = $file; 61 } 62 63 /** 64 * Path to ZendCodeAnalyzer binary 65 * 66 * @param string $analyzerPath 67 */ 68 public function setAnalyzerPath($analyzerPath) { 69 $this->analyzerPath = $analyzerPath; 70 } 71 72 /** 73 * Disable warning levels. Seperate warning levels with ',' 74 * 75 * @param string $disable 76 */ 77 public function setDisable($disable) { 78 $this->disable = explode(",", $disable); 79 } 80 81 /** 82 * Enable warning levels. Seperate warning levels with ',' 83 * 84 * @param string $enable 85 */ 86 public function setEnable($enable) { 87 $this->enable = explode(",", $enable); 88 } 89 90 /** 91 * Nested creator, creates a FileSet for this task 92 * 93 * @return FileSet The created fileset object 94 */ 95 function createFileSet() { 96 $num = array_push($this->filesets, new FileSet()); 97 return $this->filesets[$num-1]; 98 } 99 100 /** 101 * Analyze against PhingFile or a FileSet 102 */ 103 public function main() { 104 if(!isset($this->analyzerPath)) { 105 throw new BuildException("Missing attribute 'analyzerPath'"); 106 } 107 if(!isset($this->file) and count($this->filesets) == 0) { 108 throw new BuildException("Missing either a nested fileset or attribute 'file' set"); 109 } 110 111 if($this->file instanceof PhingFile) { 112 $this->analyze($this->file->getPath()); 113 } else { // process filesets 114 $project = $this->getProject(); 115 foreach($this->filesets as $fs) { 116 $ds = $fs->getDirectoryScanner($project); 117 $files = $ds->getIncludedFiles(); 118 $dir = $fs->getDir($this->project)->getPath(); 119 foreach($files as $file) { 120 $this->analyze($dir.DIRECTORY_SEPARATOR.$file); 121 } 122 } 123 } 124 $this->log("Number of findings: ".$this->counter, PROJECT_MSG_INFO); 125 } 126 127 /** 128 * Analyze file 129 * 130 * @param string $file 131 * @return void 132 */ 133 protected function analyze($file) { 134 if(file_exists($file)) { 135 if(is_readable($file)) { 136 137 // Construct shell command 138 $cmd = $this->analyzerPath." "; 139 foreach($this->enable as $enable) { // Enable warning levels 140 $cmd .= " --enable $enable "; 141 } 142 foreach($this->disable as $disable) { // Disable warning levels 143 $cmd .= " --disable $disable "; 144 } 145 $cmd .= "$file 2>&1"; 146 147 // Execute command 148 $result = shell_exec($cmd); 149 $result = explode("\n", $result); 150 for($i=2, $size=count($result); $i<($size-1); $i++) { 151 $this->counter++; 152 $this->log($result[$i], PROJECT_MSG_WARN); 153 } 154 } else { 155 throw new BuildException('Permission denied: '.$file); 156 } 157 } else { 158 throw new BuildException('File not found: '.$file); 159 } 160 } 161 } 162 163 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Fri Mar 16 22:42:14 2007 | par Balluche grâce à PHPXref 0.7 |