You are here

public function Drupal_CommentParser_ParameterElement::__construct in Coder 7.2

Constructs a Drupal_CommentParser_ParameterElement.

Parameters

PHP_CodeSniffer_CommentParser_DocElement $previousElement The element: previous to this one.

array $tokens The tokens: that make up this element.

PHP_CodeSniffer_File $phpcsFile The file that: this element is in.

File

coder_sniffer/Drupal/CommentParser/ParameterElement.php, line 37

Class

Drupal_CommentParser_ParameterElement
A class to represent param tags within a function comment.

Code

public function __construct($previousElement, $tokens, PHP_CodeSniffer_File $phpcsFile) {

  // Handle the case when a parameter type is missing.
  // If the first non-whitespace token starts with "$", then the type is
  // missing.
  if ($tokens[1][0] === '$') {

    // Insert two fake tokens for the parameter type.
    array_unshift($tokens, 'unknown');
    array_unshift($tokens, ' ');
    parent::__construct($previousElement, $tokens, $phpcsFile);

    // Now empty the type so it will be flagged as invalid.
    $this
      ->processSubElement('type', '', ' ');
  }
  else {
    if ($tokens[1] === '...') {

      // Insert two fake tokens for the parameter type.
      array_unshift($tokens, 'unknown');
      array_unshift($tokens, ' ');
      parent::__construct($previousElement, $tokens, $phpcsFile);
    }
    else {
      parent::__construct($previousElement, $tokens, $phpcsFile);
    }
  }
}