I would simplify this method by just checking instanceof on the class. This is an example, not a generic class (Symfony developers will probably figure out by themselves how to support more than one class).