当前位置: 首页>>代码示例>>PHP>>正文


PHP PHP_CodeSniffer_File::addEvent方法代码示例

本文整理汇总了PHP中PHP_CodeSniffer_File::addEvent方法的典型用法代码示例。如果您正苦于以下问题:PHP PHP_CodeSniffer_File::addEvent方法的具体用法?PHP PHP_CodeSniffer_File::addEvent怎么用?PHP PHP_CodeSniffer_File::addEvent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在PHP_CodeSniffer_File的用法示例。


在下文中一共展示了PHP_CodeSniffer_File::addEvent方法的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);
         $phpcsFile->addEvent('XP_CLASS_DECLARATION_MISSING_BRACE', array(), $stackPtr);
         return;
     }
     $curlyBrace = $tokens[$stackPtr]['scope_opener'];
     $lastContent = $phpcsFile->findPrevious(T_WHITESPACE, $curlyBrace - 1, $stackPtr, true);
     $classLine = $tokens[$lastContent]['line'];
     $braceLine = $tokens[$curlyBrace]['line'];
     /* Marius - useless check
        if ($braceLine > ($classLine + 1)) {
            $difference  = ($braceLine - $classLine - 1);
            $difference .= ($difference === 1) ? ' line' : ' lines';
            $error       = 'Opening brace of a ';
            $error      .= $tokens[$stackPtr]['content'];
            $error      .= ' must be on the same line as the ';
            $error      .= $tokens[$stackPtr]['content'];
            $error      .= ' declaration; found '.$difference;
            $phpcsFile->addError($error, $curlyBrace);
            return;
        }
        */
     if ($tokens[$curlyBrace + 1]['content'] !== $phpcsFile->eolChar) {
         //$type  = strtolower($tokens[$stackPtr]['content']);
         //$error = "Opening $type brace must be on a line by itself";
         //$phpcsFile->addError($error, $curlyBrace);
         $phpcsFile->addEvent('XP_CLASS_DECLARATION_OPENING_BRACE_WHITESPACE', array(), $curlyBrace);
     }
     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);
                 $phpcsFile->addEvent('XP_CLASS_DECLARATION_ONE_SPACE_BEFORE_OPENING_BRACE', array(), $curlyBrace);
             }
         }
     } else {
         //$error = "Expected 1 space before opening brace; 0 found";
         //$phpcsFile->addError($error, $curlyBrace);
         $phpcsFile->addEvent('XP_CLASS_DECLARATION_ONE_SPACE_BEFORE_OPENING_BRACE', array(), $curlyBrace);
     }
 }
开发者ID:Gamepay,项目名称:xp-contrib,代码行数:60,代码来源:ClassDeclarationSniff.php

示例2: process

 /**
  * Processes this test, when one of its tokens is encountered.
  *
  * @param  PHP_CodeSniffer_File $phpcsFile The file being scanned.
  * @param  integer              $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();
     $decName = $phpcsFile->findNext(T_STRING, $stackPtr);
     $fileName = dirname($phpcsFile->getFilename());
     $GnPosition = strrpos($fileName, DIRECTORY_SEPARATOR . 'GN');
     if (false === $GnPosition) {
         return;
     }
     $fileName = substr($fileName, $GnPosition + 1);
     $fileName .= DIRECTORY_SEPARATOR . basename($phpcsFile->getFilename());
     $fileName = substr($fileName, 0, strrpos($fileName, '.'));
     $className = $fileName;
     $className = substr($className, strpos($className, '_'));
     $className = substr($className, strpos($className, DIRECTORY_SEPARATOR) + 1);
     $fileName = str_replace(DIRECTORY_SEPARATOR, '_', $fileName);
     $className = str_replace(DIRECTORY_SEPARATOR, '_', $className);
     if (strpos($fileName, '__') === false) {
         $className = $fileName;
     }
     if ($tokens[$decName]['content'] !== $fileName and $tokens[$decName]['content'] !== $className) {
         $name = ucfirst($tokens[$stackPtr]['content']);
         $file .= '"' . $tokens[$stackPtr]['content'] . ' ' . $className . '".';
         $phpcsFile->addEvent('MATCH_CLASS_NAME', array('name' => $name, 'file' => $file), $stackPtr);
     }
 }
开发者ID:proofek,项目名称:SQLI_CodeSniffer,代码行数:34,代码来源:ClassFileNameSniff.php

示例3: process

 /**
  * Lance le sniff, lorsqu'un des types de segments est d�tect�
  *
  * @param PHP_CodeSniffer_File $phpcsFile Le fichier actuellement analys�.
  * @param int                  $stackPtr  La position du segment actuel dans la pile $tokens.
  *
  * @return void
  */
 public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
 {
     $tokens = $phpcsFile->getTokens();
     $operator = $tokens[$stackPtr]['content'];
     if ($tokens[$stackPtr - 1]['code'] === T_WHITESPACE) {
         $phpcsFile->addEvent('EXPECTED_SPACE_DECREMENTSPACING', array('operator' => $operator), $stackPtr);
     }
 }
开发者ID:proofek,项目名称:SQLI_CodeSniffer,代码行数:16,代码来源:IncrementDecrementSpacingSniff.php

示例4: 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']);
     // Interface names ends with Interface suffix
     if (strrpos($name, 'Interface') !== strlen($name) - strlen('Interface')) {
         $phpcsFile->addEvent('NAME_END_VALID_INTERFACE', array('name' => $name), $stackPtr);
     }
 }
开发者ID:proofek,项目名称:SQLI_CodeSniffer,代码行数:19,代码来源:ValidInterfaceNameSniff.php

示例5: process

 /**
  * Processes this test, when one of its tokens is encountered.
  *
  * @param  PHP_CodeSniffer_File $phpcsFile The file being scanned.
  * @param  integer              $stackPtr  The position of the current token
  *                                         in the stack passed in $tokens.
  * @return void
  */
 public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
 {
     // Check that this is the only class or interface in the file
     $stackPtr = $phpcsFile->findNext(array(T_CLASS, T_INTERFACE), $stackPtr + 1);
     if ($stackPtr !== false) {
         // We have another, so an error is thrown
         //$error = 'Only one interface or class is allowed in a file';
         //$phpcsFile->addError($error, $nextClass);
         $phpcsFile->addEvent('MULTIPLE_CLASS_OR_INTERFACE_IN_SINGLE_FILE', array(), $stackPtr);
     }
 }
开发者ID:proofek,项目名称:SQLI_CodeSniffer,代码行数:19,代码来源:ClassDeclarationSniff.php

