You are here

function coder_upgrade_convert_install_file_comment in Coder 7

Same name and namespace in other branches
  1. 7.2 coder_upgrade/conversions/install.inc \coder_upgrade_convert_install_file_comment()

Adds a Doxygen style comment to install files.

Install files must include a Doxygen style file comment.

Parameters

PGPReader $reader: The object containing the grammar statements of the file to convert.

1 call to coder_upgrade_convert_install_file_comment()
coder_upgrade_upgrade_parser_install_alter in coder_upgrade/conversions/install.inc
Implements hook_upgrade_parser_install_alter().

File

coder_upgrade/conversions/install.inc, line 43
Provides conversion routines applied to install files.

Code

function coder_upgrade_convert_install_file_comment(&$reader) {
  cdp("inside " . __FUNCTION__);
  $comments =& $reader
    ->getComments();
  foreach ($comments as &$comment) {
    if (is_array($comment) && !empty($comment)) {
      if (preg_match('#\\*\\s*@file#', $comment['value'])) {

        // The file already includes a file comment.
        return;
      }
    }
  }

  /*
   * A standards-compliant Drupal php file would begin with:
   * <?php
   * // $\Id: .. username Exp $ (slash added to prevent CVS from changing this line)
   *
   * ... rest of file
   *
   * Look for these types of statements in this order. Insert the file
   * comment after the Id line or the open tag (if no Id line).
   */
  $statements =& $reader
    ->getStatements();
  if (is_null($statements)) {

    // Currently, the file must begin with an open tag.
    return;
  }

  /*
    $statement = $statements->getElement(0);
    if (!is_array($statement) || empty($statement) || $statement['type'] != T_OPEN_TAG) {
      clp('ERROR: file does not begin with an open tag');
      return;
    }
  */
  $statement = $statements
    ->getElement(1);
  if (!is_array($statement) || empty($statement) || $statement['type'] != T_COMMENT || strpos($statement['value'], '// $Id:') !== 0) {
    $position = 1;
    coder_upgrade_add_install_file_comment($reader, $position);
    return;
  }
  $statement = $statements
    ->getElement(2);
  if (!is_array($statement) || empty($statement) || $statement['type'] != T_WHITESPACE) {
    $position = 2;
    coder_upgrade_add_install_file_comment($reader, $position);
    return;
  }
  $position = 3;
  coder_upgrade_add_install_file_comment($reader, $position);
}