Problem/Motivation
Part of meta-issue #2002650: [meta, no patch] improve maintainability by removing unused local variables
When this issue was originally opened it listed a number of unused local variables. They have been removed via patches in other issues. The remaining unused variables are:
File core/modules/node/lib/Drupal/node/NodeForm.php
(previously named NodeFormController.php)
Line 325: Unused variable $account.
File core/modules/node/lib/Drupal/node/Tests/NodeSaveTest.php
Line 92: Unused variable $changed.
File core/modules/node/lib/Drupal/node/Tests/NodeTypePersistenceTest.php
Line 32: Unused variable $forum_disable.
Proposed resolution
Patch in #56 removes the last few unused local variables to resolve the issue.
Remaining tasks
User interface changes
None.
API changes
None.
Original report by @jlindsey15
File /core/modules/node/lib/Drupal/node/Tests/NodeSaveTest.php
Line 92: Unused local variable $changed
File core/modules/node/lib/Drupal/node/NodeFormController.php
Line 325: Unused variable $account.
File core/modules/node/lib/Drupal/node/Tests/NodeSaveTest.php
Line 92: Unused variable $changed.
File core/modules/node/node.tokens.inc
Line 136: Unused variable $field_langcode.
File core/modules/node/lib/Drupal/node/Tests/NodeTypePersistenceTest.php
Line 32: Unused variable $forum_disable.
File core/modules/node/lib/Drupal/node/Tests/NodeTokenReplaceTest.php
Line 47: Unused variable $instance.
Line 95: Unused variable $instance.
File core/modules/node/lib/Drupal/node/Plugin/Search/NodeSearch.php
Line 408: Unused variable $node_types.
Comment | File | Size | Author |
---|---|---|---|
#56 | remove-unused-2064639-56.patch | 1.89 KB | connorwk |
#53 | remove-unused-2064639.53.patch | 2.81 KB | martin107 |
#51 | interdiff.txt | 667 bytes | jayeshanandani |
#51 | 2064639.51.patch | 3.46 KB | jayeshanandani |
#44 | 2064639-remove-unused-vars-node-44.patch | 2.81 KB | longwave |
Comments
Comment #1
jlindsey15 CreditAttribution: jlindsey15 commentedComment #2
jlindsey15 CreditAttribution: jlindsey15 commentedComment #4
jlindsey15 CreditAttribution: jlindsey15 commented#1: unused-local-variables-2064639-1.patch queued for re-testing.
Comment #5
sergeypavlenko CreditAttribution: sergeypavlenko commentedAll is well.
Comment #6
webchickActually, in this case, I wonder if this is actually highlighting a missing test below? And if not, then we should adjust the comment above because we are no longer preserving timestampS.
Comment #7
akshaan CreditAttribution: akshaan commentedComment #8
CarlHinton CreditAttribution: CarlHinton commentedSimply removing the s would resolve #6
Comment #9
CarlHinton CreditAttribution: CarlHinton commentedA patch matching #8 is attached
Comment #10
rhm5000 CreditAttribution: rhm5000 commentedComment #11
Anonymous (not verified) CreditAttribution: Anonymous commented#9 still applies OK however as @webchick suggests in comment #6 I wonder if this is missing a test. The code is as follows:
The proposed test would be:
Also perhaps I am not understanding node_presave but I am unsure as to whether the code directly following the above does do what it is intended to do as we are already using $node and just changing the title:
Comment #12
Anonymous (not verified) CreditAttribution: Anonymous commentedHere's a patch for what I'm suggesting in #11
Comment #14
Anonymous (not verified) CreditAttribution: Anonymous commentedOK I'm stuck on this as I can't figure out how to change something as my tests keep breaking locally - perhaps this is why the $change was not used as they had similar problems.
Comment #15
rahul.shindeComment #16
rahul.shindePatch re-rolled.
Comment #17
rahul.shindeComment #19
xjmPlease check that all other unused local variables are removed from the node module as well, and add those to this patch.
Comment #20
rahul.shindeComment #21
rahul.shinde@xjm, I'll be looking into other unused variables. I missed out your comment before uploading patch.
Comment #22
rahul.shindeAdding patch for test queue.
Comment #23
xjmThanks @rahul.shinde!
Comment #24
rahul.shindeComment #25
rahul.shindeComment #26
rahul.shinde@xjm, Adding patch to remove/update unused variables for node module.
Comment #27
Anonymous (not verified) CreditAttribution: Anonymous commentedI have just tested this patch and it applies cleanly to latest HEAD.
Before applying the patch node module has six unused variables, after it has zero so does the job.
Comment #28
parthipanramesh CreditAttribution: parthipanramesh commentedWorks. Thank you very much!
Comment #29
webchickThanks; this is close... however, it's not clear to me why 979534800 was chosen as the comparison value here:
Does replacing 979534800 with $node->getUpdatedTime() per stevepurkiss in #11 not work?
Comment #30
webchickComment #31
superspring CreditAttribution: superspring commentedI've changed the "979534800" line of code as it isn't actually testing anything.
Comment #33
Anonymous (not verified) CreditAttribution: Anonymous commentedI have read this again and again but unsure what to do to resolve. Thought I'd post in case you thought I was ignoring - am not, just unsure how to progress.
Comment #34
InternetDevels CreditAttribution: InternetDevels commentedProblem is this check:
this check can't be performed here, because preSave uses REQUEST_TIME for 'changed' property update and this constant does not change during request.
So we need to move this check to another test or change logic of the preSave() method and use time() instead.
In the attached patch I simply removed this check.
Comment #35
InternetDevels CreditAttribution: InternetDevels commentedOops, I've attached wrong files.
Comment #36
Anonymous (not verified) CreditAttribution: Anonymous commentedas part of the toronto sprint we reviewed the patch in comment #35 - all identified unused local variables have been removed.
looks good.
Comment #37
alexpottnode-remove-unused-variables-2064639-35.patch no longer applies.
Comment #38
Salah Messaoud CreditAttribution: Salah Messaoud commentedrerolled
Comment #39
alexpottNot need for this empty line :)
Comment #40
Salah Messaoud CreditAttribution: Salah Messaoud commentedSorry I didn't notice the extra line, I fixed it and added interdiff
Comment #41
sandipmkhairnar CreditAttribution: sandipmkhairnar commentedThanks Salah. I have tested patch and its working fine for me.
Comment #42
vlad.n CreditAttribution: vlad.n commentedRerolled. This patch applies cleanly at commit 428d0f0.
Comment #44
longwaveComment #46
longwaveA casualty of #2174997: Random fail in ImageFieldDisplayTest
44: 2064639-remove-unused-vars-node-44.patch queued for re-testing.
Comment #47
longwaveComment #48
andrei.dincu CreditAttribution: andrei.dincu commentedI have removed unused variables from the following files:
File core/modules/node/lib/Drupal/node/NodeFormController.php
Line 325: Unused variable $account.
File core/modules/node/lib/Drupal/node/NodeFormController.php
Line 325: Unused variable $account.
File core/modules/node/lib/Drupal/node/Tests/NodeTypePersistenceTest.php
Line 32: Unused variable $forum_disable.
File core/modules/node/node.tokens.inc
Line 136: Unused variable $field_langcode.
Comment #49
martin107 CreditAttribution: martin107 commentedproviding interdiff .. all looks ok maybe other committed patch has fix identical issues.
Comment #50
droplet CreditAttribution: droplet commentedone more ?
Location file [drupal8x] - ...\core\modules\node\lib\Drupal\node\Controller\NodeController.php Problem synopsis Unused local variable $uri (at line 132)
Comment #51
jayeshanandani CreditAttribution: jayeshanandani commentedRemoved Unused local variable $uri (at line 132) at core\modules\node\lib\Drupal\node\Controller\NodeController.php.
Comment #52
LinL CreditAttribution: LinL commentedPatch no longer applies, tagging for reroll.
Comment #53
martin107 CreditAttribution: martin107 commentedreroll ( Change: The removed variable in NodeController.php has already beeen removed in HEAD )
Comment #54
andrei.dincu CreditAttribution: andrei.dincu commentedPatch applied cleanly.
Rerolled done.
Comment #55
martin107 CreditAttribution: martin107 commentedComment #56
connorwk CreditAttribution: connorwk commentedRe-rolled because of:
PSR-4
#2116363: Unified repository of field definitions (cache + API) removed one of the unused variables a previous patch removed in node.token.inc
#2238077: Rename EntityFormController to EntityForm renamed one of the files that had an unused variable (NodeFormController.php to NodeForm.php)
I'm unsure why but phpStorm doesn't say that $account is an unused variable although it clearly is and was removed with a previous patch. This line is in NodeForm.php line 312 if anyone else wants to check it out.
- if (!empty($form_state['values']['uid']) && !($account = user_load_by_name($form_state['values']['uid']))) {
+ if (!empty($form_state['values']['uid']) && !user_load_by_name($form_state['values']['uid'])) {
All the unused variables in the node module seem to be removed now via phpStorm's inspect code on the node module.
My first patch at the Austin sprint!
Comment #57
alimac CreditAttribution: alimac commentedI ran Inspect Code in PhpStorm on latest of 8.x. It found 2 unused local variables: $forum_enable, $created.
I applied the patch from #56 and ran Inspect Code again. This time it did not find any unused local variables. So, it looks to me that the patch works and does what it's supposed to.
Comment #58
alimac CreditAttribution: alimac commentedMarking as RTBC.
Comment #59
alimac CreditAttribution: alimac commentedComment #60
alexpottCommitted 5417fcf and pushed to 8.x. Thanks!