You are here

class FormStateInputSniff in Coder 8.2

Same name and namespace in other branches
  1. 8.3 coder_sniffer/DrupalPractice/Sniffs/General/FormStateInputSniff.php \DrupalPractice\Sniffs\General\FormStateInputSniff
  2. 8.3.x coder_sniffer/DrupalPractice/Sniffs/General/FormStateInputSniff.php \DrupalPractice\Sniffs\General\FormStateInputSniff

Throws a message whenever $form_state['input'] is used. $form_state['values'] is preferred.

@category PHP @package PHP_CodeSniffer @link http://pear.php.net/package/PHP_CodeSniffer

Hierarchy

  • class \DrupalPractice\Sniffs\General\FormStateInputSniff implements \PHP_CodeSniffer\Sniffs\Sniff

Expanded class hierarchy of FormStateInputSniff

File

coder_sniffer/DrupalPractice/Sniffs/General/FormStateInputSniff.php, line 23

Namespace

DrupalPractice\Sniffs\General
View source
class FormStateInputSniff implements Sniff {

  /**
   * Returns an array of tokens this test wants to listen for.
   *
   * @return array
   */
  public function register() {
    return array(
      T_VARIABLE,
    );
  }

  //end register()

  /**
   * Processes this test, when one of its tokens is encountered.
   *
   * @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned.
   * @param int                         $stackPtr  The position of the function
   *                                               name in the stack.
   *
   * @return void
   */
  public function process(File $phpcsFile, $stackPtr) {
    if ($phpcsFile
      ->getTokensAsString($stackPtr, 4) === '$form_state[\'input\']' || $phpcsFile
      ->getTokensAsString($stackPtr, 4) === '$form_state["input"]') {
      $warning = 'Do not use the raw $form_state[\'input\'], use $form_state[\'values\'] instead where possible';
      $phpcsFile
        ->addWarning($warning, $stackPtr, 'Input');
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
FormStateInputSniff::process public function Processes this test, when one of its tokens is encountered.
FormStateInputSniff::register public function Returns an array of tokens this test wants to listen for.