There are some unused variables present in the Migrate Drupal module i.e. the variables are initialized but never used and we should fix it. Below is the list for the same:

core/modules/migrate_drupal/tests/src/Unit/source/DrupalSqlBaseTest.php
53 | WARNING | Unused variable $system_data.
78 | WARNING | Unused variable $system_data.

Comments

S_Bhandari created an issue. See original summary.

s_bhandari’s picture

Issue summary: View changes
s_bhandari’s picture

StatusFileSize
new3.94 KB

Added a patch to address the same.

s_bhandari’s picture

Issue summary: View changes
StatusFileSize
new1.49 KB

Ignoring patch #3, as some modifications are not needed as per the standard. Patch #4 should get considered.

s_bhandari’s picture

Assigned: s_bhandari » Unassigned
Status: Needs work » Needs review
sharma.amitt16’s picture

Status: Needs review » Reviewed & tested by the community

Thanks for the patch.
Changing the status to RTBC

alexpott’s picture

Status: Reviewed & tested by the community » Closed (duplicate)
Related issues: +#3106216: Remove unused variables from core

Thank you for your work on cleaning up Drupal core's code style!

In order to fix core coding standards in a maintainable way, all our coding standards issues should be done on a per-rule basis across all of core, rather than fixing standards in individual modules or files. We should also separate fixes where we need to write new documentation from fixes where we need to correct existing standards. This all should be done as part of #2571965: [meta] Fix PHP coding standards in core, stage 1. A good place to for unused variables is #3106216: Remove unused variables from core.

For background information on why we usually will not commit coding standards fixes that aren't scoped in that way, see the core issue scope guidelines, especially the note about coding standards cleanups. That document also includes numerous suggestions for scoping issues including documentation coding standards cleanups.

Contributing to the overall plan above will help ensure that your fixes for core's coding standards remain in core the long term.

alexpott’s picture

Status: Closed (duplicate) » Needs work

In discussion with xim, catch and larowlan, my earlier comment is incorrect. We should handle each unused variable on its own merit and do the work to work out why it is not used.

This can point to broken code or incomplete testing see #3157369: Use unused variable $filters from DateTimeSchemaTest for example. A useful tool for this is git log -S “SOME TEXT” which will search git commits for matching text to find out when the variable might have become unused. Without doing the work to show why the variable is unused the patch will not be committed. Also git blame can be useful as well.

s_bhandari’s picture

Hi @alexpott,

Thank you for reviewing it and yes, I have understood your point on this. I will look into this.

Thanks.

s_bhandari’s picture

StatusFileSize
new1.55 KB

Hi @alexpott,

As per the work done in comment #5 of the following issue you have suggested checking: https://www.drupal.org/project/drupal/issues/3157369, I have modified the patch.

Also, after doing the analysis I have found that the variable got introduced and became as unused in the following two commits: 7d6e615f, 5123f756. I have checked it by running the git blame and git show [COMMIT_ID] respectively in-order to confirm the same.

Please review the patch and let me know for any other information or observation regarding the same.

Thanks.

quietone’s picture

+++ b/core/modules/migrate_drupal/tests/src/Unit/source/DrupalSqlBaseTest.php
@@ -50,7 +50,7 @@ public function testSourceProviderNotActive() {
+    $plugin->getSystemData();

@@ -75,7 +75,7 @@ public function testSourceDatabaseError() {
+    $plugin->getSystemData();

I don't see how this will affect the test. DrupalSqlBase::getSystemData returns an array and that isn't used. It may throw an exception but this is run before setting the expectException.

paulocs’s picture

Status: Needs work » Needs review
StatusFileSize
new1.49 KB

As comment #13 said, I think we can just remove the two lines as this not interfere on the tests.

thalles’s picture

Status: Needs review » Reviewed & tested by the community

Based in #12, #13 looks good to me, and the tests don't broken

alexpott’s picture

Version: 9.1.x-dev » 9.0.x-dev
Status: Reviewed & tested by the community » Fixed

I've looked back through the history and these has never been used. Also regardless of it being called in the test - this method will be called when checkRequirements is called so this code is still running as part of the test.

Committed 8fd13be and pushed to 9.1.x and 9.0.x. Thanks!

Didn't apply to 8.9.x so didn't bother backporting there.

  • alexpott committed 8fd13be on 9.1.x
    Issue #3157975 by S_Bhandari, paulocs, quietone: Remove Unused variables...

  • alexpott committed 249d4e8 on 9.0.x
    Issue #3157975 by S_Bhandari, paulocs, quietone: Remove Unused variables...

Status: Fixed » Closed (fixed)

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