本文整理汇总了PHP中PHP_CodeSniffer_File::adderror方法的典型用法代码示例。如果您正苦于以下问题:PHP PHP_CodeSniffer_File::adderror方法的具体用法?PHP PHP_CodeSniffer_File::adderror怎么用?PHP PHP_CodeSniffer_File::adderror使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PHP_CodeSniffer_File
的用法示例。
在下文中一共展示了PHP_CodeSniffer_File::adderror方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: process
/**
* Processes this test, when one of its tokens is encountered.
*
* @param PHP_CodeSniffer_File $phpcsfile The file being scanned.
* @param int $stackptr The position of the current token in the
* stack passed in $tokens.
*
* @return void
*/
public function process(PHP_CodeSniffer_File $phpcsfile, $stackptr)
{
$tokens = $phpcsfile->gettokens();
if (isset($tokens[$stackptr]['scope_opener']) === false) {
$error = 'possible parse error: ';
$error .= $tokens[$stackptr]['content'];
$error .= ' missing opening or closing brace';
$phpcsfile->addwarning($error, $stackptr);
return;
}
$curlybrace = $tokens[$stackptr]['scope_opener'];
$lastcontent = $phpcsfile->findprevious(T_WHITESPACE, $curlybrace - 1, $stackptr, true);
$classline = $tokens[$lastcontent]['line'];
$braceline = $tokens[$curlybrace]['line'];
if ($braceline != $classline) {
$error = 'Opening brace of a ';
$error .= $tokens[$stackptr]['content'];
$error .= ' must be on the same line as the definition';
$phpcsfile->adderror($error, $curlybrace);
return;
}
if ($tokens[$curlybrace - 1]['code'] === T_WHITESPACE) {
$prevcontent = $tokens[$curlybrace - 1]['content'];
if ($prevcontent !== $phpcsfile->eolChar) {
$blankspace = substr($prevcontent, strpos($prevcontent, $phpcsfile->eolChar));
$spaces = strlen($blankspace);
if ($spaces !== 1) {
$error = "Expected 1 space before opening brace; {$spaces} found";
$phpcsfile->adderror($error, $curlybrace);
}
}
}
}
示例2: process
/**
* Processes this test, when one of its tokens is encountered.
*
* @param PHP_CodeSniffer_File $phpcsfile The file being scanned.
* @param int $stackptr The position of the current token in the
* stack passed in $tokens.
*
* @return void
*/
public function process(PHP_CodeSniffer_File $phpcsfile, $stackptr)
{
$tokens = $phpcsfile->gettokens();
// Find the next non-empty token.
$next = $phpcsfile->findnext(PHP_CodeSniffer_tokens::$emptyTokens, $stackptr + 1, null, true);
if ($tokens[$next]['code'] !== T_OPEN_PARENTHESIS) {
// Not a function call.
return;
}
if (isset($tokens[$next]['parenthesis_closer']) === false) {
// Not a function call.
return;
}
// Find the previous non-empty token.
$previous = $phpcsfile->findprevious(PHP_CodeSniffer_tokens::$emptyTokens, $stackptr - 1, null, true);
if ($tokens[$previous]['code'] === T_FUNCTION) {
// It's a function definition, not a function call.
return;
}
if ($tokens[$previous]['code'] === T_NEW) {
// We are creating an object, not calling a function.
return;
}
if ($stackptr + 1 !== $next) {
// Checking this: $value = my_function[*](...).
$error = 'Space before opening parenthesis of function call prohibited';
$phpcsfile->adderror($error, $stackptr);
}
if ($tokens[$next + 1]['code'] === T_WHITESPACE) {
// Checking this: $value = my_function([*]...).
$error = 'Space after opening parenthesis of function call prohibited';
$phpcsfile->adderror($error, $stackptr);
}
$closer = $tokens[$next]['parenthesis_closer'];
if ($tokens[$closer - 1]['code'] === T_WHITESPACE) {
// Checking this: $value = my_function(...[*]).
$between = $phpcsfile->findnext(T_WHITESPACE, $next + 1, null, true);
// Only throw an error if there is some content between the parenthesis.
// IE. Checking for this: $value = my_function().
// If there is no content, then we would have thrown an error in the
// previous IF statement because it would look like this:
// $value = my_function( ).
if ($between !== $closer) {
$error = 'Space before closing parenthesis of function call prohibited';
$phpcsfile->adderror($error, $closer);
}
}
$next = $phpcsfile->findnext(T_WHITESPACE, $closer + 1, null, true);
if ($tokens[$next]['code'] === T_SEMICOLON) {
if (in_array($tokens[$closer + 1]['code'], PHP_CodeSniffer_tokens::$emptyTokens) === true) {
$error = 'Space after closing parenthesis of function call prohibited';
$phpcsfile->adderror($error, $closer);
}
}
}
示例3: process
/**
* Processes this test, when one of its tokens is encountered.
*
* @param PHP_CodeSniffer_File $phpcsfile The file being scanned.
* @param int $stackptr The position of the current token in
* the stack passed in $tokens.
*
* @return void
*/
public function process(PHP_CodeSniffer_File $phpcsfile, $stackptr)
{
$tokens = $phpcsfile->gettokens();
if ($tokens[$stackptr + 1]['code'] !== T_WHITESPACE) {
$error = 'A cast statement must be followed by a single space';
$phpcsfile->adderror($error, $stackptr);
return;
}
if ($tokens[$stackptr + 1]['content'] !== ' ') {
$error = 'A cast statement must be followed by a single space';
$phpcsfile->adderror($error, $stackptr);
}
}
示例4: process
/**
* Processes this sniff, when one of its tokens is encountered.
*
* @param PHP_CodeSniffer_File $phpcsfile The file being scanned.
* @param int $stackptr The position of the current token in the
* stack passed in $tokens.
*
* @return void
*/
public function process(PHP_CodeSniffer_File $phpcsfile, $stackptr)
{
$tokens = $phpcsfile->gettokens();
$keyword = $tokens[$stackptr]['content'];
if (strtolower($keyword) !== $keyword) {
$error = 'TRUE, FALSE and NULL must be lowercase; expected "' . strtolower($keyword) . '" but found "' . $keyword . '"';
$phpcsfile->adderror($error, $stackptr);
}
}
示例5: process
/**
* Processes this test, when one of its tokens is encountered.
*
* @param PHP_CodeSniffer_File $phpcsfile The file being scanned.
* @param int $stackptr The position of the current token in the
* stack passed in $tokens.
*
* @return void
*/
public function process(PHP_CodeSniffer_File $phpcsfile, $stackptr)
{
$tokens = $phpcsfile->gettokens();
if ($tokens[$stackptr]['content'][0] === '#') {
$error = 'Perl-style comments are not allowed. Use "// Comment."';
$error .= ' or "/* comment */" instead.';
$phpcsfile->adderror($error, $stackptr);
}
}
示例6: process
/**
* Processes this test, when one of its tokens is encountered.
*
* @param PHP_CodeSniffer_File $phpcsfile The file being scanned.
* @param int $stackptr The position of the current token in
* the stack passed in $tokens.
*
* @return void
*/
public function process(PHP_CodeSniffer_File $phpcsfile, $stackptr)
{
$tokens = $phpcsfile->gettokens();
$content = $tokens[$stackptr]['content'];
if ($content !== strtolower($content)) {
$type = strtoupper($content);
$expected = strtolower($content);
$error = "{$type} keyword must be lowercase; expected \"{$expected}\" but found \"{$content}\"";
$phpcsfile->adderror($error, $stackptr);
}
}
示例7: process
/**
* Processes this test, when one of its tokens is encountered.
*
* @param PHP_CodeSniffer_File $phpcsfile The current file being processed.
* @param int $stackptr The position of the current token
* in the stack passed in $tokens.
*
* @return void
*/
public function process(PHP_CodeSniffer_File $phpcsfile, $stackptr)
{
$tokens = $phpcsfile->gettokens();
$classname = $phpcsfile->findnext(T_STRING, $stackptr);
$name = trim($tokens[$classname]['content']);
// Make sure that the word is all lowercase
if (!preg_match('/[a-z]?/', $name)) {
$error = ucfirst($tokens[$stackptr]['content']) . ' name is not valid, must be all lower-case';
$phpcsfile->adderror($error, $stackptr);
}
}
示例8: process
/**
* Processes this test, when one of its tokens is encountered.
*
* @param PHP_CodeSniffer_File $phpcsfile All the tokens found in the document.
* @param int $stackptr The position of the current token in
* the stack passed in $tokens.
*
* @return void
*/
public function process(PHP_CodeSniffer_File $phpcsfile, $stackptr)
{
$tokens = $phpcsfile->gettokens();
// Make sure this is whitespace used for indentation.
$line = $tokens[$stackptr]['line'];
if ($stackptr > 0 && $tokens[$stackptr - 1]['line'] === $line) {
return;
}
if (strpos($tokens[$stackptr]['content'], "\t") !== false) {
$error = 'Spaces must be used to indent lines; tabs are not allowed';
$phpcsfile->adderror($error, $stackptr);
}
}
示例9: process
/**
* Processes this test, when one of its tokens is encountered.
*
* @param PHP_CodeSniffer_File $phpcsfile All the tokens found in the document.
* @param int $stackptr The position of the current token in the
* stack passed in $tokens.
*
* @return void
*/
public function process(PHP_CodeSniffer_File $phpcsfile, $stackptr)
{
$tokens = $phpcsfile->gettokens();
// If this is an inline condition (ie. there is no scope opener), then
// return, as this is not a new scope.
if (isset($tokens[$stackptr]['scope_closer']) === false) {
return;
}
// We need to actually find the first piece of content on this line,
// as if this is a method with tokens before it (public, static etc)
// or an if with an else before it, then we need to start the scope
// checking from there, rather than the current token.
$linestart = $stackptr - 1;
for ($linestart; $linestart > 0; $linestart--) {
if (strpos($tokens[$linestart]['content'], $phpcsfile->eolChar) !== false) {
break;
}
}
// We found a new line, now go forward and find the first non-whitespace
// token.
$linestart = $phpcsfile->findnext(array(T_WHITESPACE), $linestart + 1, null, true);
$startcolumn = $tokens[$linestart]['column'];
$scopestart = $tokens[$stackptr]['scope_opener'];
$scopeend = $tokens[$stackptr]['scope_closer'];
// Check that the closing brace is on its own line.
$lastcontent = $phpcsfile->findprevious(array(T_WHITESPACE), $scopeend - 1, $scopestart, true);
if ($tokens[$lastcontent]['line'] === $tokens[$scopeend]['line']) {
$error = 'Closing brace must be on a line by itself';
$phpcsfile->adderror($error, $scopeend);
return;
}
// Check now that the closing brace is lined up correctly.
$braceindent = $tokens[$scopeend]['column'];
$isbreakcloser = $tokens[$scopeend]['code'] === T_BREAK;
if (in_array($tokens[$stackptr]['code'], array(T_CASE, T_DEFAULT)) === true && $isbreakcloser === true) {
// BREAK statements should be indented 4 spaces from the
// CASE or DEFAULT statement.
if ($braceindent !== $startcolumn + 4) {
$error = 'Break statement indented incorrectly; expected ' . ($startcolumn + 3) . ' spaces, found ' . ($braceindent - 1);
$phpcsfile->adderror($error, $scopeend);
}
} else {
if (in_array($tokens[$stackptr]['code'], array(T_CASE, T_DEFAULT))) {
$startcolumn -= 4;
}
if ($braceindent !== $startcolumn) {
$error = 'Closing brace indented incorrectly; expected ' . ($startcolumn - 1) . ' spaces, found ' . ($braceindent - 1);
$phpcsfile->adderror($error, $scopeend);
}
}
}
示例10: process
/**
* Processes this test, when one of its tokens is encountered.
*
* @param PHP_CodeSniffer_File $phpcsfile The file being scanned.
* @param int $stackptr The position of the current token in
* the stack passed in $tokens.
*
* @return void
*/
public function process(PHP_CodeSniffer_File $phpcsfile, $stackptr)
{
$tokens = $phpcsfile->gettokens();
if ($tokens[$stackptr]['code'] !== T_STRING) {
$content = $tokens[$stackptr]['content'];
if ($content !== strtolower($content)) {
$type = strtoupper($content);
$expected = strtolower($content);
$error = "{$type} keyword must be lowercase; expected \"{$expected}\" but found \"{$content}\"";
$phpcsfile->adderror($error, $stackptr);
}
return;
}
// Make sure this is a function call.
$next = $phpcsfile->findnext(T_WHITESPACE, $stackptr + 1, null, true);
if ($next === false) {
// Not a function call.
return;
}
if ($tokens[$next]['code'] !== T_OPEN_PARENTHESIS) {
// Not a function call.
return;
}
$prev = $phpcsfile->findprevious(T_WHITESPACE, $stackptr - 1, null, true);
if ($tokens[$prev]['code'] === T_FUNCTION) {
// Function declaration, not a function call.
return;
}
if ($tokens[$prev]['code'] === T_OBJECT_OPERATOR) {
// Not an inbuilt function.
return;
}
if ($tokens[$prev]['code'] === T_DOUBLE_COLON) {
// Not an inbuilt function.
return;
}
// Make sure it is an inbuilt PHP function.
// PHP_CodeSniffer doesn't include/require any files, so no
// user defined global functions can exist, except for
// PHP_CodeSniffer ones.
$content = $tokens[$stackptr]['content'];
if (function_exists($content) === false) {
return;
}
if ($content !== strtolower($content)) {
$expected = strtolower($content);
$error = "Calls to inbuilt PHP functions must be lowercase; expected \"{$expected}\" but found \"{$content}\"";
$phpcsfile->adderror($error, $stackptr);
}
}
示例11: process
/**
* Processes this test, when one of its tokens is encountered.
*
* @param PHP_CodeSniffer_File $phpcsfile The file being scanned.
* @param int $stackptr The position of the current token in the
* stack passed in $tokens.
*
* @return void
*/
public function process(PHP_CodeSniffer_File $phpcsfile, $stackptr)
{
// If short open tags are off, then any short open tags will be converted
// to inline_html tags so we can just ignore them.
// If its on, then we want to ban the use of them.
$option = ini_get('short_open_tag');
// Ini_get returns a string "0" if short open tags is off.
if ($option === '0') {
return;
}
$tokens = $phpcsfile->gettokens();
$opentag = $tokens[$stackptr];
if ($opentag['content'] === '<?') {
$error = 'Short PHP opening tag used. Found "' . $opentag['content'] . '" Expected "<?php".';
$phpcsfile->adderror($error, $stackptr);
}
if ($opentag['code'] === T_OPEN_TAG_WITH_ECHO) {
$nextvar = $tokens[$phpcsfile->findnext(PHP_CodeSniffer_tokens::$emptyTokens, $stackptr + 1, null, true)];
$error = 'Short PHP opening tag used with echo. Found "';
$error .= $opentag['content'] . ' ' . $nextvar['content'] . ' ..." but expected "<?php echo ' . $nextvar['content'] . ' ...".';
$phpcsfile->adderror($error, $stackptr);
}
}
示例12: processversion
/**
* Process the version tag.
*
* @param int $errorpos The line number where the error occurs.
*
* @return void
*/
protected function processversion($errorpos)
{
$version = $this->commentparser->getVersion();
if ($version !== null) {
$content = $version->getcontent();
$matches = array();
if (empty($content) === true) {
$error = 'content missing for @version tag in file comment';
$this->currentfile->adderror($error, $errorpos);
} else {
if (strstr($content, 'CVS:') === false && strstr($content, 'SVN:') === false) {
$error = "Invalid version \"{$content}\" in file comment; consider \"CVS: <cvs_id>\" or \"SVN: <svn_id>\" instead";
$this->currentfile->addwarning($error, $errorpos);
}
}
}
}
示例13: process
/**
* Processes this test, when one of its tokens is encountered.
*
* @param PHP_CodeSniffer_File $phpcsfile The file being scanned.
* @param int $stackptr The position of the current token in the
* stack passed in $tokens.
*
* @return void
*/
public function process(PHP_CodeSniffer_File $phpcsfile, $stackptr)
{
$tokens = $phpcsfile->gettokens();
$firstcontent = $phpcsfile->findnext(array(T_WHITESPACE), $stackptr + 1, null, true);
// If the first non-whitespace token is not an opening parenthesis, then we are not concerned.
if ($tokens[$firstcontent]['code'] !== T_OPEN_PARENTHESIS) {
return;
}
$endofstatement = $phpcsfile->findnext(array(T_SEMICOLON), $stackptr, null, false);
// If the token before the semi-colon is not a closing parenthesis, then we are not concerned.
if ($tokens[$endofstatement - 1]['code'] !== T_CLOSE_PARENTHESIS) {
return;
}
if ($phpcsfile->findnext(PHP_CodeSniffer_tokens::$operators, $stackptr, $endofstatement, false) === false) {
// There are no arithmetic operators in this.
$error = 'Echoed strings should not be bracketed';
$phpcsfile->adderror($error, $stackptr);
}
}
示例14: process
/**
* Processes this sniff, when one of its tokens is encountered.
*
* @param PHP_CodeSniffer_File $phpcsfile The file being scanned.
* @param int $stackptr The position of the current token in the
* stack passed in $tokens.
*
* @return void
*/
public function process(PHP_CodeSniffer_File $phpcsfile, $stackptr)
{
// We are only interested if this is the first open tag.
if ($stackptr !== 0) {
if ($phpcsfile->findprevious(T_OPEN_TAG, $stackptr - 1) !== false) {
return;
}
}
if ($phpcsfile->eolChar !== $this->eolChar) {
$expected = $this->eolChar;
$expected = str_replace("\n", '\\n', $expected);
$expected = str_replace("\r", '\\r', $expected);
$found = $phpcsfile->eolChar;
$found = str_replace("\n", '\\n', $found);
$found = str_replace("\r", '\\r', $found);
$error = "end of line character is invalid; expected \"{$expected}\" but found \"{$found}\"";
$phpcsfile->adderror($error, $stackptr);
}
}
示例15: processTokenOutsideScope
/**
* Processes the tokens outside the scope.
*
* @param PHP_CodeSniffer_File $phpcsfile The file being processed.
* @param int $stackptr The position where this token was
* found.
*
* @return void
*/
protected function processTokenOutsideScope(PHP_CodeSniffer_File $phpcsfile, $stackptr)
{
$functionname = $phpcsfile->getDeclarationName($stackptr);
// Is this a magic function. IE. is prefixed with "__".
if (preg_match('|^__|', $functionname) !== 0) {
$magicpart = substr($functionname, 2);
if (in_array($magicpart, $this->magicfunctions) === false) {
$error = "Function name \"{$functionname}\" is invalid; " . 'only PHP magic methods should be prefixed with a double underscore';
$phpcsfile->adderror($error, $stackptr);
}
return;
}
// Only lower-case accepted
if (preg_match('/[A-Z]+/', $functionname)) {
$error = "function name \"{$functionname}\" must be lower-case letters only";
$phpcsfile->addError($error, $stackptr);
return;
}
}