You are here

public function Drupal_Sniffs_CSS_ClassDefinitionOpeningBraceSpaceSniff::process in Coder 7.2

Processes the tokens that this sniff is interested in.

Parameters

PHP_CodeSniffer_File $phpcsFile The file where the token was found.:

int $stackPtr The position in the stack where: the token was found.

Return value

void

File

coder_sniffer/Drupal/Sniffs/CSS/ClassDefinitionOpeningBraceSpaceSniff.php, line 53

Class

Drupal_Sniffs_CSS_ClassDefinitionOpeningBraceSpaceSniff
Ensure there is a single space before the opening brace in a class definition and the content starts on the next line. Copied from Squiz_Sniffs_CSS_ClassDefinitionOpeningBraceSpaceSniff.

Code

public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) {
  $tokens = $phpcsFile
    ->getTokens();
  if ($tokens[$stackPtr - 1]['code'] !== T_WHITESPACE) {
    $error = 'Expected 1 space before opening brace of class definition; 0 found';
    $phpcsFile
      ->addError($error, $stackPtr, 'NoneBefore');
  }
  else {
    $content = $tokens[$stackPtr - 1]['content'];
    if ($content !== ' ') {
      $length = strlen($content);
      if ($length === 1) {
        $length = 'tab';
      }
      $error = 'Expected 1 space before opening brace of class definition; %s found';
      $data = array(
        $length,
      );
      $phpcsFile
        ->addError($error, $stackPtr, 'Before', $data);
    }
  }

  //end if
  $end = $tokens[$stackPtr]['bracket_closer'];

  // Do not check nested style definitions as, for example, in @media style rules.
  $nested = $phpcsFile
    ->findNext(T_OPEN_CURLY_BRACKET, $stackPtr + 1, $end);
  if ($nested !== false) {
    return;
  }
  $next = $phpcsFile
    ->findNext(T_WHITESPACE, $stackPtr + 1, null, true);
  if ($next !== false && $tokens[$next]['line'] !== $tokens[$stackPtr]['line'] + 1) {
    $error = 'Expected exactly one new line after opening brace of class definition';
    $phpcsFile
      ->addError($error, $stackPtr, 'After');
  }
}