Template for a good new topic, formatted with Markdown:
- ALM: Azure DevOps
- CI system used: Azure DevOps
- Languages of the repository: PHP
Use Doctrine, Symfony & ApiPlatform
I have an first class which define an id
abstract class AbstractUlidEntity
{
public function __construct()
{
$this->id = new Ulid();
}
#[ORM\Id, ORM\Column(type: 'ulid', unique: true)]
#[ApiProperty(identifier: true)]
protected Ulid $id;
public function getId(): string
{
return $this->id->__toString();
}
}
Then, I have a resource that extends this class. This resource is used in ApiPlatform, so it defines its own serialization.
class Resource extends AbstractUlidEntity
{
#[Groups(['myresource:read'])]
public function getId(): string
{
return parent::getId();
}
}
My abstract class doesn’t have to know anything about its implementation, so the serialization has nothing to do with it.
Redefining the id in each resource makes the abstract class useless
Each resource has its serialization group, we cannot add all in the abstract class, so redefining only the getter is a good solution, in ApiPlatform point of view.
The problem is that SonarCloud seems not to look at the difference in attributes, and say that I should
Remove this method “getId” to simply inherit it.
Is there a way to remove this warning?