CommentFileSizeAuthor
#22 2604830-22.patch6.31 KBjoelpittet
#2 2604830.patch18.05 KBheykarthikwithu

Comments

heykarthikwithu created an issue. See original summary.

heykarthikwithu’s picture

StatusFileSize
new18.05 KB

removed the unused variables in the code, added a patch for this.

heykarthikwithu’s picture

Assigned: heykarthikwithu » Unassigned
Status: Active » Needs review
heykarthikwithu’s picture

Title: Removal of unused variables through out the module. » Code cleanup, remove unused variables through out the module.
Priority: Normal » Minor
danchadwick’s picture

Have you tested each of these?

I assume this patch was created using some sort of linter. Linters cannot do a complete analysis of PHP. For example, you can refer to a variable with another variable, in the form $$my_variable_reference. Each of these changes needs to be individually looked at and tested.

I someone does that, I'd be happy to commit this. It's a LOT of work.

heykarthikwithu’s picture

yes this was tested, and this was a manual review of code, any how using a IDE for to do this.

danchadwick’s picture

Can you elaborate on how you tested this?

heykarthikwithu’s picture

 function _webform_render_email($component, $value = NULL, $filter = TRUE, $submission = NULL) {
-  global $user;
   $node = isset($component['nid']) ? node_load($component['nid']) : NULL;

$user variable is not used anymore inside the function.

   foreach (element_children($element['types']) as $filtergroup) {
-    $row = array();
-    $first_row = count($rows);
     if ($element['types'][$filtergroup]['#type'] == 'checkboxes') {

$row and $first_row variables are not used anymore inside the function.

-  $component = $element['#webform_component'];
   $format = $element['#format'];

$component is not used anymore inside the fucntion.

-  foreach ($element['#grid_questions'] as $question_key => $question) {
+  foreach ($element['#grid_questions'] as $question) {

$question_key is not used inside the foreach loop.

-    foreach ($value as $key => $option_value) {
+    foreach ($value as $option_value) {

$key is not used inside the foreach loop.

 function webform_validate_time($element, $form_state) {
-  $form_key = $element['#webform_component']['form_key'];

$form_key varible is not used in the function.

 function theme_webform_components_page($variables) {
-  $node = $variables['node'];
   $form = $variables['form'];

$node variable is not used inside the function.

-    foreach ($duplicates as $form_key => $cids) {
+    foreach ($duplicates as $cids) {

$form_key variable is not more used inside the function.

-  foreach ($node->webform['components'] as $cid => $component) {
+  foreach ($node->webform['components'] as $component) {

$cid is not used inside the foreach loop.

-  $query = db_insert('webform_component')
+  db_insert('webform_component')

$query variable is not used anymore in further code, so this can be removed.

-    $delete_conditional = FALSE;
     $specs = array(

$delete_conditional variable is not used inside the function.

-    foreach ($node->webform['components'] as $cid => $child_component) {
+    foreach ($node->webform['components'] as $child_component) {
-  foreach ($form_state['values']['conditionals'] as $key => $conditional) {
+  foreach ($form_state['values']['conditionals'] as $conditional) {

$cid and $key variables are no more used inside the foreach.

   $parents = $button['#parents'];
-  $action = array_pop($parents);

$action variable is not used in further code.

 function webform_email_delete_form($form, $form_state, $node, $email) {
-  $eid = $email['eid'];

$eid variable is no more used inside the fucction.

-  $components = $variables['components'];
   $submissions = $variables['submissions'];
   $total_count = $variables['total_count'];
   $pager_count = $variables['pager_count'];
 
-  $header = array();

$components and $header variable are no more used inside the fucntion.

-  foreach ($submissions as $sid => $submission) {
+  foreach ($submissions as $submission) {

$sid variable is not used in the foreach.

   $data = $variables['data'];
-  $sids = $variables['sids'];
   $analysis_component = $variables['component'];

$sids variable is no more used inside the function.

-  foreach ($emails as $eid => $email) {
+  foreach ($emails as $email) {
-      foreach ($conditional['actions'] as $aid => $action) {
+      foreach ($conditional['actions'] as $action) 

$eid and $aid variables are not used inside the foreach.

         $conditional = $conditionals[$conditional_spec['rgid']];
-        $conditional_result = TRUE;
 function webform_views_autocomplete($string = '') {
-  $matches = array();

$conditional_result and $matches variables are no more used inside the function.

-          foreach ($submission_node->webform['components'] as $sub_cid => $sub_component) {
+          foreach ($submission_node->webform['components'] as $sub_component) 
-    foreach ($this->submissions as $sid => $submission) {
+    foreach ($this->submissions as $submission) {
-  foreach ($items as $key => $item) {
+  foreach ($items as $item) {
-  foreach ($options['components'] as $key => &$component) {
+  foreach ($options['components'] as &$component) {
-    foreach ($node->webform['components'] as $cid => $component) {
+    foreach ($node->webform['components'] as $component) {
-    foreach ($node->webform['components'] as $cid => $component) {
+    foreach ($node->webform['components'] as $component) {
-    foreach ($node->webform['emails'] as $eid => $email) {
+    foreach ($node->webform['emails'] as $email) {
-  foreach ($node->webform['components'] as $cid => $component) {
+  foreach ($node->webform['components'] as $component) {

$sub_cid, $sid, $key, $cid, $eid, $cid variables are no more used inside their foreach loops.

 function webform_block_view($delta = '') {
-  global $user;
 function webform_client_form_prevalidate($form, &$form_state) {
-  global $user;

$user varible is no more used inside the function.

-  foreach ($text_tokens as $type => $tokens) {
+  foreach ($text_tokens as $tokens) {
-  foreach ($node->webform['components'] as $cid => $component) {
+  foreach ($node->webform['components'] as $component) {
-    foreach ($node->webform['components'] as $cid => $component) {
+    foreach ($node->webform['components'] as $component) {

$type, $cid variables are no more used inside the foreach.

danchadwick’s picture

I get that. But I never commit anything by just reading the code. I actually test it either with an automated test (seldom) or manually usually). It would be silly to introduce a regressing just to pretty up the code.

Also, some of the foreach index variables make the code self-documenting. cid for example.

heykarthikwithu’s picture

Checked manually by debugging the code where all i found the unused variables, and confirmed the few variables are no more used inside the function.

joelpittet’s picture

This looks good. @DanChadwick maybe it would be easier if it was one type of variable clean up at a time?

  1. global $user; unused.
  2. array Key unused.
  3. The rest
heykarthikwithu’s picture

Priority: Minor » Normal
Issue tags: +unused variables
danchadwick’s picture

Priority: Normal » Minor
Issue tags: -unused variables

@joelpittet -- When you say "this looks good", are you saying that you're reviewed it sufficiently to commit? I hesitate to commit a big patch like this without someone (not me) personally testing every change. Also, I'm plus/minus on removing the unused foreach keys. They provide valuable documentation to future maintainers. We could just remove them, we could add a comment, or we could leave them. I'm not sure what's best.

joelpittet’s picture

re #13 @DanChadwick I usually mark it RTBC if review it entirely. I was wondering how to best break this change up to make it easier to review the way you'd like it.

joelpittet’s picture

Status: Needs review » Needs work
  1. +++ b/components/file.inc
    @@ -300,8 +300,6 @@ function theme_webform_edit_file_extensions($variables) {
    -    $row = array();
    

    This variable needs to stay as it initializes each loop.

  2. +++ b/includes/webform.conditionals.inc
    @@ -558,7 +557,6 @@ function webform_conditional_element_add($form, &$form_state) {
    -  $action = array_pop($parents);
    

    array_pop will modify the $parents array. While the $action variable may not be needed the array_pop is needed for sure.

Read through all of them, there are two that are wrong, all the others are correct. I'll leave the decision about the foreach unused key variables up to @DanChadwick but I lean towards leaving them alone.

liam morland’s picture

Patch no longer applies. Please re-roll and take into account the issues mentioned in #15. Let's leave alone the unused foreach variables.

liam morland’s picture

It would be easier to review if different kinds of changes were made in separate patches.

liam morland’s picture

Are you still interested in working on this?

joelpittet’s picture

Assigned: Unassigned » joelpittet

@Liam Morland I am, don't mind rerolling this.

joelpittet’s picture

Title: Code cleanup, remove unused variables through out the module. » Code cleanup - Remove unused variables through out the module.
liam morland’s picture

Title: Code cleanup - Remove unused variables through out the module. » Code cleanup: Remove unused variables throughout the module
joelpittet’s picture

Status: Needs work » Needs review
StatusFileSize
new6.31 KB

Addressed my notes from #15, and removed all foreach as indicated in #16 and rerolled.

joelpittet’s picture

Assigned: joelpittet » Unassigned

liam morland’s picture

Status: Needs review » Fixed

Thanks very much!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.