本文整理匯總了PHP中PHP_CodeSniffer\Files\File::setContent方法的典型用法代碼示例。如果您正苦於以下問題:PHP File::setContent方法的具體用法?PHP File::setContent怎麽用?PHP File::setContent使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類PHP_CodeSniffer\Files\File
的用法示例。
在下文中一共展示了File::setContent方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: fixFile
/**
* Attempt to fix the file by processing it until no fixes are made.
*
* @return boolean
*/
public function fixFile()
{
$fixable = $this->currentFile->getFixableCount();
if ($fixable === 0) {
// Nothing to fix.
return false;
}
$stdin = false;
if (empty($this->currentFile->config->files) === true) {
$stdin = true;
}
$this->enabled = true;
$this->loops = 0;
while ($this->loops < 50) {
ob_start();
// Only needed once file content has changed.
$contents = $this->getContents();
if (PHP_CODESNIFFER_VERBOSITY > 2) {
@ob_end_clean();
echo '---START FILE CONTENT---' . PHP_EOL;
$lines = explode($this->currentFile->eolChar, $contents);
$max = strlen(count($lines));
foreach ($lines as $lineNum => $line) {
$lineNum++;
echo str_pad($lineNum, $max, ' ', STR_PAD_LEFT) . '|' . $line . PHP_EOL;
}
echo '--- END FILE CONTENT ---' . PHP_EOL;
ob_start();
}
$this->inConflict = false;
$this->currentFile->ruleset->populateTokenListeners();
$this->currentFile->setContent($contents);
$this->currentFile->process();
ob_end_clean();
$this->loops++;
if (PHP_CODESNIFFER_CBF === true && PHP_CODESNIFFER_VERBOSITY > 0) {
echo "\r" . str_repeat(' ', 80) . "\r";
echo "\t=> Fixing file: {$this->numFixes}/{$fixable} violations remaining [made {$this->loops} pass";
if ($this->loops > 1) {
echo 'es';
}
echo ']... ';
}
if ($this->numFixes === 0 && $this->inConflict === false) {
// Nothing left to do.
break;
} else {
if (PHP_CODESNIFFER_VERBOSITY > 1) {
echo "\t* fixed {$this->numFixes} violations, starting loop " . ($this->loops + 1) . ' *' . PHP_EOL;
}
}
}
//end while
$this->enabled = false;
if ($this->numFixes > 0) {
if (PHP_CODESNIFFER_VERBOSITY > 1) {
@ob_end_clean();
echo "\t*** Reached maximum number of loops with {$this->numFixes} violations left unfixed ***" . PHP_EOL;
ob_start();
}
return false;
}
return true;
}