當前位置: 首頁>>代碼示例>>PHP>>正文


PHP PHP_CodeSniffer_File::getErrors方法代碼示例

本文整理匯總了PHP中PHP_CodeSniffer_File::getErrors方法的典型用法代碼示例。如果您正苦於以下問題:PHP PHP_CodeSniffer_File::getErrors方法的具體用法?PHP PHP_CodeSniffer_File::getErrors怎麽用?PHP PHP_CodeSniffer_File::getErrors使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在PHP_CodeSniffer_File的用法示例。


在下文中一共展示了PHP_CodeSniffer_File::getErrors方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: handlePHPCSErrors

 private function handlePHPCSErrors(File $file, \PHP_CodeSniffer_File $phpcsFile)
 {
     $maxLine = strlen(max(array_keys($phpcsFile->getErrors())));
     $byLine = $this->prepareFileContent($file);
     foreach ($phpcsFile->getErrors() as $lineNumber => $errorsByLine) {
         $message = sprintf("   | Line %{$maxLine}s:%s\n", $lineNumber, $byLine[$lineNumber + 1]);
         foreach ($errorsByLine as $column => $errorsCollection) {
             foreach ($errorsCollection as $error) {
                 $message .= sprintf("   |%{$maxLine}s| Error at column %s: %s\n", '', $column, $error['message']);
             }
         }
         $this->pushError($message);
     }
 }
開發者ID:polishdeveloper,項目名稱:stark,代碼行數:14,代碼來源:PHPCS.php

示例2: cswExecute

 public function cswExecute()
 {
     // PHP_CodeSniffer - silent prepare
     ob_start();
     $this->setTokenListeners($this->cswStandard, array());
     $this->populateCustomRules();
     $this->populateTokenListeners();
     $tlisteners = $this->getTokenSniffs();
     ob_end_clean();
     // PHP_CodeSniffer - silent process each item and collect results
     foreach ($this->cswData as $index => $item) {
         ob_start();
         $pcsFile = new PHP_CodeSniffer_File('', $tlisteners['file'], $this->allowedFileExtensions, $this->ruleset, $this);
         $pcsFile->start($item['code']);
         $this->cswData[$index]['output'] = $this->storeOutput ? ob_get_contents() : 'output disabled';
         ob_end_clean();
         // free some memory
         unset($this->cswData[$index]['code']);
         // prepare full report
         $this->cswData[$index]['messages'] = $this->mergeMessages($pcsFile->getErrors(), $pcsFile->getWarnings(), $item['code_lines']);
         // prepare report for lines
         $this->cswData[$index]['report_for_lines'] = $this->createReportForLines($this->cswData[$index]);
     }
     // return data
     return $this->cswData;
 }
開發者ID:sunnystone85,項目名稱:CsPCHookSugar,代碼行數:26,代碼來源:CsWrapper.php

示例3: gatherErrors

 /**
  * Gather all error messages by line number from phpcs file result
  *
  * @param PHP_CodeSniffer_File $file Codesniffer File object
  * @return array
  */
 public function gatherErrors(PHP_CodeSniffer_File $file)
 {
     $foundErrors = $file->getErrors();
     $allErrors = array();
     foreach ($foundErrors as $line => $lineErrors) {
         foreach ($lineErrors as $column => $errors) {
             foreach ($errors as $error) {
                 if (!isset($allErrors[$line])) {
                     $allErrors[$line] = array();
                 }
                 $allErrors[$line][] = $error;
             }
         }
     }
     return $allErrors;
 }
開發者ID:christopheg,項目名稱:PHPCompatibility,代碼行數:22,代碼來源:BaseSniffTest.php

