function coder_upgrade_convert_return_loop_OLD in Coder 7
Same name and namespace in other branches
- 7.2 coder_upgrade/conversions/tool.inc \coder_upgrade_convert_return_loop_OLD()
1 call to coder_upgrade_convert_return_loop_OLD()
- coder_upgrade_convert_return_OLD in coder_upgrade/
conversions/ tool.inc - Initiates the transformation of array assignments in a hook.
File
- coder_upgrade/
conversions/ tool.inc, line 534 - Provides tools to assist with conversion routines.
Code
function coder_upgrade_convert_return_loop_OLD(&$node, &$count, $return_variable, $hook, $callback = '') {
// NOT DONE
cdp("inside " . __FUNCTION__);
is_object($node->data) ? cdp($node->data
->toString(), __FUNCTION__ . ' $node') : cdp($node->data, __FUNCTION__ . ' $node');
/*
* Loop on body statements until we find an assignment to the return variable.
* The assignment could be to an array element like $info['node_type_name'] = array(...).
* Or directly to the variable like $info = array('node_type_name' => array(...)).
*/
$current = $node;
while ($current->next != NULL) {
if (is_object($current->data) && $current->data->type == T_ASSIGNMENT) {
// if ($current->data->isType(T_ASSIGNMENT)) {
$assignment = $current->data;
$assign_variable = $assignment->values
->getElement()
->getElement()
->stripComments()
->toString();
if ($return_variable == $assign_variable) {
// Use case 2: makes one assignment to array variable; returns variable.
cdp("Use case 2: Assignment variable matches return variable");
/*
* TODO This equality check would fail if comments are embedded between
* variable and operator.
* Example: $theme /**\/ = $array + array(..);
*/
$value1 = $assignment->values
->getElement();
/*
* TODO Find the operand of class PGPArray.
* Example: $theme /**\/ = $array + array(..);
*/
$array1 = $value1
->getElement($value1
->count() - 1);
if (!is_object($current->data) || get_class($array1) != 'PGPArray') {
continue;
}
coder_upgrade_callback_return_case1($array1, $hook, $callback);
$count++;
}
elseif (strpos($assign_variable, $return_variable) !== FALSE) {
// Use case 3: makes multiple assignments to array variable; returns variable.
cdp("Use case 3: Assignment variable includes return variable");
/*
* TODO This substring check would fail if comments are embedded between
* variable and operator.
* Example: $theme /**\/ = $array + array(..);
*/
$assign_variable2 = $assignment->values
->getElement()
->getElement()
->stripComments();
$value1 = $assignment->values
->getElement();
if ($assign_variable2
->countType('index') == 1) {
cdp('variable has one index');
$array1 = $value1
->getElement($value1
->count() - 1);
coder_upgrade_callback_return_case3($array1, $hook, $callback);
$count++;
}
elseif ($assign_variable2
->countType('index') == 2) {
cdp('variable has two indices');
/*
* TODO Use case 5
* Assignment to array variable at an index
* $items[$admin_path] = array_merge($default_menu_fields, $menu_item);
* $items[$admin_path]['page callback'][] = 'example_admin_form';
* We need to count the indices; check for last index == []
* The second index is usually the item to be inspected
*/
$key2 = $assign_variable2
->getType('index', 2);
coder_upgrade_callback_return_case5($assignment, $hook, $callback);
}
elseif ($assign_variable2
->countType('index') == 3 && $assign_variable2
->getType('index', 3)
->toString() == '') {
cdp('variable has three indices');
/*
* TODO Use case 5
* Assignment to array variable at an index
* $items[$admin_path] = array_merge($default_menu_fields, $menu_item);
* $items[$admin_path]['page callback'][] = 'example_admin_form';
* We need to count the indices; check for last index == []
* The second index is usually the item to be inspected
*/
$key2 = $assign_variable2
->getType('index', 2);
coder_upgrade_callback_return_case5($assignment, $hook, $callback);
}
else {
clp("ERROR: Assignment variable has more than three index levels");
cdp("ERROR: Assignment variable has more than three index levels");
cdp($assign_variable2
->getType('index', 3)
->toString());
}
}
}
elseif (is_object($current->data) && in_array(get_class($current->data), array(
'PGPConditional',
'PGPFor',
'PGPForeach',
'PGPCase',
))) {
// elseif (is_a($current->data, 'PGPConditional')) {
coder_upgrade_convert_return_loop($current->data->body
->first(), $count, $return_variable, $hook, $callback);
}
else {
cdp('fell thru conditions in ' . __FUNCTION__);
is_object($current->data) ? cdp($current->data
->toString(), __FUNCTION__ . ' $current') : cdp($current->data, __FUNCTION__ . ' $current');
}
$current = $current->next;
}
}