You are here

public function Drupal_Sniffs_Classes_ClassCreateInstanceSniff::process in Coder 7.2

Processes this test, when one of its tokens is encountered.

Parameters

PHP_CodeSniffer_File $phpcsFile The file being scanned.:

int $stackPtr The position of the current token in the: stack passed in $tokens.

Return value

void

File

coder_sniffer/Drupal/Sniffs/Classes/ClassCreateInstanceSniff.php, line 50

Class

Drupal_Sniffs_Classes_ClassCreateInstanceSniff
Class create instance Test.

Code

public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) {
  $tokens = $phpcsFile
    ->getTokens();
  $nextParenthesis = $phpcsFile
    ->findNext(array(
    T_OPEN_PARENTHESIS,
    T_SEMICOLON,
  ), $stackPtr, null, false, null, true);
  if ($tokens[$nextParenthesis]['code'] != T_OPEN_PARENTHESIS || $tokens[$nextParenthesis]['line'] != $tokens[$stackPtr]['line']) {
    $error = 'Calling class constructors must always include parentheses';
    $phpcsFile
      ->addError($error, $nextParenthesis);
    return;
  }
  if ($tokens[$nextParenthesis - 1]['code'] == T_WHITESPACE) {
    $error = 'Between the class name and the opening parenthesis spaces are not welcome';
    $phpcsFile
      ->addError($error, $nextParenthesis - 1);
    return;
  }
}