示例4: generateFailureMessages

 /**
  * Generate a list of test failures for a given sniffed file.
  *
  * @param PHP_CodeSniffer_File $file The file being tested.
  *
  * @return array
  * @throws PHP_CodeSniffer_Exception
  */
 public function generateFailureMessages(PHP_CodeSniffer_File $file)
 {
     $testFile = $file->getFilename();
     $foundErrors = $file->getErrors();
     $foundWarnings = $file->getWarnings();
     $expectedErrors = $this->getErrorList(basename($testFile));
     $expectedWarnings = $this->getWarningList(basename($testFile));
     if (is_array($expectedErrors) === false) {
         throw new PHP_CodeSniffer_Exception('getErrorList() must return an array');
     }
     if (is_array($expectedWarnings) === false) {
         throw new PHP_CodeSniffer_Exception('getWarningList() must return an array');
     }
     /*
      We merge errors and warnings together to make it easier
      to iterate over them and produce the errors string. In this way,
      we can report on errors and warnings in the same line even though
      it's not really structured to allow that.
     */
     $allProblems = array();
     $failureMessages = array();
     foreach ($foundErrors as $line => $lineErrors) {
         foreach ($lineErrors as $column => $errors) {
             if (isset($allProblems[$line]) === false) {
                 $allProblems[$line] = array('expected_errors' => 0, 'expected_warnings' => 0, 'found_errors' => array(), 'found_warnings' => array());
             }
             $foundErrorsTemp = array();
             foreach ($allProblems[$line]['found_errors'] as $foundError) {
                 $foundErrorsTemp[] = $foundError;
             }
             $errorsTemp = array();
             foreach ($errors as $foundError) {
                 $errorsTemp[] = $foundError['message'] . ' (' . $foundError['source'] . ')';
             }
             $allProblems[$line]['found_errors'] = array_merge($foundErrorsTemp, $errorsTemp);
         }
         if (isset($expectedErrors[$line]) === true) {
             $allProblems[$line]['expected_errors'] = $expectedErrors[$line];
         } else {
             $allProblems[$line]['expected_errors'] = 0;
         }
         unset($expectedErrors[$line]);
     }
     //end foreach
     foreach ($expectedErrors as $line => $numErrors) {
         if (isset($allProblems[$line]) === false) {
             $allProblems[$line] = array('expected_errors' => 0, 'expected_warnings' => 0, 'found_errors' => array(), 'found_warnings' => array());
         }
         $allProblems[$line]['expected_errors'] = $numErrors;
     }
     foreach ($foundWarnings as $line => $lineWarnings) {
         foreach ($lineWarnings as $column => $warnings) {
             if (isset($allProblems[$line]) === false) {
                 $allProblems[$line] = array('expected_errors' => 0, 'expected_warnings' => 0, 'found_errors' => array(), 'found_warnings' => array());
             }
             $foundWarningsTemp = array();
             foreach ($allProblems[$line]['found_warnings'] as $foundWarning) {
                 $foundWarningsTemp[] = $foundWarning;
             }
             $warningsTemp = array();
             foreach ($warnings as $warning) {
                 $warningsTemp[] = $warning['message'] . ' (' . $warning['source'] . ')';
             }
             $allProblems[$line]['found_warnings'] = array_merge($foundWarningsTemp, $warningsTemp);
         }
         if (isset($expectedWarnings[$line]) === true) {
             $allProblems[$line]['expected_warnings'] = $expectedWarnings[$line];
         } else {
             $allProblems[$line]['expected_warnings'] = 0;
         }
         unset($expectedWarnings[$line]);
     }
     //end foreach
     foreach ($expectedWarnings as $line => $numWarnings) {
         if (isset($allProblems[$line]) === false) {
             $allProblems[$line] = array('expected_errors' => 0, 'expected_warnings' => 0, 'found_errors' => array(), 'found_warnings' => array());
         }
         $allProblems[$line]['expected_warnings'] = $numWarnings;
     }
     // Order the messages by line number.
     ksort($allProblems);
     foreach ($allProblems as $line => $problems) {
         $numErrors = count($problems['found_errors']);
         $numWarnings = count($problems['found_warnings']);
         $expectedErrors = $problems['expected_errors'];
         $expectedWarnings = $problems['expected_warnings'];
         $errors = '';
         $foundString = '';
         if ($expectedErrors !== $numErrors || $expectedWarnings !== $numWarnings) {
             $lineMessage = "[LINE {$line}]";
             $expectedMessage = 'Expected ';
             $foundMessage = 'in ' . basename($testFile) . ' but found ';
//.........這裏部分代碼省略.........
開發者ID:rjbs,項目名稱:perl-code-tidyall,代碼行數:101,代碼來源:AbstractSniffUnitTest.php

示例5: generateFailureMessages

 /**
  * Generate a list of test failures for a given sniffed file.
  *
  * @param PHP_CodeSniffer_File $file The file being tested.
  *
  * @return array
  * @throws PHP_CodeSniffer_Exception
  */
 public function generateFailureMessages(PHP_CodeSniffer_File $file)
 {
     $testFile = $file->getFilename();
     $foundErrors = $file->getErrors();
     $foundWarnings = $file->getWarnings();
     $expectedErrors = $this->getErrorList(basename($testFile));
     $expectedWarnings = $this->getWarningList(basename($testFile));
     if (!is_array($expectedErrors)) {
         throw new PHP_CodeSniffer_Exception('getErrorList() must return an array');
     }
     if (!is_array($expectedWarnings)) {
         throw new PHP_CodeSniffer_Exception('getWarningList() must return an array');
     }
     /*
      We merge errors and warnings together to make it easier
      to iterate over them and produce the errors string. In this way,
      we can report on errors and warnings in the same line even though
      it's not really structured to allow that.
     */
     $allProblems = [];
     $failureMessages = [];
     foreach ($foundErrors as $line => $lineErrors) {
         if (!array_key_exists($line, $allProblems)) {
             $allProblems[$line] = ['expected_errors' => 0, 'expected_warnings' => 0, 'found_errors' => [], 'found_warnings' => []];
         }
         foreach ($lineErrors as $column => $errors) {
             $errorsTemp = [];
             foreach ($errors as $foundError) {
                 $errorsTemp[] = $foundError['message'];
             }
             $allProblems[$line]['found_errors'] = array_merge($allProblems[$line]['found_errors'], $errorsTemp);
         }
         $allProblems[$line]['expected_errors'] = array_key_exists($line, $expectedErrors) ? $expectedErrors[$line] : 0;
         unset($expectedErrors[$line]);
     }
     foreach ($expectedErrors as $line => $numErrors) {
         if (!array_key_exists($line, $allProblems)) {
             $allProblems[$line] = ['expected_errors' => 0, 'expected_warnings' => 0, 'found_errors' => [], 'found_warnings' => []];
         }
         $allProblems[$line]['expected_errors'] = $numErrors;
     }
     foreach ($foundWarnings as $line => $lineWarnings) {
         if (!array_key_exists($line, $allProblems)) {
             $allProblems[$line] = ['expected_errors' => 0, 'expected_warnings' => 0, 'found_errors' => [], 'found_warnings' => []];
         }
         foreach ($lineWarnings as $column => $warnings) {
             $warningsTemp = [];
             foreach ($warnings as $warning) {
                 $warningsTemp[] = $warning['message'];
             }
             $allProblems[$line]['found_warnings'] = array_merge($allProblems[$line]['found_warnings'], $warningsTemp);
         }
         $allProblems[$line]['expected_warnings'] = array_key_exists($line, $expectedWarnings) ? $expectedWarnings[$line] : 0;
         unset($expectedWarnings[$line]);
     }
     foreach ($expectedWarnings as $line => $numWarnings) {
         if (!array_key_exists($line, $allProblems)) {
             $allProblems[$line] = ['expected_errors' => 0, 'expected_warnings' => 0, 'found_errors' => [], 'found_warnings' => []];
         }
         $allProblems[$line]['expected_warnings'] = $numWarnings;
     }
     ksort($allProblems);
     foreach ($allProblems as $line => $problems) {
         $numErrors = count($problems['found_errors']);
         $numWarnings = count($problems['found_warnings']);
         $expectedErrors = $problems['expected_errors'];
         $expectedWarnings = $problems['expected_warnings'];
         $errors = '';
         $foundString = '';
         if ($expectedErrors !== $numErrors || $expectedWarnings !== $numWarnings) {
             $lineMessage = "[LINE {$line}]";
             $expectedMessage = 'Expected ';
             $foundMessage = 'in ' . basename($testFile) . ' but found ';
             if ($expectedErrors !== $numErrors) {
                 $expectedMessage .= "{$expectedErrors} error(s)";
                 $foundMessage .= "{$numErrors} error(s)";
                 if ($numErrors !== 0) {
                     $foundString .= 'error(s)';
                     $errors .= implode("\n -> ", $problems['found_errors']);
                 }
                 if ($expectedWarnings !== $numWarnings) {
                     $expectedMessage .= ' and ';
                     $foundMessage .= ' and ';
                     if ($numWarnings !== 0 && $foundString !== '') {
                         $foundString .= ' and ';
                     }
                 }
             }
             if ($expectedWarnings !== $numWarnings) {
                 $expectedMessage .= "{$expectedWarnings} warning(s)";
                 $foundMessage .= "{$numWarnings} warning(s)";
                 if ($numWarnings !== 0) {
//.........這裏部分代碼省略.........
開發者ID:ezzy1337,項目名稱:dws-coding-standard,代碼行數:101,代碼來源:AbstractSniffUnitTest.php

示例6: prepareFileReport

 /**
  * Pre-process and package violations for all files.
  *
  * Used by error reports to get a packaged list of all errors in each file.
  *
  * @param PHP_CodeSniffer_File $phpcsFile The file that has been processed.
  *
  * @return array
  */
 public function prepareFileReport(PHP_CodeSniffer_File $phpcsFile)
 {
     $report = array('filename' => $phpcsFile->getFilename(), 'errors' => $phpcsFile->getErrorCount(), 'warnings' => $phpcsFile->getWarningCount(), 'fixable' => $phpcsFile->getFixableCount(), 'messages' => array());
     if ($report['errors'] === 0 && $report['warnings'] === 0) {
         // Prefect score!
         return $report;
     }
     $errors = array();
     // Merge errors and warnings.
     foreach ($phpcsFile->getErrors() as $line => $lineErrors) {
         if (is_array($lineErrors) === false) {
             continue;
         }
         foreach ($lineErrors as $column => $colErrors) {
             $newErrors = array();
             foreach ($colErrors as $data) {
                 $newErrors[] = array('message' => $data['message'], 'source' => $data['source'], 'severity' => $data['severity'], 'fixable' => $data['fixable'], 'type' => 'ERROR');
             }
             //end foreach
             $errors[$line][$column] = $newErrors;
         }
         //end foreach
         ksort($errors[$line]);
     }
     //end foreach
     foreach ($phpcsFile->getWarnings() as $line => $lineWarnings) {
         if (is_array($lineWarnings) === false) {
             continue;
         }
         foreach ($lineWarnings as $column => $colWarnings) {
             $newWarnings = array();
             foreach ($colWarnings as $data) {
                 $newWarnings[] = array('message' => $data['message'], 'source' => $data['source'], 'severity' => $data['severity'], 'fixable' => $data['fixable'], 'type' => 'WARNING');
             }
             //end foreach
             if (isset($errors[$line]) === false) {
                 $errors[$line] = array();
             }
             if (isset($errors[$line][$column]) === true) {
                 $errors[$line][$column] = array_merge($newWarnings, $errors[$line][$column]);
             } else {
                 $errors[$line][$column] = $newWarnings;
             }
         }
         //end foreach
         ksort($errors[$line]);
     }
     //end foreach
     ksort($errors);
     $report['messages'] = $errors;
     return $report;
 }
開發者ID:eredi93,項目名稱:forms,代碼行數:61,代碼來源:Reporting.php

示例7: generateFailureMessages

 /**
  * Generate a list of test failures for a given sniffed file.
  *
  * @param PHP_CodeSniffer_File $file The file being tested.
  *
  * @return array
  *
  * @throws PHP_CodeSniffer_Exception When the getErrorList() or getWarningList() return value is invalid.
  *
  * @SuppressWarnings(PHPMD.Superglobals)
  * @SuppressWarnings(PHPMD.CamelCaseVariableName)
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  * @SuppressWarnings(PHPMD.NPathComplexity)
  * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
  */
 public function generateFailureMessages(PHP_CodeSniffer_File $file)
 {
     $testFile = $file->getFilename();
     $foundErrors = $file->getErrors();
     $foundWarnings = $file->getWarnings();
     $expectedErrors = $this->getErrorList(basename($testFile));
     $expectedWarnings = $this->getWarningList(basename($testFile));
     if (is_array($expectedErrors) === false) {
         throw new PHP_CodeSniffer_Exception('getErrorList() must return an array');
     }
     if (is_array($expectedWarnings) === false) {
         throw new PHP_CodeSniffer_Exception('getWarningList() must return an array');
     }
     /*
         We merge errors and warnings together to make it easier
         to iterate over them and produce the errors string. In this way,
         we can report on errors and warnings in the same line even though
         it's not really structured to allow that.
     */
     $allProblems = array();
     $failureMessages = array();
     foreach ($foundErrors as $line => $lineErrors) {
         foreach ($lineErrors as $column => $errors) {
             if (isset($allProblems[$line]) === false) {
                 $allProblems[$line] = array('expected_errors' => 0, 'expected_warnings' => 0, 'found_errors' => array(), 'found_warnings' => array());
             }
             $foundErrorsTemp = array();
             foreach ($allProblems[$line]['found_errors'] as $foundError) {
                 $foundErrorsTemp[] = $foundError;
             }
             $errorsTemp = array();
             foreach ($errors as $foundError) {
                 $errorsTemp[] = $foundError['message'] . ' (' . $foundError['source'] . ')';
                 $source = $foundError['source'];
                 if (in_array($source, $GLOBALS['PHP_CODESNIFFER_SNIFF_CODES']) === false) {
                     $GLOBALS['PHP_CODESNIFFER_SNIFF_CODES'][] = $source;
                 }
                 if ($foundError['fixable'] === true && in_array($source, $GLOBALS['PHP_CODESNIFFER_FIXABLE_CODES']) === false) {
                     $GLOBALS['PHP_CODESNIFFER_FIXABLE_CODES'][] = $source;
                 }
             }
             $allProblems[$line]['found_errors'] = array_merge($foundErrorsTemp, $errorsTemp);
         }
         if (isset($expectedErrors[$line]) === true) {
             $allProblems[$line]['expected_errors'] = $expectedErrors[$line];
         } else {
             $allProblems[$line]['expected_errors'] = 0;
         }
         unset($expectedErrors[$line]);
     }
     foreach ($expectedErrors as $line => $numErrors) {
         if (isset($allProblems[$line]) === false) {
             $allProblems[$line] = array('expected_errors' => 0, 'expected_warnings' => 0, 'found_errors' => array(), 'found_warnings' => array());
         }
         $allProblems[$line]['expected_errors'] = $numErrors;
     }
     foreach ($foundWarnings as $line => $lineWarnings) {
         foreach ($lineWarnings as $column => $warnings) {
             if (isset($allProblems[$line]) === false) {
                 $allProblems[$line] = array('expected_errors' => 0, 'expected_warnings' => 0, 'found_errors' => array(), 'found_warnings' => array());
             }
             $foundWarningsTemp = array();
             foreach ($allProblems[$line]['found_warnings'] as $foundWarning) {
                 $foundWarningsTemp[] = $foundWarning;
             }
             $warningsTemp = array();
             foreach ($warnings as $warning) {
                 $warningsTemp[] = $warning['message'] . ' (' . $warning['source'] . ')';
             }
             $allProblems[$line]['found_warnings'] = array_merge($foundWarningsTemp, $warningsTemp);
         }
         if (isset($expectedWarnings[$line]) === true) {
             $allProblems[$line]['expected_warnings'] = $expectedWarnings[$line];
         } else {
             $allProblems[$line]['expected_warnings'] = 0;
         }
         unset($expectedWarnings[$line]);
     }
     foreach ($expectedWarnings as $line => $numWarnings) {
         if (isset($allProblems[$line]) === false) {
             $allProblems[$line] = array('expected_errors' => 0, 'expected_warnings' => 0, 'found_errors' => array(), 'found_warnings' => array());
         }
         $allProblems[$line]['expected_warnings'] = $numWarnings;
     }
     // Order the messages by line number.
//.........這裏部分代碼省略.........
開發者ID:phpcq,項目名稱:coding-standard,代碼行數:101,代碼來源:AbstractSniffUnitTest.php

示例8: fileHasExpectedErrors

 protected function fileHasExpectedErrors(\PHP_CodeSniffer_File $sniffedFile, array $expectedProblems)
 {
     $this->problemsMatchExpected($expectedProblems, $sniffedFile->getErrors(), 'error');
 }
開發者ID:matthiasnoback,項目名稱:php-coding-standard,代碼行數:4,代碼來源:AbstractSniffTest.php

示例9: getFileResult

 /**
  * Get simple result of processed file
  *
  * @param \PHP_CodeSniffer_File $phpcsFile
  * @return array
  */
 protected function getFileResult($phpcsFile)
 {
     $report = array();
     if ($phpcsFile && ($phpcsFile->getErrorCount() || $phpcsFile->getWarningCount())) {
         $report = array('errors' => $phpcsFile->getErrors(), 'warnings' => $phpcsFile->getWarnings());
     }
     return $report;
 }
開發者ID:andkirby,項目名稱:commithook,代碼行數:14,代碼來源:NonCliSniffer.php

示例10: generateFailureMessages

 /**
  * Generate a list of test failures for a given sniffed file.
  *
  * @param PHP_CodeSniffer_File $file The file being tested.
  *
  * @return array
  * @throws PHP_CodeSniffer_Exception
  */
 public function generateFailureMessages(\PHP_CodeSniffer_File $file)
 {
     $testFile = $file->getFilename();
     $foundErrors = $file->getErrors();
     $foundWarnings = $file->getWarnings();
     $expectedErrors = $this->getErrorList(basename($testFile));
     $expectedWarnings = $this->getWarningList(basename($testFile));
     if (is_array($expectedErrors) === false) {
         throw new \PHP_CodeSniffer_Exception('getErrorList() must return an array');
     }
     if (is_array($expectedWarnings) === false) {
         throw new \PHP_CodeSniffer_Exception('getWarningList() must return an array');
     }
     $failureMessages = [];
     $failureMessages = array_merge($failureMessages, self::validateFailures($foundErrors, $expectedErrors, basename($testFile), 'error'));
     $failureMessages = array_merge($failureMessages, self::validateFailures($foundWarnings, $expectedWarnings, basename($testFile), 'warning'));
     return $failureMessages;
 }
開發者ID:suitmedia,項目名稱:php-code-standards,代碼行數:26,代碼來源:AbstractSniffUnitTest.php


注:本文中的PHP_CodeSniffer_File::getErrors方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。