Part of meta-issue #2002650: [meta, no patch] improve maintainability by removing unused local variables

In this Patch:
/core/modules/system/lib/Drupal/system/Tests/Ajax/ElementValidationTest.php
Line 31 Unused variable $web_user.
Line 35 Unused variable $post_result.
Line 44 Unused variable $post_result.

/core/modules/system/lib/Drupal/system/Tests/Database/DatabaseTestBase.php
Line 79: Unused variable $ringo.

/core/modules/system/lib/Drupal/system/Tests/Database/SelectOrderedTest.php
Line 28: Unused variable $name_field.
Line 49: Unused variable $name_field.
Line 80: Unused variable $name_field.

/core/modules/system/lib/Drupal/system/Tests/Form/ProgrammaticTest.php
Line 38: Unused variable $batch.

/core/modules/system/lib/Drupal/system/Tests/Lock/LockFunctionalTest.php
Line 63: Unused variable $lock_not_acquired_exit.

/core/modules/system/lib/Drupal/system/Tests/System/FrontPageTest.php
Line 55: Unused variable $node.

The following will be handled by separate issues:
File /core/modules/system/lib/Drupal/system/Tests/Routing/MimeTypeMatcherTest.php
Line 91: Unused local variable $routes
Moved to core/tests in #2130551: Convert system modules MimeTypeMatcherTest to phpunit
To be handled in #2081153: Remove unused local variables from core/tests

/core/modules/system/lib/Drupal/system/SystemConfigSubscriber.php
Line 33 Unused variable $importList.
Open issue #2056445: Ensure that all config can not be deleted using the config importer

/core/modules/system/lib/Drupal/system/Tests/Database/SelectTest.php
Line 28: Unused variable $name_field.
Line 29: Unused variable $age_field.
Line 45: Unused variable $name_field.
Line 46: Unused variable $age_field.
Line 66: Unused variable $name_field.
Line 67: Unused variable $age_field.
Line 71: Unused variable $record.

Open issue #2080311: Clean up Drupal\system\Tests\Database\SelectTest.php

Comments

lokapujya’s picture

Assigned: Unassigned » lokapujya
Status: Active » Needs review
StatusFileSize
new759 bytes

Remove an unused variable.

parthipanramesh’s picture

Issue summary: View changes
Status: Needs review » Needs work

can't apply patch

lokapujya’s picture

The test moved to PHPUnitTest in #2130551: Convert system modules MimeTypeMatcherTest to phpunit, but we still have the unused variable.

lokapujya’s picture

StatusFileSize
new643 bytes
lokapujya’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 4: unused-local-variables-2080343-3.patch, failed testing.

lokapujya’s picture

Status: Needs work » Needs review
areke’s picture

Status: Needs review » Reviewed & tested by the community

Looks good; the patch applies and removes the variable while keeping the test.

xjm’s picture

Title: Remove Unused local variable $routes from /core/modules/system/lib/Drupal/system/Tests/Routing/MimeTypeMatcherTest.php » Remove Unused local variables from system.module
Priority: Normal » Minor
Status: Reviewed & tested by the community » Needs work

Please roll all system.module local variable removals into one patch, and confirm that all unused local variables are removed from the module directory before RTBCing. Also, these issues should be filed as minor.

xjm’s picture

Status: Needs work » Closed (duplicate)
Related issues: +#2080343: Remove Unused local variables from system module
xjm’s picture

Status: Closed (duplicate) » Needs work
Related issues: -#2080343: Remove Unused local variables from system module

Whoops, I just closed this as a duplicate of itself. :D

lokapujya’s picture

Issue summary: View changes
lokapujya’s picture

Issue summary: View changes
lokapujya’s picture

Status: Needs work » Needs review
StatusFileSize
new1.28 KB
lokapujya’s picture

Both issues have already individually been RTBC. The latest patch combines the open "unused variables" tasks for the system module.

parthipanramesh’s picture

Status: Needs review » Reviewed & tested by the community

Looks good to me. Applies fine.

rahul.shinde’s picture

Title: Remove Unused local variables from system.module » Remove Unused local variables from system module
Assigned: lokapujya » rahul.shinde
Issue summary: View changes
Status: Reviewed & tested by the community » Needs work

Updating title and adding some more files for update.

rahul.shinde’s picture

Status: Needs work » Needs review
StatusFileSize
new9.2 KB

Adding patch to be review.
@xjm, Please suggest if more needs to care.

Status: Needs review » Needs work

The last submitted patch, 18: 2080343-18-work_arround_for_unused_variable.patch, failed testing.

lokapujya’s picture

raul.shinde, those issues should to be reviewed separately since they are more complicated. If you agree with that plan, please set this back to RTBC.

rahul.shinde’s picture

