0

for doctyping a class-string you can doctype using: class-string<ParentClassType>.

But i cannot find any documentation surrounding enums.

I can find you can document something to be a value of an Enum with value-fo<Enum> https://phpstan.org/writing-php-code/phpdoc-types.

But is there a doctype available for enums? (i would expect something like? enum-class)

So the editor would know it can call ::tryFrom, ::from and ::cases()

Joel Harkes
  • 10,975
  • 3
  • 46
  • 65
  • I'm confused, what are you looking for? From the title you want to doc-type a string, but in the end "know it can call", what does "it" represent? A string cannot call these methods. – shingo Apr 14 '23 at 10:27
  • @shingo in PHP a string can be a reference to a class and thus call it's static methods "ClassName"::method() is totally valid in PHP – Joel Harkes Apr 14 '23 at 11:11
  • Honestly I didn't realize strings can be used like this in PHP. – shingo Apr 14 '23 at 11:52

1 Answers1

2

Fortunately all the enumerations implement the UnitEnum interface, and all the backed enumerations implement the BackedEnum interface, so you can use class-string<UnitEnum> to hint enumeration strings, and use class-string<BackedEnum> to hint backed enumeration strings.

shingo
  • 18,436
  • 5
  • 23
  • 42