示例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)
 {
     if (0 !== $stackPtr) {
         //$phpcsFile->addError('Extra content before open tag', $stackPtr);
         $phpcsFile->addEvent('XP_OPEN_TAG_EXTRA_CONTENT_BEFORE_OPEN_TAG', array(), $stackPtr);
     }
     $tokens = $phpcsFile->getTokens();
     $openTag = $tokens[$stackPtr];
     if ($openTag['content'] === '<?') {
         $error = 'Short PHP opening tag used. Found "' . $openTag['content'] . '" Expected "<?php".';
         //$phpcsFile->addError($error, $stackPtr);
         $phpcsFile->addEvent('XP_OPEN_TAG_SHORT_PHP_OPENING_TAG', array('message' => $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);
         $phpcsFile->addEvent('XP_OPEN_TAG_SHORT_PHP_OPENING_TAG_WITH_ECHO', array('message' => $error), $stackPtr);
     }
 }
开发者ID:Gamepay,项目名称:xp-contrib,代码行数:30,代码来源:OpenTagSniff.php

示例7: processMemberVar

 /**
  * Processes the function tokens within the class.
  *
  * @param PHP_CodeSniffer_File $phpcsFile The file where this token was found.
  * @param int                  $stackPtr  The position where the token was found.
  *
  * @return void
  */
 protected function processMemberVar(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
 {
     $tokens = $phpcsFile->getTokens();
     $modifier = $phpcsFile->findPrevious(PHP_CodeSniffer_Tokens::$scopeModifiers, $stackPtr, NULL, FALSE, NULL, TRUE);
     if ($modifier === false) {
         // || ($tokens[$modifier]['line'] !== $tokens[$stackPtr]['line'])) {
         $var = $tokens[$stackPtr]['content'];
         $error = 'Scope modifier not specified for member variable "' . $var . '"';
         //$phpcsFile->addError($error, $stackPtr);
         $phpcsFile->addEvent('XP_MEMBER_VAR_SCOPE_NOT_SPECIFIED', array('message' => $error), $stackPtr);
     }
 }
开发者ID:Gamepay,项目名称:xp-contrib,代码行数:20,代码来源:MemberVarScopeSniff.php

示例8: 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 the first letter is a capital.
     if (preg_match('|^[A-Z]|', $name) === 0) {
         $phpcsFile->addEvent('NAME_START_LETTER_VALID_CLASS', array('name' => ucfirst($tokens[$stackPtr]['content'])), $stackPtr);
     }
     // Check that each new word starts with a capital as well, but don't
     // check the first word, as it is checked above.
     $validName = true;
     $nameBits = explode('_', $name);
     $firstBit = array_shift($nameBits);
     foreach ($nameBits as $bit) {
         if ($bit === '' || $bit[0] !== strtoupper($bit[0])) {
             $validName = false;
             break;
         }
     }
     if ($validName !== true) {
         // Strip underscores because they cause the suggested name
         // to be incorrect.
         $nameBits = explode('_', trim($name, '_'));
         $firstBit = array_shift($nameBits);
         if ($firstBit === '') {
             $phpcsFile->addEvent('NAME_NOT_VALID_VALID_CLASS', array('name' => ucfirst($tokens[$stackPtr]['content'])), $stackPtr);
         } else {
             $newName = strtoupper($firstBit[0]) . substr($firstBit, 1) . '_';
             foreach ($nameBits as $bit) {
                 if ($bit !== '') {
                     $newName .= strtoupper($bit[0]) . substr($bit, 1) . '_';
                 }
             }
             $newName = rtrim($newName, '_');
             $phpcsFile->addEvent('NAME_NOT_VALID_NEWNAME_VALID_CLASS', array('name' => ucfirst($tokens[$stackPtr]['content']), 'newname' => $newName), $stackPtr);
         }
     }
     //end if
 }
开发者ID:proofek,项目名称:SQLI_CodeSniffer,代码行数:49,代码来源:ValidClassNameSniff.php

示例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 it's 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);
         $phpcsFile->addEvent('XP_SCOPE_CLOSING_BRACE_CLOSING_BRACE_MUST_BE_ON_A_LINE_BY_ITSELF', array('message' => $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 + 2) {
             $error = 'Break statement indented incorrectly; expected ' . ($startColumn + 1) . ' spaces, found ' . ($braceIndent - 1);
             //$phpcsFile->addError($error, $scopeEnd);
             $phpcsFile->addEvent('XP_SCOPE_CLOSING_BRACE_BREAK_STATEMENT_INDENTED_INCORRECTLY', array('message' => $error), $scopeEnd);
         }
     } else {
         if ($braceIndent !== $startColumn) {
             $error = 'Closing brace indented incorrectly; expected ' . ($startColumn - 1) . ' spaces, found ' . ($braceIndent - 1);
             //$phpcsFile->addError($error, $scopeEnd);
             $phpcsFile->addEvent('XP_SCOPE_CLOSING_BRACE_CLOSING_BRACE_INDENTED_INCORRECTLY', array('message' => $error), $scopeEnd);
         }
     }
 }
开发者ID:Gamepay,项目名称:xp-contrib,代码行数:60,代码来源:ScopeClosingBraceSniff.php

