ListDataDefinition::getClass() contains the following code.

  $class = isset($this->definition['class']) ? $this->definition['class'] : NULL;
  if (!empty($class)) {
    return $class;
  }

It is a rather convoluted version of the following code.

  if (isset($this->definition['class'])) {
    return $this->definition['class'];
  }

That is exactly the code used from DataDefinition::getClass().

  if (isset($this->definition['class'])) {
    return $this->definition['class'];
  }

Also there isn't a need to use an if() {} else {} statement, since the if() part returns to the caller, when executed.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

kiamlaluno created an issue. See original summary.

apaderno’s picture

Status: Active » Needs review
FileSize
1.59 KB
joelpittet’s picture

Status: Needs review » Needs work

You're right it does look convoluted but it should be if (!empty($this->definition['class'])) { no? The !empty() does more than the isset() and an implicit isset.

apaderno’s picture

Status: Needs work » Needs review
FileSize
1.59 KB

I assumed there is code that verifies the class name is not set to an empty string or FALSE because the other method uses isset().

I didn't check such code exists in Drupal, but I agree that at the point getClass() is called, $this->definition['class'] should already contain a valid class name, or not be set.
If, eventually, an empty string does have a particular meaning, it should be converted to a real class name before getClass() is called, or inside getClass().

Since at the moment there isn't such need, this is the updated patch.

joelpittet’s picture

Status: Needs review » Reviewed & tested by the community

That looks better, thanks for updating the patch.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 4: simplify-code-2934096-4.patch, failed testing. View results

apaderno’s picture

Status: Needs work » Needs review
joelpittet’s picture

Status: Needs review » Reviewed & tested by the community

That's strange it says it passed... testbot! 👿

apaderno’s picture

@joelpittet It was not passing because an error on DrupalCI (Requeued after CI error. Requeued after CI error. Requeued after CI error. Requeued after CI error. Requeued after CI error.) not because the patch is wrong.

larowlan’s picture

Crediting @joelpittet as his review changed the shape of the patch

larowlan’s picture

Status: Reviewed & tested by the community » Fixed

Committed as 6eafe72 and pushed to 8.5.x.

Thanks

  • larowlan committed 6eafe72 on 8.5.x
    Issue #2934096 by kiamlaluno, joelpittet: Simplify the...

Status: Fixed » Closed (fixed)

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

apaderno’s picture

Issue summary: View changes