nette / php-generator

🐘 Generates neat PHP code for you. Supports new PHP 8.3 features.
https://doc.nette.org/php-generator
Other
2.11k stars 138 forks source link

Make `ClassLike::from` return type assert the subclass type #154

Closed GromNaN closed 7 months ago

GromNaN commented 7 months ago

When reading a ClassType from a FQCN or a file, the result can be anything from the 4 subclasses. When we know the type of the object that is parsed, having a more strict return type has additional benefits:

Usage: If the type is unknown, use ClassLike::from($class). Otherwise, when the expected type is known, use the more specific ClassType::from($fqcn), TraitType::from($fqcn), InterfaceType::from($fqcn), or EnumType::from($fqcn).

This is a breaking change for users that call ClassType::from($fqcn) on something that is not a class name.

dg commented 7 months ago

Thanks!

dg commented 7 months ago

Since this is a BC break, for now I'll just put a warning instead of throwing exceptions, and I'll put this change in the bigger version.