Problem/Motivation
In #3106216: Remove unused variables from core we introduced the sniff DrupalPractice.CodeAnalysis.VariableAnalysis to detect unused variables in Drupal Core.
To narrow the scope the decision was made to exclude all the test-classes.
This issue is created to make that sniff run without errors on all test-classes.
Steps to reproduce
Proposed resolution
Fix reported errors in Kernel and Unit tests
Remaining tasks
Careful review of the changes to core/modules/migrate/tests/src/Unit/MigrateExecutableTest.php, especially where it is testing an a thrown exception.
User interface changes
API changes
Data model changes
Release notes snippet
| Comment | File | Size | Author |
|---|
Issue fork drupal-3251754
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
spokjePostponed on #3106216: Remove unused variables from core
Comment #3
longwaveThe parent issue is committed so this can be worked on now.
Comment #4
spokjeComment #6
spokjeThanks @tstoeckler for the On-The-Fly review :)
Comment #7
spokjeComment #8
longwaveA few more comments, mostly things that look like they can be removed entirely now.
Comment #9
tstoecklerNo problem, and thanks for the fixes, looking pretty close now 👍
Comment #10
spokjeComment #11
daffie commentedThe MR looks good.
Comment #12
spokjeThanks @longwave and @daffie for their eagled-eyed reviews.
Comment #13
spokjeComment #14
daffie commentedAll the code changes look good to me.
The file core/phpcs.xml.dist has the exclude-pattern removed.
The testbot is happy.
For me it is RTBC.
Comment #15
longwaveRTBC +1
Comment #16
alexpottThis needs to go on 10.0.x first.
Comment #17
spokjeOk...
What's the reasoning behind that, and would that reasoning apply to all RTBC-ed Coding standards issues?
Comment #18
alexpott@Spokje everything has to go into 10.x first because otherwise there is a future Drupal without this fixed. And yes it applies to all coding standards patches currently rtbc.
Comment #19
spokjeThanks for clearing that up.
I'm sure somebody else would love to keep RTBCed coding standards up to date with the ever moving core releases for months, I've done so for a few issues that were RTBC for 2 months and longer. I'm not keen on doing that again for 2+ months for the D10 version and then the needs-a-backport D9.4.x version.
If those changes are too big, too disruptive, no fun to look through, fine with me, but then there should be a ruling about how big/how many changes a MR/patch can have as a maximum, because this seems now like a lot of time that would be more usefully spend elsewhere.
_drops EUR 0.02 and all Coding standards issue_
Comment #20
longwaveReuploading patch for 9.4.x, rerolled for 10.0.x.
Comment #21
longwaveNW following #3174402: Fix unused variable $unpublished in TrackerTest.php
Also not sure why PHPStan is failing on AssertHelperTraitTest, maybe a symptom of #3259355: Always do a full phpstan analysis on DrupalCI?
Comment #22
mallezieTesting if phpstan causes the problem here.
Comment #23
malleziePHPstan gives same result on both partial and full scan.
In our phpstan config we have
excludePaths:
# Skip test fixtures.
- */tests/fixtures/*.php
This skips the AssertHelperTestClass class.
Comment #24
mallezieComment #25
mondrakeAssertHelperTraitTest and the fixture will anyway be removed with #3261266: Remove deprecated code from the testing framework (base classes, listeners, etc), so we may want to postpone this on that
Comment #26
alexpottThis is no longer unused.
Comment #30
quietone commentedClosed #3338899: Remove unused variables [$resource,$key] from ResourceTest as a duplicate, adding credit.
Adding parent.
Comment #31
quietone commentedDiscussed this longwave and they suggested a different parent. I am changing the parent now. I will add a comment to the previous parent since this is using a sniff.
Comment #32
quietone commentedChange parent to the meta implementing this sniff.
Comment #34
quietone commentedWhile working on this I found two tests that seem to have lost test coverage from earlier changes. Because of that and the size of this was growing I decided to split this up.
Comment #35
quietone commentedThere is an error on core/modules/views/tests/src/Unit/Controller/ViewAjaxControllerTest.php
because setupValidMocks has a return type hint of array but it does not return an array. It returns a mock. Changed in #3458427: Add array return typehints to protected test helper methods
Comment #37
quietone commentedComment #38
smustgrave commentedAppears to be a pretty valid open question.
When I opened the current implementation of core/modules/field/tests/src/Unit/Plugin/migrate/process/d6/FieldInstanceSettingsTest.php I actually see that $migration is flagged as an unused variable
Comment #39
quietone commentedComment #40
smustgrave commentedBelieve feedback has been addressed for this one.
Comment #41
longwaveNW for some additional removals and also a question about the configuration file.
Comment #42
quietone commentedThanks for the reviews.
Comment #43
smustgrave commentedRemoved the suggestions, had to re-run tests 2 times for random failures.
Comment #44
alexpottCommitted 0635e0d and pushed to 11.x. Thanks!