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
| Comment | File | Size | Author |
|---|---|---|---|
| #71 | interdiff-2080343-69-71.txt | 4.52 KB | connorwk |
| #71 | remove-unused-2080343-71.patch | 13.85 KB | connorwk |
| #69 | remove-unused-2080343-69.patch | 9.33 KB | connorwk |
| #64 | interdiff-2080343-61-64.txt | 2.58 KB | connorwk |
| #64 | remove-unused-2080343-64.patch | 13.16 KB | connorwk |
Comments
Comment #1
lokapujyaRemove an unused variable.
Comment #2
parthipanramesh commentedcan't apply patch
Comment #3
lokapujyaThe test moved to PHPUnitTest in #2130551: Convert system modules MimeTypeMatcherTest to phpunit, but we still have the unused variable.
Comment #4
lokapujyaComment #5
lokapujyaComment #7
lokapujya4: unused-local-variables-2080343-3.patch queued for re-testing.
Comment #8
areke commentedLooks good; the patch applies and removes the variable while keeping the test.
Comment #9
xjmPlease 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.
Comment #10
xjmPlease combine this patch with #2080343: Remove Unused local variables from system module.
Comment #11
xjmWhoops, I just closed this as a duplicate of itself. :D
Comment #12
lokapujyaComment #13
lokapujyaComment #14
lokapujyaincludes:
#2080117: Add assertion to Drupal/system/Tests/Database/DeleteTruncateTest.php
but not:
#2056445: Ensure that all config can not be deleted using the config importer (has a bug associated with it.)
#2080311: Clean up Drupal\system\Tests\Database\SelectTest.php (xjm asked for it to have a separate review)
Comment #15
lokapujyaBoth issues have already individually been RTBC. The latest patch combines the open "unused variables" tasks for the system module.
Comment #16
parthipanramesh commentedLooks good to me. Applies fine.
Comment #17
rahul.shindeUpdating title and adding some more files for update.
Comment #18
rahul.shindeAdding patch to be review.
@xjm, Please suggest if more needs to care.
Comment #20
lokapujyaraul.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.
Comment #21
rahul.shinde18: 2080343-18-work_arround_for_unused_variable.patch queued for re-testing.
Comment #22
rahul.shinde@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 :)
Comment #23
parthipanramesh commentedSorry but the latest patch doesn't apply..
Comment #24
lokapujya#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.
Comment #25
rahul.shinde@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.
Comment #26
lz1irq commentedReview 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.
Comment #27
lokapujyaOk, some other issues need to be combined.
Comment #28
lokapujyaComment #29
lokapujyaComment #30
lokapujyaComment #31
lokapujyaComment #32
lokapujyaProgrammaticTest.php and FrontPageTest.php changes are new changes. The other changes are patches applied from the "individual file" issues.
Comment #33
lokapujyaAlso, I removed this line.
Comment #34
lokapujyaComment #35
lokapujyaComment #36
lokapujyaanyone get a chance to review this before we have to re-roll again?
Comment #37
izus commentedhi,
i reviewed it and made a last check. i found some unused
usestatements.will upload a patch in minutes
Comment #38
izus commentedso here it is !
i deted unused use statements, extra unused variables and some extra semicolons !
Hopefully this goes green.
Comment #39
izus commentedComment #40
lokapujyaadding the interdiff.
Comment #41
lokapujyaI didn't create that interdiff correctly. Here is a redo.
Comment #42
lokapujyaizus, 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
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.
Comment #43
lokapujya#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.
Comment #44
lokapujyaComment #45
lokapujyaSpawned a new issue #2187477: Remove Unused use statements from system module for the unused use statements.
Comment #46
yesct commentedcorrected info about which issue would handle MimeTypeMatcherTest
Comment #47
lokapujya38: 2080343-38.patch queued for re-testing.
Comment #49
lokapujya32: 2080343-32.patch queued for re-testing.
Comment #50
lokapujyaComment #52
lokapujyaComment #53
lokapujyaComment #54
lokapujyaReroll.
Comment #55
lokapujya54: 2080343-54.patch queued for re-testing.
Comment #57
lokapujyaRerolled.
Comment #59
lokapujya$routes in the RouteBuilderTest is actually used now, so it shouldn't be removed. Fixed.
Comment #60
yesct commentedI 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?
Comment #61
connorwk commentedJust rerolled this patch.
Still needs a full review.
Comment #62
sunThese lines should not be touched by this patch.
Comment #63
connorwk commentedI 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.
Comment #64
connorwk commentedRemoved 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.
Comment #65
connorwk commentedSetting to needs review to see what the testbot says while I continue to work.
Comment #67
sunThose lines are changing the static
$batchvariable 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.Comment #68
lokapujya@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.
Comment #69
connorwk commentedSo 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.
Comment #70
lokapujyaCheck 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.
Comment #71
connorwk commentedI 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.
Comment #72
lokapujyaThe interdiff removes some unused variables that were added after the original patch was made.
Comment #73
webchickCommitted and pushed to 8.x. Thanks!