Part of meta-issue #2002650: [meta, no patch] improve maintainability by removing unused local variables

File /core/modules/views/lib/Drupal/views/Plugin/views/field/FieldPluginBase.php

Line 855: Unused local variable $arg
Line 1470: Unused local variable $arg

Merged with:

#2072597-17: Remove Unused local variables from tests in the Views module (this issue, comment #17)
File /core/modules/views/lib/Drupal/views/Plugin/views/argument_validator/Entity.php

Line 173: Unused local variable $ids

#2072597-17: Remove Unused local variables from tests in the Views module (this issue, comment #17)
File /core/modules/views/lib/Drupal/views/Tests/Plugin/StyleTableUnitTest.php

Line 132: Unused local variable $style_plugin

#2072601: Remove Unused local variable $count from /core/modules/views/lib/Drupal/views/Plugin/views/area/Result.php
File /core/modules/views/lib/Drupal/views/Plugin/views/area/Result.php

Line 71: Unused local variable $count
Line 75: Unused local variable $label
Line 77: Unused local variable $page_count
Line 82: Unused local variable $page_count
Line 90: Unused local variable $current_record_count

#2072613: Remove Unused local variable $view from /core/modules/views/lib/Drupal/views/Tests/ViewStorageTest.php
File /core/modules/views/lib/Drupal/views/Tests/ViewStorageTest.php

Line 222: Unused local variable $view

#2072617: Remove Unused local variable $base from /core/modules/views/lib/Drupal/views/Tests/Handler/FieldWebTest.php
File /core/modules/views/lib/Drupal/views/Tests/Handler/FieldWebTest.php

Line 207: Unused local variable $base
Line 208: Unused local variable $absolute_string
Line 232: Unused local variable $expected_result
Line 234: Unused local variable $result

Beta phase evaluation

Reference: https://www.drupal.org/core/beta-changes
Issue priority Normal because nothing is broken.
Unfrozen changes Unfrozen because this issue improves automated tests, performance, and DX.
CommentFileSizeAuthor
#88 remove-unused-2072597-88.patch2.48 KBtkuldeep17
#85 remove-unused-2072597-85.patch2.35 KBjgeryk
#80 remove-unused-2072597-80.patch1.95 KBanish.a
#78 remove-unused-2072597-78.patch2.7 KBAnonymous (not verified)
#68 remove-unused-2072597-68.patch3.47 KBpushpinderchauhan
#66 remove-unused-2072597-66.patch2.73 KBpushpinderchauhan
#64 interdiff-remove-unused-2072597-64.txt1.43 KBjoshi.rohit100
#64 remove-unused-2072597-64.patch3.58 KBjoshi.rohit100
#59 interdiff-2072597-57-59.txt2.1 KBamitgoyal
#59 2072597-59.patch2.22 KBamitgoyal
#57 interdiff-2072597-57.txt945 bytesdamiankloip
#57 2072597-57.patch4.83 KBdamiankloip
#56 interdiff-54-56.txt595 bytesmartin107
#56 remove-unused-2072597-56.patch3.91 KBmartin107
#54 remove-unused-2072597-54.patch4.49 KBconnorwk
#53 remove-unused-2072597-53.patch5.96 KBconnorwk
#45 2072597-44-interdiff.txt1.05 KBbogdan khrupa
#44 2072597-44.patch6.81 KBbogdan khrupa
#41 2072597-41.patch6.91 KBbogdan khrupa
#33 core-views-remove-unused-vars-2072597-33-test.patch4.82 KBAnonymous (not verified)
#29 core-views-remove-unused-vars-2072597-29-test.patch4.82 KBAnonymous (not verified)
#27 core-views-remove-unused-vars-2072597-test.patch4.95 KBAnonymous (not verified)
#22 core-views-remove-unused-vars-2072597-22.patch1.44 KBjvranckx
#17 2072597-13-17-interdiff.txt2.9 KBAnonymous (not verified)
#17 core-views-remove-unused-vars-2072597-17.patch7.32 KBAnonymous (not verified)
#13 2072597-8-13-interdiff.txt772 bytesAnonymous (not verified)
#13 core-views-remove-unused-vars-2072597-13.patch6.04 KBAnonymous (not verified)
#8 core-views-remove-unused-vars-2072597-8.patch6.05 KBlegolasbo
#5 2072597_5_core_remove_unused_local_variables_from_Views_module.patch4.95 KBstuti.manandhar
#3 core-remove-unused-vars-fieldpluginbase.php-2072597-3.patch2.09 KBlegolasbo
#1 core-remove-unused-vars-fieldpluginbase.php-2072597-1.patch1.33 KBlegolasbo

