当前位置: 首页>>代码示例>>PHP>>正文


PHP PHP_CodeSniffer_Reporting::prepare方法代码示例

本文整理汇总了PHP中PHP_CodeSniffer_Reporting::prepare方法的典型用法代码示例。如果您正苦于以下问题:PHP PHP_CodeSniffer_Reporting::prepare方法的具体用法?PHP PHP_CodeSniffer_Reporting::prepare怎么用?PHP PHP_CodeSniffer_Reporting::prepare使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在PHP_CodeSniffer_Reporting的用法示例。


在下文中一共展示了PHP_CodeSniffer_Reporting::prepare方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: testPrepare

 /**
  * Test prepare report method.
  * 
  * @return void
  */
 public function testPrepare()
 {
     $fixtureFilesViolations = $this->getFixtureFilesViolations();
     $reports = $this->reporting->prepare($fixtureFilesViolations);
     $this->assertArrayHasKey('files', $reports);
     $this->assertEquals(3, count($reports['files']));
     $this->assertArrayHasKey('foo', $reports['files']);
     $this->assertArrayHasKey('errors', $reports['files']['foo']);
     $this->assertEquals(4, $reports['files']['foo']['errors']);
     $this->assertArrayHasKey('warnings', $reports['files']['foo']);
     $this->assertEquals(2, $reports['files']['foo']['warnings']);
     // Two errors on line 1 column 10.
     $this->assertArrayHasKey('messages', $reports['files']['foo']);
     $fooMessages = $reports['files']['foo']['messages'];
     $this->assertArrayHasKey(1, $fooMessages, 'messages on line 1');
     $this->assertArrayHasKey(10, $fooMessages[1], 'messages on line 1 column 10');
     $this->assertEquals(2, count($fooMessages[1][10]), '2 messages on line 1 column 10');
     // One error one warning on line 10 column 1.
     $this->assertArrayHasKey(10, $fooMessages, 'messages on line 10');
     $this->assertArrayHasKey(1, $fooMessages[10], 'messages on line 10 column 1');
     $this->assertEquals(2, count($fooMessages[10][1]), '2 messages on line 10 column 1');
     // Empty file has structure without data.
     $this->assertArrayHasKey('baz', $reports['files']);
     $this->assertArrayHasKey('messages', $reports['files']['baz']);
     $this->assertEquals(0, count($reports['files']['baz']['messages']));
     // Totals.
     $this->assertArrayHasKey('totals', $reports, 'report totals exist');
     $this->assertArrayHasKey('errors', $reports['totals'], 'errors total exists');
     $this->assertEquals(8, $reports['totals']['errors'], 'errors total is well calculated');
     $this->assertArrayHasKey('warnings', $reports['totals'], 'warnings total exists');
     $this->assertEquals(2, $reports['totals']['warnings'], 'warnings total is well calculated');
     // Files Order.
     reset($reports['files']);
     $this->assertEquals('bar', key($reports['files']), 'report files ordered by name');
     next($reports['files']);
     $this->assertEquals('baz', key($reports['files']), 'report files ordered by name');
     // Violations Order.
     reset($fooMessages);
     $this->assertEquals(1, key($fooMessages), 'line level violations order');
     next($fooMessages);
     $this->assertEquals(5, key($fooMessages), 'line level violations order');
     reset($fooMessages[1]);
     $this->assertEquals(1, key($fooMessages[1]), 'column level violations order');
     next($fooMessages[1]);
     $this->assertEquals(10, key($fooMessages[1]), 'column level violations order');
 }
开发者ID:resid,项目名称:PHP_CodeSniffer,代码行数:51,代码来源:ReportingTest.php

示例2: printErrorReport

 /**
  * Prints the error report.
  *
  * @param PHP_CodeSniffer $phpcs The PHP_CodeSniffer object containing
  *                               the errors.
  *
  * @return int The number of error and warning messages shown.
  */
 protected function printErrorReport($phpcs)
 {
     if ($this->showSniffs) {
         $sniffs = $phpcs->getSniffs();
         $sniffStr = '';
         foreach ($sniffs as $sniff) {
             $sniffStr .= '- ' . $sniff . PHP_EOL;
         }
         $this->log('The list of used sniffs (#' . count($sniffs) . '): ' . PHP_EOL . $sniffStr, Project::MSG_INFO);
     }
     $filesViolations = $phpcs->getFilesErrors();
     $reporting = new PHP_CodeSniffer_Reporting();
     $report = $reporting->prepare($filesViolations, $this->showWarnings);
     // process output
     foreach ($this->formatters as $fe) {
         switch ($fe->getType()) {
             case 'default':
                 // default format goes to logs, no buffering
                 $this->outputCustomFormat($report);
                 $fe->setUseFile(false);
                 break;
             default:
                 $reportFile = '';
                 if ($fe->getUseFile()) {
                     $reportFile = $fe->getOutfile()->getPath();
                     ob_start();
                 }
                 $reporting->printReport($fe->getType(), $filesViolations, $this->showWarnings, $this->showSources, $reportFile, $this->reportWidth);
                 // reporting class uses ob_end_flush(), but we don't want
                 // an output if we use a file
                 if ($fe->getUseFile()) {
                     ob_end_clean();
                 }
                 break;
         }
     }
     return $report;
 }
开发者ID:RadioCampusFrance,项目名称:airtime,代码行数:46,代码来源:PhpCodeSnifferTask.php

示例3: printErrorReport

 /**
  * Prints the error report.
  *
  * @param PHP_CodeSniffer $phpcs The PHP_CodeSniffer object containing
  *                               the errors.
  *
  * @return int The number of error and warning messages shown.
  */
 protected function printErrorReport($phpcs)
 {
     if ($this->showSniffs) {
         $sniffs = $phpcs->getSniffs();
         $sniffStr = '';
         foreach ($sniffs as $sniff) {
             $sniffStr .= '- ' . $sniff . PHP_EOL;
         }
         $this->log('The list of used sniffs (#' . count($sniffs) . '): ' . PHP_EOL . $sniffStr, Project::MSG_INFO);
     }
     $filesViolations = $phpcs->getFilesErrors();
     $reporting = new PHP_CodeSniffer_Reporting();
     $report = $reporting->prepare($filesViolations, $this->showWarnings);
     // process output
     foreach ($this->formatters as $fe) {
         switch ($fe->getType()) {
             case 'default':
                 // default format goes to logs, no buffering
                 $this->outputCustomFormat($report);
                 $fe->setUseFile(false);
                 break;
             default:
                 $reportFile = null;
                 if ($fe->getUseFile()) {
                     $reportFile = $fe->getOutfile();
                     ob_start();
                 }
                 // Determine number of parameters required to
                 // ensure backwards compatibility
                 $rm = new ReflectionMethod('PHP_CodeSniffer_Reporting', 'printReport');
                 if ($rm->getNumberOfParameters() == 5) {
                     $reporting->printReport($fe->getType(), $filesViolations, $this->showSources, $reportFile, $this->reportWidth);
                 } else {
                     $reporting->printReport($fe->getType(), $filesViolations, $this->showWarnings, $this->showSources, $reportFile, $this->reportWidth);
                 }
                 // reporting class uses ob_end_flush(), but we don't want
                 // an output if we use a file
                 if ($fe->getUseFile()) {
                     ob_end_clean();
                 }
                 break;
         }
     }
     return $report;
 }
开发者ID:altesien,项目名称:FinalProject,代码行数:53,代码来源:PhpCodeSnifferTask.php

示例4: execute

 /**
  * Execute the task
  *
  * @return self
  * @throw BuildException
  */
 public function execute()
 {
     if (!$this->getStandard()) {
         throw new BuildException("No standard set");
     }
     if (!class_exists("CodeSniffer")) {
         Pale::run(function () {
             require_once "PHP/CodeSniffer.php";
         });
     }
     if (CodeSniffer::isInstalledStandard($this->getStandard()) === false) {
         throw new BuildException("Invalid standard name");
     }
     // Clear out argv so PHP_CodeSniffer doesn"t freak out
     $oldArgv = $SERVER["argv"];
     $SERVER["argv"] = array();
     $SERVER["argc"] = 0;
     // Get the current working directory because PHP_CodeSniffer will change it
     $cwd = getcwd();
     $codeSniffer = new CodeSniffer(0, 0, "UTF-8");
     $codeSniffer->process($this->getFiles(), $this->filterProperties($this->getStandard()));
     // Restore the argv/c superglobals
     $SERVER["argv"] = $oldArgv;
     $SERVER["argc"] = count($oldArgv);
     // Reset the current working directory
     chdir($cwd);
     $filesViolations = $codeSniffer->getFilesErrors();
     $reporting = new Reporting();
     $report = $reporting->prepare($filesViolations, $this->getShowWarnings());
     $reporting->printReport($this->getReportType(), $filesViolations, $this->getShowSources(), $this->getReportFile(), $this->getReportWidth());
     return $this;
 }
开发者ID:toxygene,项目名称:pants,代码行数:38,代码来源:PhpCodeSniffer.php


注:本文中的PHP_CodeSniffer_Reporting::prepare方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。