示例10: process

 /**
  * Processes this test, when one of its tokens is encountered
  *
  * @param  PHP_CodeSniffer_File $phpcsFile All the tokens found in the document
  * @param  integer              $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 it's own line.
     $lastContent = $phpcsFile->findPrevious(array(T_WHITESPACE), $scopeEnd - 1, $scopeStart, true);
     if ($tokens[$lastContent]['line'] === $tokens[$scopeEnd]['line']) {
         $phpcsFile->addEvent('ONELINE_SCOPE_CLOSINGBRACE', array('name' => ucfirst($tokens[$stackPtr]['content'])), $scopeEnd);
         return;
     }
     // SQLI ce qui suit ne nous intéresse pas dans ce contexte, de plus un nombre d'espaces est codé en dur
     //        // 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 and $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 ($braceIndent !== $startColumn) {
     //                $error = 'Closing brace indented incorrectly; expected ' . ($startColumn - 1)
     //                       . ' spaces, found ' . ($braceIndent - 1);
     //                $phpcsFile->addError($error, $scopeEnd);
     //            }
     //        }
 }
开发者ID:proofek,项目名称:SQLI_CodeSniffer,代码行数:57,代码来源:ScopeClosingBraceSniff.php

示例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)
 {
     $tokens = $phpcsFile->getTokens();
     // Check if there is a scope opening after a closing bracket
     if ($tokens[$stackPtr]['code'] == T_CLOSE_PARENTHESIS) {
         $check = $phpcsFile->findNext(T_WHITESPACE, $stackPtr + 1, NULL, TRUE);
         if ($tokens[$check]['code'] == T_OPEN_CURLY_BRACKET) {
             // var_dump($tokens[$check]);
         }
         return;
     }
     $nextToken = $tokens[$stackPtr + 1];
     if ($nextToken['code'] === T_WHITESPACE) {
     } else {
         $error = sprintf('Not enough whitespace after Keyword: %s', $tokens[$stackPtr]['content']);
         //$phpcsFile->addError($error, $stackPtr);
         $phpcsFile->addEvent('XP_WHITESPACE_AFTER_KEYWORD_MISSING', array('message' => $error), $stackPtr);
     }
 }
开发者ID:Gamepay,项目名称:xp-contrib,代码行数:28,代码来源:WhitespaceAfterKeywordSniff.php

示例12: 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();
     $functionName = $phpcsFile->findNext(array(T_STRING), $stackPtr);
     $openBracket = $tokens[$stackPtr]['parenthesis_opener'];
     $closeBracket = $tokens[$stackPtr]['parenthesis_closer'];
     $multiLine = $tokens[$openBracket]['line'] !== $tokens[$closeBracket]['line'];
     $nextParam = $openBracket;
     $params = array();
     while (($nextParam = $phpcsFile->findNext(T_VARIABLE, $nextParam + 1, $closeBracket)) !== false) {
         $nextToken = $phpcsFile->findNext(T_WHITESPACE, $nextParam + 1, $closeBracket + 1, true);
         if ($nextToken === false) {
             break;
         }
         $nextCode = $tokens[$nextToken]['code'];
         if ($nextCode === T_EQUAL) {
             // Check parameter default spacing.
             if ($nextToken - $nextParam > 1) {
                 //$gap   = strlen($tokens[($nextParam + 1)]['content']);
                 //$arg   = $tokens[$nextParam]['content'];
                 //$error = "Expected 0 spaces between argument \"$arg\" and equals sign; $gap found";
                 //$phpcsFile->addError($error, $nextToken);
                 $phpcsFile->addEvent('XP_FUNCTION_DECLARATION_ARGUMENT_SPACING_NOPSACE_BEFORE_EQUALS', array(), $nextToken);
             }
             if ($tokens[$nextToken + 1]['code'] === T_WHITESPACE && $tokens[$nextToken + 1]['content'] !== ' ') {
                 //$gap   = strlen($tokens[($nextToken + 1)]['content']);
                 //$arg   = $tokens[$nextParam]['content'];
                 //$error = "Expected 1 space between default value and equals sign for argument \"$arg\"; $gap found";
                 //$phpcsFile->addError($error, $nextToken);
                 $phpcsFile->addEvent('XP_FUNCTION_DECLARATION_ARGUMENT_SPACING_ONESPACE_AFTER_EQUALS', array(), $nextToken);
             }
             if ($tokens[$nextToken + 1]['code'] !== T_WHITESPACE) {
                 //$arg   = $tokens[$nextParam]['content'];
                 //$error = "Expected 1 space between default value and equals sign for argument \"$arg\"; 0 found";
                 //$phpcsFile->addError($error, $nextToken);
                 $phpcsFile->addEvent('XP_FUNCTION_DECLARATION_ARGUMENT_SPACING_ONESPACE_AFTER_EQUALS', array(), $nextToken);
             }
         }
         // Find and check the comma (if there is one).
         $nextComma = $phpcsFile->findNext(T_COMMA, $nextParam + 1, $closeBracket);
         if ($nextComma !== false) {
             // Comma found.
             if ($tokens[$nextComma - 1]['code'] === T_WHITESPACE) {
                 //$space = strlen($tokens[($nextComma - 1)]['content']);
                 //$arg   = $tokens[$nextParam]['content'];
                 //$error = "Expected 0 spaces between argument \"$arg\" and comma; $space found";
                 //$phpcsFile->addError($error, $nextToken);
                 $phpcsFile->addEvent('XP_FUNCTION_DECLARATION_ARGUMENT_SPACING_NOSPACE_BEFORE_COMMA', array(), $nextToken);
             }
         }
         // Take references into account when expecting the
         // location of whitespace.
         if ($phpcsFile->isReference($nextParam - 1) === true) {
             $whitespace = $tokens[$nextParam - 2];
         } else {
             $whitespace = $tokens[$nextParam - 1];
         }
         if (empty($params) === false) {
             // This is not the first argument in the function declaration.
             $arg = $tokens[$nextParam]['content'];
             if ($whitespace['code'] === T_WHITESPACE) {
                 $gap = strlen($whitespace['content']);
                 // Before we throw an error, make sure there is no type hint.
                 $comma = $phpcsFile->findPrevious(T_COMMA, $nextParam - 1);
                 $nextToken = $phpcsFile->findNext(T_WHITESPACE, $comma + 1, null, true);
                 if ($phpcsFile->isReference($nextToken) === true) {
                     $nextToken++;
                 }
                 if ($nextToken !== $nextParam) {
                     // There was a type hint, so check the spacing between
                     // the hint and the variable as well.
                     $hint = $tokens[$nextToken]['content'];
                     if ($gap !== 1) {
                         //$error = "Expected 1 space between type hint and argument \"$arg\"; $gap found";
                         //$phpcsFile->addError($error, $nextToken);
                         $phpcsFile->addEvent('XP_FUNCTION_DECLARATION_ARGUMENT_ONESPACE_AFTER_HINT', array(), $nextToken);
                     }
                     if ($multiLine === false) {
                         if ($tokens[$comma + 1]['code'] !== T_WHITESPACE) {
                             //$error = "Expected 1 space between comma and type hint \"$hint\"; 0 found";
                             //$phpcsFile->addError($error, $nextToken);
                             $phpcsFile->addEvent('XP_FUNCTION_DECLARATION_ARGUMENT_ONESPACE_BETWEEN_COMMA_AND_HINT', array(), $nextToken);
                         } else {
                             $gap = strlen($tokens[$comma + 1]['content']);
                             if ($gap !== 1) {
                                 //$error = "Expected 1 space between comma and type hint \"$hint\"; $gap found";
                                 //$phpcsFile->addError($error, $nextToken);
                                 $phpcsFile->addEvent('XP_FUNCTION_DECLARATION_ARGUMENT_ONESPACE_BETWEEN_COMMA_AND_HINT', array(), $nextToken);
                             }
                         }
                     }
//.........这里部分代码省略.........
开发者ID:Gamepay,项目名称:xp-contrib,代码行数:101,代码来源:FunctionDeclarationArgumentSpacingSniff.php

示例13: processVariableInString

 /**
  * Processes the variable found within a double quoted string
  *
  * @param  PHP_CodeSniffer_File $phpcsFile The file being scanned
  * @param  integer              $stackPtr  The position of the double quoted string
  * @return void
  */
 public function processVariableInString(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
 {
     $tokens = $phpcsFile->getTokens();
     $phpReservedVars = array('_SERVER', '_GET', '_POST', '_REQUEST', '_SESSION', '_ENV', '_COOKIE', '_FILES', 'GLOBALS');
     if (preg_match_all('|[^\\\\]\\$([a-zA-Z0-9_]+)|', $tokens[$stackPtr]['content'], $matches) !== 0) {
         foreach ($matches[1] as $varName) {
             // If it's a php reserved var, then its ok
             if (in_array($varName, $phpReservedVars) === true) {
                 continue;
             }
             // There is no way for us to know if the var is public or private, so we have to ignore a
             // leading underscore if there is one and just check the main part of the variable name
             $originalVarName = $varName;
             // SQLI : les premier caractère ne doit pas être un underscore
             //                if (substr($varName, 0, 1) === '_') {
             //                    if ($phpcsFile->hasCondition($stackPtr, array(T_CLASS, T_INTERFACE)) === true) {
             //                        $varName = substr($varName, 1);
             //                    }
             //                }
             if (PHP_CodeSniffer::isCamelCaps($varName, false, true, false) === false) {
                 $varName = $matches[0];
                 $phpcsFile->addEvent('NOT_VALID_CAMEL_VALID_VARIABLE', array('varname' => $varName), $stackPtr);
             } else {
                 if (preg_match('|\\d|', $varName)) {
                     $phpcsFile->addEvent('CONTAINS_NUMBER_VALID_VARIABLE', array('varname' => $varName), $stackPtr);
                 }
             }
         }
     }
 }
开发者ID:proofek,项目名称:SQLI_CodeSniffer,代码行数:37,代码来源:ValidVariableNameSniff.php

示例14: processParams

 /**
  * Process the function parameter comments.
  *
  * @param int $commentStart The position in the stack where
  *                          the comment started.
  *
  * @return void
  */
 protected function processParams($commentStart)
 {
     $realParams = $this->currentFile->getMethodParameters($this->_functionToken);
     $params = $this->commentParser->getParams();
     $foundParams = array();
     if (empty($params) === false) {
         $lastParm = count($params) - 1;
         /* if (substr_count($params[$lastParm]->getWhitespaceAfter(), $this->currentFile->eolChar) !== 2) {
                $error    = 'Last parameter comment requires a blank newline after it';
                $errorPos = ($params[$lastParm]->getLine() + $commentStart);
                $this->currentFile->addError($error, $errorPos);
            } */
         // Parameters must appear immediately after the comment.
         /*if ($params[0]->getOrder() !== 2) {
               $error    = 'Parameters must appear immediately after the comment';
               $errorPos = ($params[0]->getLine() + $commentStart);
               $this->currentFile->addError($error, $errorPos);
           } */
         $previousParam = null;
         $spaceBeforeVar = 10000;
         $spaceBeforeComment = 10000;
         $longestType = 0;
         $longestVar = 0;
         foreach ($params as $param) {
             $paramComment = trim($param->getComment());
             $errorPos = $param->getLine() + $commentStart;
             // Make sure that there is only one space before the var type.
             /* if ($param->getWhitespaceBeforeType() !== ' ') {
                    $error = 'Expected 1 space before variable type';
                    $this->currentFile->addError($error, $errorPos);
                } */
             $spaceCount = substr_count($param->getWhitespaceBeforeVarName(), ' ');
             if ($spaceCount < $spaceBeforeVar) {
                 $spaceBeforeVar = $spaceCount;
                 $longestType = $errorPos;
             }
             $spaceCount = substr_count($param->getWhitespaceBeforeComment(), ' ');
             if ($spaceCount < $spaceBeforeComment && $paramComment !== '') {
                 $spaceBeforeComment = $spaceCount;
                 $longestVar = $errorPos;
             }
             // Make sure they are in the correct order,
             // and have the correct name.
             $pos = $param->getPosition();
             $paramName = $param->getVarName() !== '' ? $param->getVarName() : '[ UNKNOWN ]';
             if ($previousParam !== null) {
                 $previousName = $previousParam->getVarName() !== '' ? $previousParam->getVarName() : 'UNKNOWN';
                 // Check to see if the parameters align properly.
                 /*if ($param->alignsVariableWith($previousParam) === false) {
                       $error = 'The variable names for parameters '.$previousName.' ('.($pos - 1).') and '.$paramName.' ('.$pos.') do not align';
                       $this->currentFile->addError($error, $errorPos);
                   }*/
                 /*if ($param->alignsCommentWith($previousParam) === false) {
                       $error = 'The comments for parameters '.$previousName.' ('.($pos - 1).') and '.$paramName.' ('.$pos.') do not align';
                       $this->currentFile->addError($error, $errorPos);
                   }*/
             }
             //end if
             // Make sure the names of the parameter comment matches the
             // actual parameter.
             if (isset($realParams[$pos - 1]) === true) {
                 $realName = substr($realParams[$pos - 1]['name'], 1);
                 $foundParams[] = $realName;
                 // Append ampersand to name if passing by reference.
                 /*if ($realParams[($pos - 1)]['pass_by_reference'] === true) {
                       $realName = '&'.$realName;
                   }*/
                 if ($realName !== $param->getVarName()) {
                     $error = 'Doc comment var "' . $paramName;
                     $error .= '" does not match actual variable name "' . $realName;
                     $error .= '" at position ' . $pos;
                     //$this->currentFile->addError($error, $errorPos);
                     $this->currentFile->addEvent('XP_FUNCTION_COMMENT_PARAM_NOMATCH', array('message' => $error), $errorPos);
                 }
             } else {
                 // We must have an extra parameter comment.
                 $error = 'Superfluous doc comment at position ' . $pos;
                 //$this->currentFile->addError($error, $errorPos);
                 $this->currentFile->addEvent('XP_FUNCTION_COMMENT_PARAM_SUPERFLUOUS', array('message' => $error), $errorPos);
             }
             if ($param->getVarName() === '') {
                 $error = 'Missing parameter name at position ' . $pos;
                 //$this->currentFile->addError($error, $errorPos);
                 $this->currentFile->addEvent('XP_FUNCTION_COMMENT_PARAM_MISSING_NAME', array('message' => $error), $errorPos);
             }
             // var_dump($realParams[($pos - 1)]['pass_by_reference']);
             if ($param->getType() === '') {
                 $error = 'Missing type at position ' . $pos;
                 //$this->currentFile->addError($error, $errorPos);
                 $this->currentFile->addEvent('XP_FUNCTION_COMMENT_PARAM_MISSING_TYPE', array('message' => $error), $errorPos);
             } else {
                 if ($realParams[$pos - 1]['pass_by_reference'] === FALSE && '&' === substr($param->getType(), 0, 1)) {
//.........这里部分代码省略.........
开发者ID:Gamepay,项目名称:xp-contrib,代码行数:101,代码来源:FunctionCommentSniff.php

示例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) {
             $phpcsFile->addEvent('NAME_INVALID_MAGIC_METHOD_VALID_FUNCTION', array('name' => $functionName), $stackPtr);
         }
         return;
     }
     // Function names can be in two parts; the package name and
     // the function name.
     //$packagePart   = '';
     $camelCapsPart = '';
     $underscorePos = strrpos($functionName, '_');
     if ($underscorePos === false) {
         $camelCapsPart = $functionName;
     } else {
         //$packagePart   = substr($functionName, 0, $underscorePos);
         $camelCapsPart = substr($functionName, $underscorePos + 1);
         // We don't care about _'s on the front.
         //$packagePart = ltrim($packagePart, '_');
     }
     // If it has a package part, make sure the first letter is a capital.
     //if ($packagePart !== '') {
     if ($functionName[0] === '_') {
         $phpcsFile->addEvent('NAME_INVALID_PRIVATE_METHOD_VALID_FUNCTION', array('name' => $functionName), $stackPtr);
         return;
     }
     /*
                 if ($functionName{0} !== strtoupper($functionName{0})) {
         $phpcsFile->addEvent(
             'NAME_PREFIXED_START_CAPITAL_LETTER_VALID_FUNCTION', 
             array('name' => $functionName),
             $stackPtr
         );        	
                     return;
                 }
     */
     //}
     // If it doesn't have a camel caps part, it's not valid.
     if (trim($camelCapsPart) === '') {
         $phpcsFile->addEvent('NAME_NOT_VALID_INCOMPLETE_VALID_FUNCTION', array('name' => $functionName), $stackPtr);
         return;
     }
     $validName = true;
     $newPackagePart = $packagePart;
     $newCamelCapsPart = $camelCapsPart;
     // Every function must have a camel caps part, so check that first.
     if (PHP_CodeSniffer::isCamelCaps($camelCapsPart, false, true, false) === false) {
         $validName = false;
         $newCamelCapsPart = strtolower($camelCapsPart[0]) . substr($camelCapsPart, 1);
     }
     if ($packagePart !== '') {
         // Check that each new word starts with a capital.
         $nameBits = explode('_', $packagePart);
         foreach ($nameBits as $bit) {
             if ($bit[0] !== strtoupper($bit[0])) {
                 $newPackagePart = '';
                 foreach ($nameBits as $bit) {
                     $newPackagePart .= strtoupper($bit[0]) . substr($bit, 1) . '_';
                 }
                 $validName = false;
                 break;
             }
         }
     }
     if ($validName === false) {
         $newName = rtrim($newPackagePart, '_') . '_' . $newCamelCapsPart;
         if ($newPackagePart === '') {
             $newName = $newCamelCapsPart;
         } else {
             $newName = rtrim($newPackagePart, '_') . '_' . $newCamelCapsPart;
         }
         $phpcsFile->addEvent('NAME_INVALID_CONSIDER_NEWNAME_VALID_FUNCTION', array('name' => $functionName, 'newname' => $newName), $stackPtr);
     }
 }
开发者ID:proofek,项目名称:SQLI_CodeSniffer,代码行数:87,代码来源:ValidFunctionNameSniff.php


注:本文中的PHP_CodeSniffer_File::addEvent方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。