You are here

function coder_upgrade_upgrade_call_user_authenticate_alter in Coder 7

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

Implements hook_upgrade_call_user_authenticate_alter().

File

coder_upgrade/conversions/call.inc, line 2630
Provides conversion routines applied to function calls.

Code

function coder_upgrade_upgrade_call_user_authenticate_alter(&$node, &$reader) {

  // DONE
  // Create helper objects.
  $editor = PGPEditor::getInstance();

  // Get the function call object.
  $item =& $node->data;

  // Process function call.
  $name =& $item->name;
  $count = $item->parameters
    ->count();
  if ($count == 0) {
    $editor
      ->setParameters($item, array(
      '$name',
      '$password /* TODO Set these variables */',
    ));
    return;
  }

  /*
   * Two cases:
   * - parameter is an array expression: extract values to use as new
   *   parameters
   * - parameter is a variable expression (not an array): assume the
   *   variable has name and pass as elements
   */
  $p0 = $item
    ->getParameter();
  $operand = $p0
    ->getElement();
  $class = get_class($operand);
  if ($class == 'PGPOperand') {

    // Get the variable name used as the parameter.
    $parameter = $item
      ->printParameter();

    // Make variable assignments referring to two new parameters.
    $assign1 = $editor
      ->textToStatements('$name = ' . $parameter . "['name']; // TODO Set these variables");
    $assign2 = $editor
      ->textToStatements('$password = ' . $parameter . "['pass'];")
      ->getElement(0);
    cdp($assign1
      ->print_r());

    // Insert the assignments before this statement.
    // Get the statement (i.e. node) this function call is part of.
    $parent =& $item->parent;

    // Get the statement list the parent is part of.
    $container =& $parent->container;

    // Insert statements.
    $container
      ->insertListBefore($parent, $assign1, 'assignment');
    $container
      ->insertBefore($parent, $assign2, 'assignment');

    // Set the parameters on this function call.
    $editor
      ->setParameters($item, array(
      '$name',
      '$password',
    ));
  }
  elseif ($class == 'PGPArray') {
    $name = $operand
      ->findValue('name')
      ->toString();
    $password = $operand
      ->findValue('pass')
      ->toString();

    // Set the parameters on this function call.
    $editor
      ->setParameters($item, array(
      $name,
      $password,
    ));
  }
}