The serializer of Symfony\Component\Serializer\Serializer type that unserialize to an object have only 1 exact return type.
That means we can add specific type on deserialize() call, based on 2nd argument:
-public function resolveEntity($data)
+public function resolveEntity($data): SomeType
{
return $this->serializer->deserialize($data, SomeType::class, 'json');
}
If the deserialize() fails, it will throw an exception. So the value is never nullable.
The rule should handle only direct returns like these, keep it simple.
This rule should be part of type declaration set.