本文整理汇总了PHP中PHP_CodeSniffer_File::getWarningCount方法的典型用法代码示例。如果您正苦于以下问题:PHP PHP_CodeSniffer_File::getWarningCount方法的具体用法?PHP PHP_CodeSniffer_File::getWarningCount怎么用?PHP PHP_CodeSniffer_File::getWarningCount使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PHP_CodeSniffer_File
的用法示例。
在下文中一共展示了PHP_CodeSniffer_File::getWarningCount方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: _processFile
/**
* Process the sniffs for a single file.
*
* Does raw processing only. No interactive support or error checking.
*
* @param string $file The file to process.
* @param string $contents The contents to parse. If NULL, the content
* is taken from the file system.
*
* @return PHP_CodeSniffer_File
* @see processFile()
*/
private function _processFile($file, $contents)
{
$stdin = false;
$cliValues = $this->cli->getCommandLineValues();
if (empty($cliValues['files']) === true) {
$stdin = true;
}
if (PHP_CODESNIFFER_VERBOSITY > 0 || PHP_CODESNIFFER_CBF === true && $stdin === false) {
$startTime = microtime(true);
echo 'Processing ' . basename($file) . ' ';
if (PHP_CODESNIFFER_VERBOSITY > 1) {
echo PHP_EOL;
}
}
$phpcsFile = new PHP_CodeSniffer_File($file, $this->_tokenListeners, $this->ruleset, $this);
$phpcsFile->start($contents);
if (PHP_CODESNIFFER_VERBOSITY > 0 || PHP_CODESNIFFER_CBF === true && $stdin === false) {
$timeTaken = (microtime(true) - $startTime) * 1000;
if ($timeTaken < 1000) {
$timeTaken = round($timeTaken);
echo "DONE in {$timeTaken}ms";
} else {
$timeTaken = round($timeTaken / 1000, 2);
echo "DONE in {$timeTaken} secs";
}
if (PHP_CODESNIFFER_CBF === true) {
$errors = $phpcsFile->getFixableCount();
echo " ({$errors} fixable violations)" . PHP_EOL;
} else {
$errors = $phpcsFile->getErrorCount();
$warnings = $phpcsFile->getWarningCount();
echo " ({$errors} errors, {$warnings} warnings)" . PHP_EOL;
}
}
return $phpcsFile;
}
示例2: _processFile
/**
* Process the sniffs for a single file.
*
* Does raw processing only. No interactive support or error checking.
*
* @param string $file The file to process.
* @param string $contents The contents to parse. If NULL, the content
* is taken from the file system.
* @param array $restrictions The sniff codes to restrict the
* violations to.
*
* @return PHP_CodeSniffer_File
* @see processFile()
*/
private function _processFile($file, $contents, $restrictions)
{
if (PHP_CODESNIFFER_VERBOSITY > 0) {
$startTime = time();
echo 'Processing ' . basename($file) . ' ';
if (PHP_CODESNIFFER_VERBOSITY > 1) {
echo PHP_EOL;
}
}
$phpcsFile = new PHP_CodeSniffer_File($file, $this->_tokenListeners, $this->allowedFileExtensions, $this->ruleset, $restrictions, $this);
$phpcsFile->start($contents);
$phpcsFile->cleanUp();
if (PHP_CODESNIFFER_VERBOSITY > 0) {
$timeTaken = time() - $startTime;
if ($timeTaken === 0) {
echo 'DONE in < 1 second';
} else {
if ($timeTaken === 1) {
echo 'DONE in 1 second';
} else {
echo "DONE in {$timeTaken} seconds";
}
}
$errors = $phpcsFile->getErrorCount();
$warnings = $phpcsFile->getWarningCount();
echo " ({$errors} errors, {$warnings} warnings)" . PHP_EOL;
}
return $phpcsFile;
}
示例3: 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;
}
示例4: _processFile
/**
* Run the code sniffs over a signle given file.
*
* Processes the file and runs the PHP_CodeSniffer sniffs to verify that it
* conforms with the standard.
*
* @param string $file The file to process.
*
* @return void
* @throws PHP_CodeSniffer_Exception If the file could not be processed.
*/
private function _processFile($file)
{
$file = realpath($file);
if (file_exists($file) === false) {
throw new PHP_CodeSniffer_Exception("Source file {$file} does not exist");
}
if (PHP_CODESNIFFER_VERBOSITY > 0) {
$startTime = time();
echo 'Processing ' . basename($file) . ' ';
if (PHP_CODESNIFFER_VERBOSITY > 1) {
echo PHP_EOL;
}
}
$phpcsFile = new PHP_CodeSniffer_File($file, $this->_listeners);
$this->_files[] = $phpcsFile;
$phpcsFile->start();
if (PHP_CODESNIFFER_VERBOSITY > 0) {
$timeTaken = time() - $startTime;
if ($timeTaken === 0) {
echo 'DONE in < 1 second';
} else {
if ($timeTaken === 1) {
echo 'DONE in 1 second';
} else {
echo "DONE in {$timeTaken} seconds";
}
}
$errors = $phpcsFile->getErrorCount();
$warnings = $phpcsFile->getWarningCount();
echo " ({$errors} errors, {$warnings} warnings)" . PHP_EOL;
}
}
示例5: 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;
}
示例6: _processFile
/**
* Process the sniffs for a single file.
*
* Does raw processing only. No interactive support or error checking.
*
* @param string $file The file to process.
* @param string $contents The contents to parse. If NULL, the content
* is taken from the file system.
*
* @return PHP_CodeSniffer_File
* @see processFile()
*/
private function _processFile($file, $contents)
{
if (PHP_CODESNIFFER_VERBOSITY > 0) {
$startTime = microtime(true);
echo 'Processing ' . basename($file) . ' ';
if (PHP_CODESNIFFER_VERBOSITY > 1) {
echo PHP_EOL;
}
}
$phpcsFile = new PHP_CodeSniffer_File($file, $this->_tokenListeners, $this->allowedFileExtensions, $this->ruleset, $this);
$phpcsFile->start($contents);
if (PHP_CODESNIFFER_VERBOSITY > 0) {
$timeTaken = (microtime(true) - $startTime) * 1000;
if ($timeTaken < 1000) {
$timeTaken = round($timeTaken);
echo "DONE in {$timeTaken}ms";
} else {
$timeTaken = round($timeTaken / 1000, 2);
echo "DONE in {$timeTaken} secs";
}
$errors = $phpcsFile->getErrorCount();
$warnings = $phpcsFile->getWarningCount();
echo " ({$errors} errors, {$warnings} warnings)" . PHP_EOL;
}
return $phpcsFile;
}