Status: Needs work » Needs review
rahul.shinde’s picture

@lokapujya, As per @xjm we should take care all variables in one place. So i did. You suggest the way that we can work upon. I don;t have any problem in any case :)

parthipanramesh’s picture

Status: Needs review » Needs work

Sorry but the latest patch doesn't apply..

lokapujya’s picture

Assigned: rahul.shinde » lokapujya
Status: Needs work » Needs review

#2080117: Add assertion to Drupal/system/Tests/Database/DeleteTruncateTest.php was committed. So #4 is the one to review.

The other 2 issues should not be combined, see comment #14.

rahul.shinde’s picture

@lokapujya, i think we are loosing on the issue title here. @xjm, please pitch in here n throws some suggestion, thought #14 says much but the title says other thing.

lz1irq’s picture

Review for the latest patch

The patch seems to be secure. Fields are checked for errors and unexpected content. No sign of 'smells'. Code is not duplicated and its very purpose is to make the codebase more efficient in which it succeeds. There are no tests provided but as far as I know, the change is not unit testable (since this is the essence of the patch, I do not count this as a 'smell'). The patch applies cleanly (as of commit 588e6783d29759b66d22651285b9e2c49640b345) and fixes the issue.

lokapujya’s picture

Issue summary: View changes
Status: Needs review » Needs work

Ok, some other issues need to be combined.

lokapujya’s picture

Issue summary: View changes
lokapujya’s picture

Title: Remove Unused local variables from system module » Remove Unused local variables from system module (except changes that fix bugs)
Issue summary: View changes
lokapujya’s picture

Title: Remove Unused local variables from system module (except changes that fix bugs) » Remove Unused local variables from system module
Issue summary: View changes
lokapujya’s picture

Issue summary: View changes
lokapujya’s picture

Status: Needs work » Needs review
StatusFileSize
new11.6 KB

ProgrammaticTest.php and FrontPageTest.php changes are new changes. The other changes are patches applied from the "individual file" issues.

lokapujya’s picture

