Skip to content

Entity helper recognized as accessor #1432

Open
@fmarchalemisys

Description

@fmarchalemisys

My entities have some helper methods looking like this:

public function setPosition($latitude, $longitude)
{
    $this->setLatitude($latitude);
    $this->setLongitude($longitude);
    return $this;
}

It seems Symfony 4 as an improved PropertyInfo class that has become too smart for its own good. It returns the nonexistent property $position because of the method looking like a setter.

Looking at ReflectionExtractor in property-info bundle, any method beginning with 'add', 'remove', 'set', 'is', 'can', 'get', 'has' will generate such a ghost property.

The solution here is to declare a fake, unused, $position with a dummy type (for instance @var string) just to avoid the error saying the type of $position can't be guessed. It's a dirty hack. Is there any cleaner solution?

PS: I like the idea of creating fake setters/getters in cases like this:

/**
 * @var boolean
 */
private $result;

public function getResult()
{
    return $this->result;
}

/**
 * @return string
 */
public function getResultLabel()
{
    return $this->result ? "allowed" : "denied";
}

Skipping any "property" returned by property-info that doesn't have a real property in the class would prevent the above alternate getter from working.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions