Part of meta-issue #2002650: [meta, no patch] improve maintainability by removing unused local variables
File /core/modules/system/lib/Drupal/system/Tests/Database/SelectTest.php
Line 28: Unused local variable $name_field
Line 29: Unused local variable $age_field
Line 33: Unused local variable $record
Line 45: Unused local variable $name_field
Line 46: Unused local variable $age_field
Line 50: Unused local variable $record
Line 66: Unused local variable $name_field
Line 67: Unused local variable $age_field
Line 71: Unused local variable $record
Comment | File | Size | Author |
---|---|---|---|
#34 | interdiff-2080311-30-34.txt | 1.45 KB | amitgoyal |
#34 | removed-unused-variables-2080311-34.patch | 2.8 KB | amitgoyal |
Comments
Comment #1
chertzogClosing the following as duplicates:
#2080113: Remove Unused local variable $plugin_id from /core/modules/system/lib/Drupal/system/Tests/Plugin/CacheDecoratorLanguageTest.php
#2080115: Remove Unused local variable $cached from /core/modules/system/lib/Drupal/system/Tests/Cache/GenericCacheBackendUnitTestBase.php
#2080117: Add assertion to Drupal/system/Tests/Database/DeleteTruncateTest.php
#2080119: Remove Unused local variable $result from /core/modules/system/lib/Drupal/system/Tests/Database/InsertDefaultsTest.php
#2080121: Remove Unused local variable $ringo from /core/modules/system/lib/Drupal/system/Tests/Database/DatabaseTestBase.php
#2080317: Remove Unused local variable $task_field from /core/modules/system/lib/Drupal/system/Tests/Database/SelectComplexTest.php
#2080289: Remove Unused local variable $name_field from /core/modules/system/lib/Drupal/system/Tests/Database/SelectOrderedTest.php
#2080291: Remove Unused local variable $john from /core/modules/system/lib/Drupal/system/Tests/Database/CaseSensitivityTest.php
#2080295: Remove Unused local variable $ret from /core/modules/system/lib/Drupal/system/Tests/Database/SchemaTest.php
#2080299: Remove Unused local variable $record from /core/tests/Drupal/Tests/Core/Database/EmptyStatementTest.php
#2080303: Remove Unused local variable $log from /core/modules/system/lib/Drupal/system/Tests/Database/LoggingTest.php
#2080305: Remove Unused local variable $records from /core/modules/system/lib/Drupal/system/Tests/Database/FetchTest.php
#2080309: Remove Unused local variable $record from /core/modules/system/lib/Drupal/system/Tests/Database/AlterTest.php
Comment #2
chertzogComment #4
chertzogComment #5
rhm5000 CreditAttribution: rhm5000 commentedNoticed some code that is using a while or for loop:
Example One
Example two
to perform what the count function does. Updated patch with count function.
Comment #7
rhm5000 CreditAttribution: rhm5000 commented#5: 2080311-remove-unused-local-variables-5.patch queued for re-testing.
Comment #9
pfrenssenWhy did you lump all these separate issues together like this? This greatly complicates the review process.
Comment #10
angel.hAlthough sometimes joining issues is effective, the issues closed as duplicates shouldn't have been closed for the following reasons:
0. It is easier for new people to start contributing to core with simple tasks which include changing one file and a few lines.
1. It's much easier to review them.
2. Sometimes small changes can lead to bigger complications, for example the code might now need test (see #2072597: Remove Unused local variables from tests in the Views module).
This has been discussed with YesCT at the core sprint at DrupalCon Prague.
For these reasons I'll return the issues to their previous status.
This issue should be done only regarding the file it concerns.
Comment #11
rhm5000 CreditAttribution: rhm5000 commentedAddressing #10. Patch addressing issue #2080311 separately.
Comment #12
pfrenssenThe unused $record variables were not yet removed. Removed them in this patch.
Comment #14
rhm5000 CreditAttribution: rhm5000 commented#12: 2080311-remove-unused-local-12.patch queued for re-testing.
Comment #15
areke CreditAttribution: areke commentedThe patch from #12 looks good; it keeps the tests while removing the unused variables and effectively gets rid of useless while loops. RTBC.
Comment #16
chx CreditAttribution: chx commentedThis, however, removes the actual counting of records and relies on rowCount working properly. Do we test that?
Comment #17
YesCT CreditAttribution: YesCT commentedmaybe we should use an approach like in #5: count($result) ?
Comment #18
chx CreditAttribution: chx commentedSounds a plan to me. You could do even do both the rowCount and the count() to test rowCount() while at it.
Comment #19
areke CreditAttribution: areke commentedHow's this?
Comment #21
xjmPlease combine this patch with #2080343: Remove Unused local variables from system module.
Comment #22
xjmActually this looks like another one that could stand to have its own separate review. Thanks!
Comment #23
Rajesh Ashok CreditAttribution: Rajesh Ashok commentedTested via Netbeans. Currently there are no unused variables at Drupal\system\Tests\Database\SelectTest.php So closing this issue.
Comment #24
Rajesh Ashok CreditAttribution: Rajesh Ashok commentedSorry, made a mistake there and so reopening the issue.
Comment #25
Rajesh Ashok CreditAttribution: Rajesh Ashok commentedAs per #10, I have fixed only unused variables in Drupal\system\Tests\Database\SelectTest.php
As per #16, I did not replace the code with rowCount function to get number of records returned by the query.
ie. Did not replace the following code with rowCount function
Comment #28
InternetDevels CreditAttribution: InternetDevels commentedI've changed "while" cycles to the count and added "fetchAll". First I've planned to use rowCount() but according to this issue: #2146733: Select queries should not use rowCount() to calculate number of rows it shouldn't be used for "Select" queries.
Comment #29
amitgoyal CreditAttribution: amitgoyal commentedThe patch no longer applies as the file core/modules/system/lib/Drupal/system/Tests/Database/SelectTest.php does not exist there.
Comment #30
natemow CreditAttribution: natemow commentedRe-rolled patch per new drupal/core/modules/system/src/Tests/Database/SelectTest.php path.
Comment #31
natemow CreditAttribution: natemow commentedComment #32
amitgoyal CreditAttribution: amitgoyal commented#30 looks good to me.
Comment #33
alexpott$num_records is now an weird name $records would be better.
Comment #34
amitgoyal CreditAttribution: amitgoyal commentedPlease review updated patch with fixes in #33.
Comment #35
cedricpriestley CreditAttribution: cedricpriestley commentedThis patch still applies.
Comment #36
dawehnerLooks nice!
Comment #37
alexpottCommitted 7fe5f2a and pushed to 8.x. Thanks!