Changeset 374
- Timestamp:
- 05/29/08 05:06:14 (7 months ago)
- Files:
-
- branches/2.4/classes/phing/tasks/ext/PhpCodeSnifferTask.php (modified) (6 diffs)
- branches/2.4/docs/phing_guide/book/chapters/appendixes/AppendixC-OptionalTasks.html (modified) (4 diffs, 1 prop)
- branches/2.4/docs/phing_guide/book/chapters/appendixes/AppendixD-CoreTypes.html (modified) (1 prop)
- branches/2.4/docs/phing_guide/book/chapters/appendixes/AppendixE-ProjectComponents.html (modified) (1 prop)
- branches/2.4/docs/phing_guide/book/chapters/appendixes/AppendixF-FileFormats.html (modified) (1 prop)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branches/2.4/classes/phing/tasks/ext/PhpCodeSnifferTask.php
r347 r374 47 47 protected $showSniffs = false; 48 48 protected $outputFormat = 'default'; 49 protected $formatters = array(); 49 50 50 51 /** … … 184 185 } 185 186 187 /** 188 * Create object for nested formatter element. 189 * @return CodeSniffer_FormatterElement 190 */ 191 public function createFormatter () { 192 $num = array_push($this->formatters, 193 new PhpCodeSnifferTask_FormatterElement()); 194 return $this->formatters[$num-1]; 195 } 196 186 197 /** 187 198 * Executes PHP code sniffer against PhingFile or a FileSet … … 190 201 if(!isset($this->file) and count($this->filesets) == 0) { 191 202 throw new BuildException("Missing either a nested fileset or attribute 'file' set"); 192 } 203 } 204 205 if (count($this->formatters) == 0) { 206 // turn legacy outputFormat attribute into formatter 207 $fmt = new CodeSniffer_FormatterElement(); 208 $fmt->setType($this->outputFormat); 209 $fmt->setUseFile(false); 210 $this->formatters[] = $fmt; 211 } 193 212 194 213 require_once 'PHP/CodeSniffer.php'; … … 213 232 $fileList[] = $dir.DIRECTORY_SEPARATOR.$file; 214 233 } 215 }234 } 216 235 $codeSniffer->process($fileList, $this->standard, $this->sniffs, $this->noSubdirectories); 217 } 236 } 237 218 238 $this->output($codeSniffer); 219 239 } … … 231 251 } 232 252 $this->log('The list of used sniffs (#' . count($sniffs) . '): ' . PHP_EOL . $sniffStr, Project::MSG_INFO); 233 } 234 235 switch ($this->outputFormat) { 236 case 'default': 237 $this->outputCustomFormat($codeSniffer); 238 break; 239 case 'xml': 240 $codeSniffer->printXMLErrorReport($this->showWarnings); 241 break; 242 case 'checkstyle': 243 $codeSniffer->printCheckstyleErrorReport($this->showWarnings); 244 break; 245 case 'csv': 246 $codeSniffer->printCSVErrorReport($this->showWarnings); 247 break; 248 case 'report': 249 $codeSniffer->printErrorReport($this->showWarnings); 250 break; 251 case 'summary': 252 $codeSniffer->printErrorReportSummary($this->showWarnings); 253 break; 254 case 'doc': 255 $codeSniffer->generateDocs($this->standard, $this->sniffs); 256 break; 257 default: 258 $this->log('Unknown output format "' . $this->outputFormat . '"', Project::MSG_INFO); 259 break; 260 } 261 } 253 } 254 255 // process output 256 foreach ($this->formatters as $fe) { 257 $output = ''; 258 259 switch ($fe->getType()) { 260 case 'default': 261 // default format goes to logs, no buffering 262 $this->outputCustomFormat($codeSniffer); 263 $fe->setUseFile(false); 264 break; 265 266 case 'xml': 267 ob_start(); 268 $codeSniffer->printXMLErrorReport($this->showWarnings); 269 $output = ob_get_contents(); 270 ob_end_clean(); 271 break; 272 273 case 'checkstyle': 274 ob_start(); 275 $codeSniffer->printCheckstyleErrorReport($this->showWarnings); 276 $output = ob_get_contents(); 277 ob_end_clean(); 278 break; 279 280 case 'csv': 281 ob_start(); 282 $codeSniffer->printCSVErrorReport($this->showWarnings); 283 $output = ob_get_contents(); 284 ob_end_clean(); 285 break; 286 287 case 'report': 288 ob_start(); 289 $codeSniffer->printErrorReport($this->showWarnings); 290 $output = ob_get_contents(); 291 ob_end_clean(); 292 break; 293 294 case 'summary': 295 ob_start(); 296 $codeSniffer->printErrorReportSummary($this->showWarnings); 297 $output = ob_get_contents(); 298 ob_end_clean(); 299 break; 300 301 case 'doc': 302 ob_start(); 303 $codeSniffer->generateDocs($this->standard, $this->sniffs); 304 $output = ob_get_contents(); 305 ob_end_clean(); 306 break; 307 308 default: 309 $this->log('Unknown output format "' . $fe->getType() . '"', Project::MSG_INFO); 310 continue; //skip to next formatter in list 311 break; 312 } //end switch 313 314 if (!$fe->getUseFile()) { 315 // output raw to console 316 echo $output; 317 318 } else { 319 // write to file 320 $outputFile = $fe->getOutfile(); 321 $check = file_put_contents($outputFile, $output); 322 if (is_bool($check) && !$check) { 323 throw new BuildException('Error writing output to ' . $outputFile); 324 } 325 } 326 } //end foreach 327 } //end output 262 328 263 329 /** … … 324 390 } 325 391 326 } 392 } //end phpCodeSnifferTask 393 394 class PhpCodeSnifferTask_FormatterElement extends DataType { 395 396 /** 397 * Type of output to generate 398 * @var string 399 */ 400 protected $type = ""; 401 402 /** 403 * Output to file? 404 * @var bool 405 */ 406 protected $useFile = true; 407 408 /** 409 * Output file. 410 * @var string 411 */ 412 protected $outfile = ""; 413 414 /** 415 * Validate config. 416 */ 417 public function parsingComplete () { 418 if(empty($this->type)) { 419 throw new BuildException("Format missing required 'type' attribute."); 420 } 421 if ($useFile && empty($this->outfile)) { 422 throw new BuildException("Format requres 'outfile' attribute when 'useFile' is true."); 423 } 424 425 } 426 427 public function setType ($type) { 428 $this->type = $type; 429 } 430 431 public function getType () { 432 return $this->type; 433 } 434 435 public function setUseFile ($useFile) { 436 $this->useFile = $useFile; 437 } 438 439 public function getUseFile () { 440 return $this->useFile; 441 } 442 443 public function setOutfile ($outfile) { 444 $this->outfile = $outfile; 445 } 446 447 public function getOutfile () { 448 return $this->outfile; 449 } 450 451 } //end FormatterElement branches/2.4/docs/phing_guide/book/chapters/appendixes/AppendixC-OptionalTasks.html
- Property svn:executable deleted
r352 r374 883 883 <td>The output format. The <em>default</em> format is specified in the task itself. Additionally the formats of CodeSniffer can be choosen: <em>xml</em>, <em>checkstyle</em>, <em>csv</em>, <em>report</em> and <em>summary</em>. A special case is the format <em>doc</em> which generates the documentation of the standard.</td> 884 884 <td>default</td> 885 <td>No< /td>885 <td>No<br/>Ignored if nested <em>formatter</em> elements are supplied.</td> 886 886 </tr> 887 887 <tr> … … 986 986 </table> 987 987 </li> 988 <li>formatter 989 <p>The results of the tests can be printed in different formats. Output will always be sent to a file, unless you set the <em>usefile</em> attribute to <em>false.</em></p> 990 <h3>Attributes</h3> 991 <table> 992 <thead> 993 <tr> 994 <th>Name</th> 995 <th>Type</th> 996 <th>Description</th> 997 <th>Default</th> 998 <th>Required</th> 999 </tr> 1000 </thead> 1001 <tbody> 1002 <tr> 1003 <td>type</td> 1004 <td>String</td> 1005 <td>The output format. Accepts the the same values as the <em>outputFormat</em> attribute (<em>default</em>, <em>xml</em>, <em>checkstyle</em>, <em>csv</em>, <em>report</em>, <em>summary</em> & <em>doc</em>).</td> 1006 <td>n/a</td> 1007 <td>Yes</td> 1008 </tr> 1009 <tr> 1010 <td>usefile</td> 1011 <td>Boolean</td> 1012 <td>Boolean that determines whether output should be sent to a file.</td> 1013 <td>true</td> 1014 <td>No</td> 1015 </tr> 1016 <tr> 1017 <td>outfile</td> 1018 <td>String</td> 1019 <td>Path to write output file to.</td> 1020 <td>n/a</td> 1021 <td>Yes, if <em>usefile</em> is <em>true</em>.</td> 1022 </tr> 1023 </tbody> 1024 </table> 1025 </li> 988 1026 </ul> 989 1027 <h3>Examples</h3> … … 996 1034 </phpcodesniffer> 997 1035 </pre> 998 <p>Checks all matching files in the directory <em>dir</em> with a custom external standard, sets the <em>zend_ca_path</em> configuration which may be required by one of the sniffs, prints a list of used sniffs and prints the <em>default</em> report with warnings .</p>1036 <p>Checks all matching files in the directory <em>dir</em> with a custom external standard, sets the <em>zend_ca_path</em> configuration which may be required by one of the sniffs, prints a list of used sniffs and prints the <em>default</em> report with warnings and the <em>checkstyle</em> report to <em>/path/to/checkstyle.xml</em>.</p> 999 1037 <pre><phpunit 1000 1038 standard="/path/to/external-standard" … … 1004 1042 <include name="**/*.php"/> 1005 1043 </fileset> 1006 <config name="zend_ca_path" value="/path/to/ZendStudio/bin/ZendCodeAnalyzer"> 1044 <config name="zend_ca_path" value="/path/to/ZendStudio/bin/ZendCodeAnalyzer"/> 1045 <formatter type="default" usefile="false"/> 1046 <formatter type="checkstyle" outfile="/path/to/checkstyle.xml"/> 1007 1047 </phpunit> 1008 1048 </pre> branches/2.4/docs/phing_guide/book/chapters/appendixes/AppendixD-CoreTypes.html
- Property svn:executable deleted
branches/2.4/docs/phing_guide/book/chapters/appendixes/AppendixE-ProjectComponents.html
- Property svn:executable deleted
branches/2.4/docs/phing_guide/book/chapters/appendixes/AppendixF-FileFormats.html
- Property svn:executable deleted
