In core/tests/Drupal/Tests/Core/Annotation/TranslationTest.php, testGet() is initializing two variables that aren't used.

  $arguments = isset($values['arguments']) ? $values['arguments'] : [];
    $options = isset($values['context']) ? [
      'context' => $values['context'],
    ] : [];

Those variables need to be removed.

CommentFileSizeAuthor
unsused-variable-removed.patch774 byteshardik_patel_12

Comments

Hardik_Patel_12 created an issue. See original summary.

siddhant.bhosale’s picture

Assigned: Unassigned » siddhant.bhosale
siddhant.bhosale’s picture

Assigned: siddhant.bhosale » Unassigned
Status: Needs review » Reviewed & tested by the community
avpaderno’s picture

Issue summary: View changes
Status: Reviewed & tested by the community » Needs work

To push this patch, we need to check if it's just a matter of initialized variables that aren't used or there is missing code that needs to be restored.
We need to check in which commit those variables were introduced and which commit removed the code using those variables, if such commit has been done.

paulocs’s picture

I found the issue that removed the code that used to use the variables, but I'm not sure if we should re-add what was removed or just remove the unused variables.

The code bellow was removed in issue #2557113: Make t() return a TranslationWrapper object to remove reliance on a static, unpredictable safe list:

-    $this->translationManager->expects($this->once())
-      ->method('translate')
-      ->with($values['value'], $arguments, $options);
avpaderno’s picture

Issue summary: View changes
avpaderno’s picture

@paulocs Good catch!

Given that the current code is the following one, it's the variables that need to be removed, not the code to be added.

  public function testGet(array $values, $expected) {
    $container = new ContainerBuilder();
    $container->set('string_translation', $this->translationManager);
    \Drupal::setContainer($container);
    $arguments = isset($values['arguments']) ? $values['arguments'] : [];
    $options = isset($values['context']) ? [
      'context' => $values['context'],
    ] : [];
    $annotation = new Translation($values);
    $this->assertSame($expected, (string) $annotation->get());
  }

$values is already passed to the constructor of the Translation class. There is no need to extract $arguments and >$options from $values.

avpaderno’s picture

Status: Needs work » Reviewed & tested by the community

The patch is removing the unused variables, which is the correct thing to do.

  • catch committed 703dbe1 on 9.1.x
    Issue #3158266 by Hardik_Patel_12, kiamlaluno, paulocs: Unused local...
catch’s picture

Status: Reviewed & tested by the community » Fixed

Committed 703dbe1 and pushed to 9.1.x. Thanks!

Status: Fixed » Closed (fixed)

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