Issue Bug Closed

#94144Return values of FileReferences getters is null when it should be empty string

Chris Müller 05/17/21, 06:57 updated 07/06/23, 15:10

Description

In introduced in a project Rector with the code quality rule. In one of my controllers I have the following code:

/* @var FileReference $image */
if ($image->getAlternative()) {
    // do something
}

Rector now changes this condition to:

if ($image->getAlternative() !== '') {
   // do something
}

This is because the @return annotation of the getAlternative() method is set to “string”.

But this is not correct as ->getAlternative() can also return null.

The same is with ->getTitle() and ->getDescription().

Reviews 2