Problem/Motivation
Remove unused variable $field_name from FieldDiscoveryTest.
foreach ($actual_fields['node'] as $bundle => $fields) {
foreach ($fields as $field_name => $field_info) {
$this->assertArrayHasKey('type', $field_info);
$this->assertCount(22, $field_info);
$this->assertEquals($bundle, $field_info['type_name']);
}
}
Steps to reproduce
Proposed resolution
Remaining tasks
Update patch to make the same change in \Drupal\Tests\migrate_drupal\Kernel\d7\FieldDiscoveryTest
Review
Commit
User interface changes
API changes
Data model changes
Release notes snippet
| Comment | File | Size | Author |
|---|---|---|---|
| #5 | interdiff_2-5.txt | 739 bytes | reenaraghavan |
| #5 | 3334910-5.patch | 1.76 KB | reenaraghavan |
| #2 | 3334910-2.patch | 897 bytes | diegors |
Issue fork drupal-3334910
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
diegorsDid the change, please review.
Comment #3
quietone commentedI looked at the patch to find out which FieldDiscoveryTest is being changed. I originally thought is was \Drupal\Tests\migrate_drupal\Unit\FieldDiscoveryTest but in fact it is one of the two Kernel test. The d6 one. I am now looking at the d7 test to see if it has the same unused variable. Yes, it does. The change was made to both in #2951550: Make service for field discovery for use in migrate entity derivers.
It is the same test file in both versions so this change should be made in both files in one patch.
Comment #5
reenaraghavan commentedComment #6
urvashi_vora commentedSetting it to Needs Review as @reenaraghavan provided another patch in #5.
I will review the patch.
Thanks
Comment #7
urvashi_vora commentedI reviewed the patch provided in #5.
It was applied cleanly.
Also with respect to comment #3
I can confirm that 3334910-5.patch changes FieldDiscoveryTest.php file in both Kernel tests, i.e for d6 as well as d7. And both file changes are made in one single patch.
To me, it looks good to be committed.
As per my humble opinion, Moving it to RTBC.
Please change the issue status if you find it unappropriate.
Thank You!
Comment #8
catchWe don't consider the $key in a foreach loop to be unused - neither phpstan nor phpcs will report it as such, so this is 'by design'. If we wanted to change that, it would need to come with a phpcs or phpstan rule and a patch that brings all of core into line with the new rule. Closing this one out.
Comment #9
jonathan1055 commentedI agree that this is 'closed works as designed' but just for completeness and accuracy, there is no special handling of the $key of a foreach in the Coder sniff
DrupalPractice.CodeAnalysis.VariableAnalysis.UnusedVariable. This sniff is active in core 10.1 and there are no unused $key variables in the main code, they are either used or the $key has been removed, see #3106216: Remove unused variables from core. If you edit a core file which has a foreach and add a $key which is not used, you do get:However, the reason why the problem in the issue summary was not reported by phpcs is that the high level parent sniff
DrupalPractice.CodeAnalysis.VariableAnalysisis excluded from running against any*/tests/*path. See core/phpcs.xml.dist line 148The issue #3310127: [META] Fix DrupalPractice best practice in Core covers the discussion on how best to include or ignore DrupalPractice sniffs in core