本文整理汇总了PHP中PHP_CodeSniffer_File::getWarnings方法的典型用法代码示例。如果您正苦于以下问题:PHP PHP_CodeSniffer_File::getWarnings方法的具体用法?PHP PHP_CodeSniffer_File::getWarnings怎么用?PHP PHP_CodeSniffer_File::getWarnings使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PHP_CodeSniffer_File
的用法示例。
在下文中一共展示了PHP_CodeSniffer_File::getWarnings方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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;
}
示例2: gatherWarnings
/**
* Gather all warning messages by line number from phpcs file result
*
* @param PHP_CodeSniffer_File $file Codesniffer File object
* @return array
*/
public function gatherWarnings(PHP_CodeSniffer_File $file)
{
$foundWarnings = $file->getWarnings();
$allWarnings = array();
foreach ($foundWarnings as $line => $lineWarnings) {
foreach ($lineWarnings as $column => $warnings) {
foreach ($warnings as $warning) {
if (!isset($allWarnings[$line])) {
$allWarnings[$line] = array();
}
$allWarnings[$line][] = $warning;
}
}
}
return $allWarnings;
}
示例3: 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) {
//.........这里部分代码省略.........
示例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 ';
//.........这里部分代码省略.........
示例5: 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;
}
示例6: 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.
//.........这里部分代码省略.........
示例7: fileHasExpectedWarnings
protected function fileHasExpectedWarnings(\PHP_CodeSniffer_File $sniffedFile, array $expectedWarnings)
{
$this->problemsMatchExpected($expectedWarnings, $sniffedFile->getWarnings(), 'warning');
}
示例8: 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;
}
示例9: 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;
}