Comments

legolasbo’s picture

Assigned: legolasbo » Unassigned
Status: Active » Needs review
StatusFileSize
new1.33 KB

Removed unused local variables

phiit’s picture

Status: Needs review » Needs work

Reviewed, patch fixes both $arg cases but after applying the patch, second $arg removal makes $handler unused variable in line 1473.

@@ -1470,7 +1470,7 @@ public function getRenderTokens($item) {
       $tokens = $this->view->build_info['substitutions'];
     }
     $count = 0;
-    foreach ($this->view->display_handler->getHandlers('argument') as $arg => $handler) {
+    foreach ($this->view->display_handler->getHandlers('argument') as $handler) {

The $handler is not used in this foreach loop at all.

legolasbo’s picture

Status: Needs work » Needs review
Issue tags: +Needs tests
StatusFileSize
new2.09 KB

I've had a look at the code chunk related to $handler and found a way to remove both $handler and $token. While figuring out if this code was actually used or not I found out that removing the code chunk doesn't break any tests while the result of the function changes. I think this code needs tests, but perhaps it is better to check for and add missing tests for the entire class in a follow up issue.

xjm’s picture

Title: Remove Unused local variable $arg from /core/modules/views/lib/Drupal/views/Plugin/views/field/FieldPluginBase.php » Remove Unused local variables from the Views module
Issue summary: View changes
Priority: Normal » Minor
Status: Needs review » Needs work

I've re-scoped this issue to include unused local variables in the whole Views module. Please merge in the three patches from the other issues referencing this one, and also include any other unused local variables for that module.

Also, please file these as minor issues.

stuti.manandhar’s picture

Status: Needs work » Needs review
StatusFileSize
new4.95 KB

All mentioned four patches are merged into single one.

enhdless’s picture

Patch #5 failed to apply.

enhdless’s picture

Status: Needs review » Needs work
legolasbo’s picture

I was also working on this last night. attached patch is my attempt at a merge of the issues

legolasbo’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 8: core-views-remove-unused-vars-2072597-8.patch, failed testing.

The last submitted patch, 8: core-views-remove-unused-vars-2072597-8.patch, failed testing.

legolasbo’s picture

Status: Needs work » Needs review
Anonymous’s picture

Patch had whitespace so re-rolling without it.

parthipanramesh’s picture

Status: Needs review » Needs work

Sorry but this apply doesn't apply properly..

Anonymous’s picture

Status: Needs work » Needs review

Just tested on latest HEAD using git apply -v and applies cleanly - also passes tests - could you try again? If still issues please explain what the issue is so I can address it directly thanks as all seems OK here.

areke’s picture

Status: Needs review » Needs work

The supplied patch does apply, and it takes care of the unused local variable issue in this file. Also, thank you for taking care of some other stuff in the patch like changing
views_get_view('test_view');
to
\Drupal\views\Views::getView('test_view');
However, it does look like there are some more unused local variables in the module that are not resolved by the latest patch (@xjm re-scoped the issue). These should also be taken care of.

Anonymous’s picture

Issue summary: View changes
Status: Needs work » Needs review
StatusFileSize
new7.32 KB
new2.9 KB

OK, first I went through all the 'known unused' issues for 'unused' local variables for views module from the meta issue list #2002650: [meta, no patch] improve maintainability by removing unused local variables:

#2072601: Remove Unused local variable $count from /core/modules/views/lib/Drupal/views/Plugin/views/area/Result.php done in #2072597: Remove Unused local variables from tests in the Views module
#2072613: Remove Unused local variable $view from /core/modules/views/lib/Drupal/views/Tests/ViewStorageTest.php done in #2072597: Remove Unused local variables from tests in the Views module
#2072617: Remove Unused local variable $base from /core/modules/views/lib/Drupal/views/Tests/Handler/FieldWebTest.php done in #2072597: Remove Unused local variables from tests in the Views module
#2072625: Remove Unused local variable $view from /core/modules/views/lib/Drupal/views/Tests/Handler/FilterDateTest.php committed 4/12
#2072609: Remove Unused local variable $id from /core/modules/views/lib/Drupal/views/Tests/ModuleTest.php committed 3/12
#2067529: Remove Unused local variable $alias from /core/modules/views/lib/Drupal/views/ManyToOneHelper.php committed 4/12
#2072593: Remove Unused local variable $id from /core/modules/views/lib/Drupal/views/Plugin/views/display/DisplayPluginBase.php committed 4/12
#2060725: Remove Unused local variable $plugin from /core/modules/views/lib/Drupal/views/Plugin/Block/ViewsBlock.php closed, unused variable already been removed
#2064289: Remove Unused local variables from /core/modules/views/views.theme.inc committed 14/8
#2065115: Remove Unused local variable $langcode from /core/modules/views/views.tokens.inc committed 2/9
#2065125: Remove Unused local variable $display_id from /core/modules/views/lib/Drupal/views/DisplayBag.php committed 8/15
#2067541: Remove Unused local variable $id from /core/modules/views/lib/Drupal/views/ViewStorageController.php committed 8/18
#2072583: Remove Unused local variable $converted from /core/modules/views/lib/Drupal/views/ViewExecutable.php committed 8/29
#2072587: Remove Unused local variable $filter_id from /core/modules/views/lib/Drupal/views/Plugin/views/exposed_form/InputRequired.php committed 8/29
#2072589: Remove Unused local variable $extra from /core/modules/views/lib/Drupal/views/Plugin/views/join/Subquery.php committed 8/29
#2072591: Remove Unused local variable $extra from /core/modules/views/lib/Drupal/views/Plugin/views/join/JoinPluginBase.php committed 8/29
#2072595: Remove Unused local variable $base_field from /core/modules/views/lib/Drupal/views/Plugin/views/relationship/GroupwiseMax.php committed 2/10
#2072599: Remove Unused local variable $placeholder from /core/modules/views/lib/Drupal/views/Plugin/views/filter/String.php committed 8/29
#2072603: Remove Unused local variable $key from /core/modules/views/lib/Drupal/views/Plugin/views/query/Sql.php committed 4/9
#2072607: Remove Unused local variable $fake_item from /core/modules/views/lib/Drupal/views/Plugin/views/style/StylePluginBase.php committed 8/29
#2072611: Remove Unused local variable $result_nodes_per_char from /core/modules/views/lib/Drupal/views/Tests/GlossaryTest.php committed 2/10
#2072615: Remove Unused local variable $edit from /core/modules/views/lib/Drupal/views/Tests/Plugin/PagerTest.php committed 2/10
#2072619: Remove Unused local variable $key from /core/modules/views/lib/Drupal/views/Tests/Handler/RelationshipTest.php committed 2/10
#2072621: Remove Unused local variable $string from /core/modules/views/lib/Drupal/views/Tests/Handler/ArgumentNullTest.php committed 2/10
#2072623: Remove Unused local variable $empty_text from /core/modules/views/lib/Drupal/views/Tests/Handler/FieldUnitTest.php closed, both variables used
#2067547: Remove Unused local variable $display_id from /core/modules/views/lib/Drupal/views/Plugin/views/HandlerBase.php committed 2/10
#2057157: Remove Unused local variable $plugin from /core/modules/views/views.module committed 13/8
#2080023: Remove Unused local variable $tid from /core/modules/views/includes/ajax.inc closed, no longer relevant
#2081215: Remove Unused local variable $arg from /core/modules/views/lib/Drupal/views/Plugin/views/area/TokenizeAreaPluginBase.php committed 4/9

Then I applied patch from this issue and ran code inspector and went through each of the unused local variable instances it found. Here's the list in order of as it appears in PhpStorm Code Inspector, along with my notes for each:

/core/modules/views/lib/Drupal/views/Plugin/Block/ViewsBlockBase.php - Line 68: $plugin - used for list() parameter positioning
/core/modules/views/tests/Drupal/views/Tests/EventSubscriber/RouteSubscriberTest.php - Line 84: $view - used for list() parameter positioning
/core/modules/views/tests/Drupal/views/Tests/EventSubscriber/RouteSubscriberTest.php - Line 84: $executable	 - used for list() parameter positioning
/core/modules/views/lib/Drupal/views/Plugin/views/area/Result.php - Line 90: $label - used in line 110, see #2072601: Remove Unused local variable $count from /core/modules/views/lib/Drupal/views/Plugin/views/area/Result.php
/core/modules/views/lib/Drupal/views/Plugin/views/area/Result.php - Line 92: $page_count - used in line 110, see #2072601: Remove Unused local variable $count from /core/modules/views/lib/Drupal/views/Plugin/views/area/Result.php
/core/modules/views/lib/Drupal/views/Plugin/views/area/Result.php - Line 97: $page_count - used in line 110, see #2072601: Remove Unused local variable $count from /core/modules/views/lib/Drupal/views/Plugin/views/area/Result.php
/core/modules/views/lib/Drupal/views/Plugin/views/area/Result.php - Line 105: $current_record_count - used in line 110, see #2072601: Remove Unused local variable $count from /core/modules/views/lib/Drupal/views/Plugin/views/area/Result.php
/core/modules/views/tests/Drupal/views/Tests/EventSubscriber/RouteSubscriberTest.php - Line 114: $view	 - used for list() parameter positioning
/core/modules/views/tests/Drupal/views/Tests/EventSubscriber/RouteSubscriberTest.php - Line 114: $executable - used for list() parameter positioning
/core/modules/views/lib/Drupal/views/Tests/Plugin/StyleTableUnitTest.php Line 132: $style_plugin - not used, have removed
/core/modules/views/tests/Drupal/views/Tests/Controller/ViewAjaxControllerTest.php - Line 134: $view - used for list() parameter positioning
/core/modules/views/lib/Drupal/views/Plugin/views/argument_validator/Entity.php - Line 173: $ids - set directly before returning FALSE, have removed
/core/modules/views/lib/Drupal/views/Tests/Handler/FieldWebTest.php - Line 203: $base_url - see #2072617: Remove Unused local variable $base from /core/modules/views/lib/Drupal/views/Tests/Handler/FieldWebTest.php, have added line 234: // @todo see #1852492: Read More link field converts html anchor hash character in link output and #1342124: "Output this field as a link" escapes some characters
/core/modules/views/lib/Drupal/views/Tests/Handler/FieldWebTest.php - 203: $script_path - see #2072617: Remove Unused local variable $base from /core/modules/views/lib/Drupal/views/Tests/Handler/FieldWebTest.php, have added line 234: // @todo see #1852492: Read More link field converts html anchor hash character in link output and #1342124: "Output this field as a link" escapes some characters
/core/modules/views/lib/Drupal/views/Tests/Handler/FieldWebTest.php - Line 230: $expected_result - see #2072617: Remove Unused local variable $base from /core/modules/views/lib/Drupal/views/Tests/Handler/FieldWebTest.php, have added line 234: // @todo see #1852492: Read More link field converts html anchor hash character in link output and #1342124: "Output this field as a link" escapes some characters
/core/modules/views/lib/Drupal/views/Plugin/views/join/JoinPluginBase.php - Line 231: $operator - used, see #2072591: Remove Unused local variable $extra from /core/modules/views/lib/Drupal/views/Plugin/views/join/JoinPluginBase.php
/core/modules/views/lib/Drupal/views/Tests/Handler/FieldWebTest.php - Line 232: $result - see #2072617: Remove Unused local variable $base from /core/modules/views/lib/Drupal/views/Tests/Handler/FieldWebTest.php, have added line 234: // @todo see #1852492: Read More link field converts html anchor hash character in link output and #1342124: "Output this field as a link" escapes some characters
/core/modules/views/lib/Drupal/views/Plugin/views/join/JoinPluginBase.php - Line 234: $operator - used, see #2072591: Remove Unused local variable $extra from /core/modules/views/lib/Drupal/views/Plugin/views/join/JoinPluginBase.php
/core/modules/views/lib/Drupal/views/Tests/Handler/FieldUnitTest.php - Line 470: $empty_text - used, see #2072623: Remove Unused local variable $empty_text from /core/modules/views/lib/Drupal/views/Tests/Handler/FieldUnitTest.php
/core/modules/views/lib/Drupal/views/Tests/Handler/FieldUnitTest.php - Line 486: $alter_text - used, see #2072623: Remove Unused local variable $empty_text from /core/modules/views/lib/Drupal/views/Tests/Handler/FieldUnitTest.php

So the attached patch removes 2 further unused local variables, with all the other occurrences accounted for.

On one of the relevant issues there is a currently unused test, instead of removing I found the relevant issues and updated them to inform to uncomment the test when they've been attended to, also I added some comments in this patch to link to those issues.

I've also fixed a couple of code style issues and updated the issue summary.

I saw the comment re the change from views_get_view('test_view'); to \Drupal\views\Views::getView('test_view'); - although these are an easy change I haven't added any further to this issue, there are 100+ occurrences so I went searching for a META issue but couldn't find one - is there one for this issue?

Anyway that should be all the unused local variables for views counted for.

areke’s picture

Ok. I reviewed this again and it looks good, so +1 from me.
This probably does need some tests though.

Anonymous’s picture

"This probably does need some tests though." - if someone could elaborate I could try to write some tests, unsure where to start...

legolasbo’s picture

File /core/modules/views/lib/Drupal/views/Plugin/views/area/Result.php
contains several code chunks like the one below, where it loops trough some variables that were incorrectly marked as unused. Removing those variables doesn't break any tests, which implies there are no tests covering those variables. That might be a good place to start, I'm sure you'll find more code without tests while working on this.

    // Get the search information.
    $items = array('start', 'end', 'total', 'label', 'per_page', 'current_page', 'current_record_count', 'page_count');
    $replacements = array();
    foreach ($items as $item) {
      $replacements["@$item"] = ${$item};
    }
jvranckx’s picture

Assigned: Unassigned » jvranckx
jvranckx’s picture

The patch (comment #17) couldn't find the correct linenumbers. Fixed the patch so it applies correctly again.

jvranckx’s picture

Assigned: jvranckx » Unassigned

Issue still needs writing of tests to cover all unused variables.

Anonymous’s picture

looking at this as part of the Toronto sprint: just adding some knowledge -
it appears that the tool to detect unused variables came up with false positives. These variables were removed (should not have been!) and no tests failed.
So we need some tests that will fail if this happens again (or the code needs to be rewritten to prevent the false positives).

comment #20 above https://drupal.org/comment/8358373#comment-8358373 illustrates the code construct that confused the tool. The array of $items end up producing references to variables.

Anonymous’s picture

some more knowledge: the "unused" variables are located in Result (Result.php) which is used to support the "Global: Result Summary" which can be placed in the Footer of a view.

Anonymous’s picture

figured it out - a test case is needed that will verify that a Result Summary field gets processed properly. I have created a new test case and a supporting test view. will attach a patch soon...

Anonymous’s picture

I am attaching a patch that contains 1 new test case that utilizes a result Summary in its footer. Note that this patch is a test case only. No changes to the core code are involved.

Status: Needs review » Needs work

The last submitted patch, 27: core-views-remove-unused-vars-2072597-test.patch, failed testing.

Anonymous’s picture

Status: Needs work » Needs review
StatusFileSize
new4.82 KB

converted the patch file to be unix style eol's

Anonymous’s picture

Anonymous’s picture

Issue summary: View changes

Status: Needs review » Needs work

The last submitted patch, 29: core-views-remove-unused-vars-2072597-29-test.patch, failed testing.

Anonymous’s picture

fixed the patch file format - last line had no return

Anonymous’s picture

Status: Needs work » Needs review
Anonymous’s picture

hide a broken patch file

damiankloip’s picture

So we need some tests that will fail if this happens again (or the code needs to be rewritten to prevent the false positives).

I'm sorry, there is already test coverage for this class :/ Please see \Drupal\views\Tests\Plugin\area\ResultTest.

it looks like there is one unused variable that is actually unused in Drupal\views\Plugin\views\area\Result:

$count = count($this->view->result);

The patch in #17 was correct, the tests passed because that was indeed never needed :)

Anonymous’s picture

Understood - it was a little confusing as the "other" plugin area tests are located in a different folder so we could not find the test. We looked in folder core/modules/views/lib/Drupal/views/Tests/Handler and did not find a related test. So we made one. The existing test is alone in core/modules/views/Tests/Drupal/views/Tests/Plugin/area.

Can someone clarify the difference between the 2 folders?

I have hidden the not required patch #33.

damiankloip’s picture

The tests inside the lib folder are web tests/DUTB classes. The tests in the tests folder are for phpunit.

jgSnell’s picture

Assigned: Unassigned » jgSnell

Working on this during core mentoring

dawehner’s picture

Status: Needs review » Needs work

setting back to needs work.

bogdan khrupa’s picture

Status: Needs work » Needs review
StatusFileSize
new6.91 KB

This is a re-roll.

xano’s picture

Issue tags: +LembergSprint

Adding tag.

taran2l’s picture

Status: Needs review » Needs work
+++ b/core/modules/views/lib/Drupal/views/Plugin/views/field/FieldPluginBase.php
@@ -1469,19 +1469,19 @@ public function getRenderTokens($item) {
+    ¶
...
+    ¶

Remove trailing spaces.

bogdan khrupa’s picture

Status: Needs work » Needs review
StatusFileSize
new6.81 KB

Remove spaces.

bogdan khrupa’s picture

StatusFileSize
new1.05 KB

Sorry i'm forget interdiff file.

Status: Needs review » Needs work

The last submitted patch, 44: 2072597-44.patch, failed testing.

bogdan khrupa’s picture

The last submitted patch, 17: core-views-remove-unused-vars-2072597-17.patch, failed testing.

damiankloip’s picture

Seems like an unrelated failure.

xano’s picture

44: 2072597-44.patch queued for re-testing.

xano’s picture

Status: Needs work » Needs review

Setting the status back to what it was before the test failure.

connorwk’s picture

Assigned: jgSnell » Unassigned

Here at the Austin sprint, going to review this.

connorwk’s picture

StatusFileSize
new5.96 KB

Rerolled, 3-way auto-merge.
No conflicts.
Just uploading the patch to see what the bot says, reviewing it now.

connorwk’s picture

Issue tags: -LembergSprint +Austin Sprint
StatusFileSize
new4.49 KB

The rerolled patch looks good.
I added to the patch by removing more unused variables and checking all other variables phpStorm states as unused.
Here is a list of what is done to fix and or why the other unused variables are fine as they are.
1. I fixed the StyleUnformattedTest.php which had two un-asserted variables making them unused.
2. There are four false positive variables in Result.php that are used but auto inserted into an array by a foreach statement tricking phpStorm into thinking they are unused.
3. There are unused variables in multiple files that were in the list function which can be left out as per the example here: http://us1.php.net/manual/en/function.list.php
4. In FieldWebTest.php there are two unused variables that are used but the line is commented out with a todo message above it so they can be ignored.
5. In FieldUnitTest.php there is a false positive of an unused variable. It gets used in an assert shortly after being created.
6. In JoinPluginBase.php there are two instances of the same variable that phpStorm says is unused although there is a statement a further down using it? Maybe its over written by a lower down statement and phpStorm realizes this? But otherwise they are used, the code just may need to be cleaned up.

Otherwise this just needs another review and it should be good.

Status: Needs review » Needs work

The last submitted patch, 54: remove-unused-2072597-54.patch, failed testing.

martin107’s picture

Status: Needs work » Needs review
StatusFileSize
new3.91 KB
new595 bytes

Restored some variables definitions removed in #54.
FieldWebTest.php is now green locally

damiankloip’s picture

StatusFileSize
new4.83 KB
new945 bytes

I think we can go the other way and remove the variables that are unused that use the globals that were removed before.

damiankloip’s picture

+++ b/core/modules/views/tests/src/Controller/ViewAjaxControllerTest.php
@@ -131,7 +131,7 @@ public function testAjaxView() {
+    list(, $executable) = $this->setupValidMocks();

@@ -167,7 +167,7 @@ public function testAjaxViewWithArguments() {
+    list(, $executable) = $this->setupValidMocks();

@@ -189,7 +189,7 @@ public function testAjaxViewWithPager() {
+    list(, $executable) = $this->setupValidMocks();

+++ b/core/modules/views/tests/src/EventSubscriber/RouteSubscriberTest.php
@@ -78,7 +78,7 @@ protected function setUp() {
+    list(, , $display_1, $display_2) = $this->setupMocks();

IMO, this is not a good change. Yes, they are unused technically but this impacts the readability of these bits of code considerably.

amitgoyal’s picture

StatusFileSize
new2.22 KB
new2.1 KB

Please review changes as suggested in #58.

xano’s picture

IMO, this is not a good change. Yes, they are unused technically but this impacts the readability of these bits of code considerably.

It can also give the impression these variables are used somewhere, which they aren't. I'm just saying that based on damiankloip's reviews here and mine in person at the Drupalcon Austin sprints, this seems to hinge on personal preference a bit.

As both solutions are valid PHP, and we don't have anything about this in our coding standards, I'd say either solution is good in this case.

damiankloip’s picture

Yes, this seems to totally come down to preference :) But hey - this is a views issue ;)

In general, this just outlines the terrible-ness of using the list() construct.

xano’s picture

Status: Needs review » Reviewed & tested by the community

Agreed.

alexpott’s picture

Status: Reviewed & tested by the community » Needs work

There are loads more unused variables in the views module - not just the list() examples - I agree with @damiankloip I prefer the readability of having the unused variables declared. For example $view in Drupal\views\Tests\ViewStorageTest::displayMethodTests

joshi.rohit100’s picture

Status: Needs work » Needs review
StatusFileSize
new3.58 KB
new1.43 KB

review the patch.

jhedstrom’s picture

Status: Needs review » Needs work
Issue tags: +Needs reroll

+1 for removing unused code. This however needs a reroll.

pushpinderchauhan’s picture

Status: Needs work » Needs review
Issue tags: -Needs reroll
StatusFileSize
new2.73 KB

Rerolled.

Status: Needs review » Needs work

The last submitted patch, 66: remove-unused-2072597-66.patch, failed testing.

pushpinderchauhan’s picture

StatusFileSize
new3.47 KB
pushpinderchauhan’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 68: remove-unused-2072597-68.patch, failed testing.

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 68: remove-unused-2072597-68.patch, failed testing.

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 68: remove-unused-2072597-68.patch, failed testing.

Status: Needs work » Needs review
Anonymous’s picture

Patch worked fine locally so queued for re-testing.

Status: Needs review » Needs work

The last submitted patch, 68: remove-unused-2072597-68.patch, failed testing.

Anonymous’s picture

Status: Needs work » Needs review
StatusFileSize
new2.7 KB

Asked on irc and berdir said:

stevepurkiss: there's a segfault in the installer. has to be something about your patch because it doesn't happen without, although I can't say what
stevepurkiss: oh, that change in PathPluginBase is wrong. $pos *is* used

So I've removed the first chunk of code which deals with the PathPluginBase, see if this works.

mile23’s picture

Issue summary: View changes
Status: Needs review » Needs work

Hey, congrats. Patch in #78 still applies. :-)

Added beta evaluation.

Still using list(), which I gather is OK, just not OK when you do this: list(,$second_value) as per #63.

Poking through, contrary to the issue summary, those variables are, in fact, unused in /core/modules/views/lib/Drupal/views/Plugin/views/area/Result.php

Can't verify that there aren't any other unused variables in Views until this drops: #2451435: Trait collision in Drupal\views\Plugin\views\field\Field

anish.a’s picture

StatusFileSize
new1.95 KB

The above patch was no longer valid. Created new patch with similar modifications.

Although I am not sure how it works with latest code.

borisson_’s picture

Status: Needs work » Needs review
mile23’s picture

Status: Needs review » Needs work

Nice work, thanks.

In this case it didn't seem to matter, but rerolling patches is a good skill: https://www.drupal.org/patch/reroll

This patch does two things:

  1. It changes Drupal\views\Tests\Plugin\StyleUnformattedTest::testDefaultRowClasses() to assert that two counters are the same at the end of the test, which I think is probably a good idea.
  2. It also changes the return signature of Drupal\Tests\views\Unit\EventSubscriber\RouteSubscriberTest::setupMocks() to return a 2-item array instead of a 4-item array.

The thing about that is, the documentation lists four items which will be returned:

   * @return array
   *   An array of Views mocks, including the executable, the view entity, and
   *   two display plugins.

So let's change that to say:

   * @return \Drupal\views\Plugin\views\display\DisplayRouterInterface[]|\PHPUnit_Framework_MockObject_MockObject[]
   *   An array of two mocked view displays.
jgeryk’s picture

jgeryk’s picture

Assigned: Unassigned » jgeryk
jgeryk’s picture

Assigned: jgeryk » Unassigned
Status: Needs work » Needs review
StatusFileSize
new2.35 KB

Updated documentation as proposed

dawehner’s picture

These changes look alright for me! Why do we still have the 'Needs tests' tag? Doesn't really makes sense for me IMHO.

mile23’s picture

Status: Needs review » Needs work
Issue tags: -Needs tests

I think it had 'needs tests' from scope creep.

+++ b/core/modules/views/tests/src/Unit/EventSubscriber/RouteSubscriberTest.php
@@ -140,8 +140,7 @@ public function testOnAlterRoutes() {
    *
    * @return array
-   *   An array of Views mocks, including the executable, the view entity, and
-   *   two display plugins.
+   *   An array of two mocked view displays
    */

Still needs proper @returns documentation, like this:

   * @return \Drupal\views\Plugin\views\display\DisplayRouterInterface[]|\PHPUnit_Framework_MockObject_MockObject[]
   *   An array of two mocked view displays.
tkuldeep17’s picture

Status: Needs work » Needs review
StatusFileSize
new2.48 KB

Hi Mile23,

Uploading patch by modifying @return documentation.

steinmb’s picture

Status: Needs review » Reviewed & tested by the community

Find this issue a bit confusing though the patch looks OK.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 88: remove-unused-2072597-88.patch, failed testing.

Status: Needs work » Needs review
legolasbo’s picture

The tests failed across many non-views related tests, all because of some mysql related error. It is my guess testbot lied, so let's retest.

legolasbo’s picture

Status: Needs review » Reviewed & tested by the community

Yep, lies. so back to RTBC

alexpott’s picture

Title: Remove Unused local variables from the Views module » Remove Unused local variables from tests in the Views module
Status: Reviewed & tested by the community » Fixed

Committed 1c9d106 and pushed to 8.0.x. Thanks!

  • alexpott committed 1c9d106 on 8.0.x
    Issue #2072597 by stevepurkiss, giffenk, legolasbo, bogdan khrupa, er....

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.