+++ b/core/modules/system/lib/Drupal/system/Tests/Ajax/ElementValidationTest.php
@@ -28,11 +28,10 @@ public static function getInfo() {
-    $web_user = $this->drupalCreateUser();

Also, I removed this line.

lokapujya’s picture

Issue summary: View changes
lokapujya’s picture

Issue summary: View changes
lokapujya’s picture

Assigned: lokapujya » Unassigned

anyone get a chance to review this before we have to re-roll again?

izus’s picture

Status: Needs review » Needs work

hi,
i reviewed it and made a last check. i found some unused use statements.
will upload a patch in minutes

izus’s picture

StatusFileSize
new35.71 KB

so here it is !
i deted unused use statements, extra unused variables and some extra semicolons !
Hopefully this goes green.

izus’s picture

Status: Needs work » Needs review
lokapujya’s picture

StatusFileSize
new35.71 KB

adding the interdiff.

lokapujya’s picture

StatusFileSize
new24.1 KB

I didn't create that interdiff correctly. Here is a redo.

lokapujya’s picture

izus, those extra unused variable are being handled in other issues (that are not RTBC'd) mentioned in the issue summary, specifically:
/core/modules/system/lib/Drupal/system/SystemConfigSubscriber.php
/core/modules/system/lib/Drupal/system/Tests/Database/SelectTest.php

+++ b/core/modules/system/entity.api.php
@@ -355,11 +355,13 @@ function hook_entity_translation_insert(\Drupal\Core\Entity\EntityInterface $tra
-  $variables = array(
-    '@language' => $languages[$langcode]->name,
-    '@label' => $entity->label(),
-  );
-  watchdog('example', 'The @language translation of @label has just been deleted.', $variables);
+  foreach ($languages as $langcode => $entity) {
+    $variables = array(
+      '@language' => $languages[$langcode]->name,
+      '@label' => $entity->label(),
+    );
+    watchdog('example', 'The @language translation of @label has just been deleted.', $variables);
+  }

This change is bug fix, and should be filed as a separate issue.

I think that the unused use statements is out of scope and should be done in another issue.

lokapujya’s picture

#2056445: Ensure that all config can not be deleted using the config importer is RTBC'd and #2080311: Clean up Drupal\system\Tests\Database\SelectTest.php is active, so we don't need those changes in this patch. So, I think patch #32 is still the one to review.

Perhaps the unused use statements and extra semicolons from #38 can be a new issue.

lokapujya’s picture

Assigned: Unassigned » lokapujya
lokapujya’s picture

Spawned a new issue #2187477: Remove Unused use statements from system module for the unused use statements.

yesct’s picture

Issue summary: View changes

corrected info about which issue would handle MimeTypeMatcherTest

lokapujya’s picture

38: 2080343-38.patch queued for re-testing.

Status: Needs review » Needs work

The last submitted patch, 38: 2080343-38.patch, failed testing.

lokapujya’s picture

32: 2080343-32.patch queued for re-testing.

lokapujya’s picture

The last submitted patch, 32: 2080343-32.patch, failed testing.

lokapujya’s picture

lokapujya’s picture

lokapujya’s picture

Status: Needs work » Needs review
StatusFileSize
new11.6 KB

Reroll.

lokapujya’s picture

54: 2080343-54.patch queued for re-testing.

Status: Needs review » Needs work

The last submitted patch, 54: 2080343-54.patch, failed testing.

lokapujya’s picture

Status: Needs work » Needs review
StatusFileSize
new11.61 KB

Rerolled.

Status: Needs review » Needs work

The last submitted patch, 57: 2080343-57.patch, failed testing.

lokapujya’s picture

Status: Needs work » Needs review
StatusFileSize
new10.97 KB

$routes in the RouteBuilderTest is actually used now, so it shouldn't be removed. Fixed.

yesct’s picture

I gave this a quick look. Nothing worrying jumps out.

In terms of a review, i think what this needs is:
someone to look at the vars that are removed and
*think* about if the values should have been used:

should we have tested the results of the functions?

Were there conditions we were missing or asserts we might have wanted to do?

connorwk’s picture

StatusFileSize
new10.58 KB

Just rerolled this patch.
Still needs a full review.

sun’s picture

Status: Needs review » Needs work
+++ b/core/modules/system/src/Tests/Form/ProgrammaticTest.php
   function testSubmissionWorkflow() {
-    // Backup the current batch status and reset it to avoid conflicts while
-    // processing the dummy form submit handler.
-    $current_batch = $batch =& batch_get();
-    $batch = array();
...
-    // Restore the current batch status.
-    $batch = $current_batch;

These lines should not be touched by this patch.

connorwk’s picture

I noticed phpStorm was saying that these variables are used, but I noticed they are unused anywhere else in the function.

I realized that these lines are tricking phpStorm into thinking they are used because they are using each other.
If there is another explanation for why these should not be removed then please explain.

Removing them does not make the patch fail during testing. If they really need to be there that means we are missing an assertion.

I agree with the change to needs work though as there are still a ton of unused variables.
I'll be working on that now.

connorwk’s picture

StatusFileSize
new13.16 KB
new2.58 KB

Removed all the unused files in just one file so far.
I found an example of how to fix the unused $key in a foreach loop here: #2080309: Remove Unused local variable $record from /core/modules/system/lib/Drupal/system/Tests/Database/AlterTest.php
That's how I fixed it here.
Still working on this patch though.

connorwk’s picture

Status: Needs work » Needs review

Setting to needs review to see what the testbot says while I continue to work.

Status: Needs review » Needs work

The last submitted patch, 64: remove-unused-2080343-64.patch, failed testing.

sun’s picture

Component: other » system.module

Those lines are changing the static $batch variable by reference, so as to account for a potential batch being started by the subsequently following form submission. That's a functional change, out of scope for this issue.

lokapujya’s picture

@connork: The changes that you added in #64 are already taken care of in this issue: #2080311: Clean up Drupal\system\Tests\Database\SelectTest.php.

Also, I agree with Sun that the change in #62 should be removed from this patch. $batch is not an unused variable, it's a reference variable.

connorwk’s picture

StatusFileSize
new9.33 KB

So I went back to the reroll patch I made, added back in the $batch code and since I went back to the reroll the changes I made having to do with #2080311: Clean up Drupal\system\Tests\Database\SelectTest.php has been reverted as-well.
Now I'll work on the rest of the module.

lokapujya’s picture

Check the issue summary under "The following will be handled by separate issues:". A couple other issues take care of some of the other unused variables that may be the same as the ones you are seeing. The reason they are in a separate issue is that those changes fixed bugs and need more thorough review.

connorwk’s picture

Status: Needs work » Needs review
StatusFileSize
new13.85 KB
new4.52 KB

I removed some unused variables that look obvious but the rest look as if they may be needed for asserts or tests that haven't been completed.
It's honestly a bit over my head so I think I'll leave it at this.
I'll set it to needs review so that my patches can be tested.

lokapujya’s picture

Assigned: lokapujya » Unassigned
Status: Needs review » Reviewed & tested by the community

The interdiff removes some unused variables that were added after the original patch was made.

webchick’s picture

Status: Reviewed & tested by the community » Fixed

Committed and pushed to 8.x. Thanks!

  • Commit d8505d2 on 8.x by webchick:
    Issue #2080343 by connork, izus, rahul.shinde, lokapujya | mrsinguyen:...

Status: Fixed » Closed (fixed)

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