phpstan-drupal icon indicating copy to clipboard operation
phpstan-drupal copied to clipboard

Provide stub files for field types in core provided optional modules

Open dpi opened this issue 3 years ago • 6 comments

#342 #344 added stubs for field types which are always available with Drupal.

It'd be great if field types in Drupal in optional [non-test] modules were also hinted

eg

text.module:

\Drupal\text\Plugin\Field\FieldType\TextWithSummaryItem \Drupal\text\Plugin\Field\FieldType\TextItem \Drupal\text\Plugin\Field\FieldType\TextLongItem

options.module:

\Drupal\options\Plugin\Field\FieldType\ListStringItem \Drupal\options\Plugin\Field\FieldType\ListIntegerItem \Drupal\options\Plugin\Field\FieldType\ListFloatItem

etc, etc

For writing field type stubs, see the examples:

  • https://github.com/mglaman/phpstan-drupal/tree/main/stubs/Drupal/Core/Field/Plugin/Field/FieldType
  • https://github.com/mglaman/phpstan-drupal/tree/main/stubs/Drupal/file/Plugin/Field/FieldType
  • https://github.com/mglaman/phpstan-drupal/tree/main/stubs/Drupal/link

Official docs: https://phpstan.org/user-guide/stub-files

dpi avatar Mar 11 '22 11:03 dpi

Yes, it was such a drag creating these. Especially the first few due to needing to stub all dependent classes or interface. My plan is to add these, I just need to sit down and do it. Or make issues for them all as "good first issue"

mglaman avatar Mar 12 '22 16:03 mglaman

I'll work on making issues based on this format https://github.com/mglaman/phpstan-drupal/issues/360

mglaman avatar Mar 12 '22 16:03 mglaman

Layout Builder isn't needed since it has a @property doc already

mglaman avatar Mar 12 '22 16:03 mglaman

@dpi do you think we should add some common contrib field types? Like Entity Reference Revisions?

mglaman avatar Mar 12 '22 16:03 mglaman

It'd be nice, sure, but how sustainable is it? I personally wouldnt want to maintain an unlimited number of contrib types? Maybe contribs should implement @property. As you already mentioned LB has it. Theoretically contrib modules are more agile, and we can always point them here, or to some documentation on what they need to do.

dpi avatar Mar 12 '22 18:03 dpi

I think its critical that this project provides the shims for core, even if the ultimate aim would be to create issues in core itself to add hints.

dpi avatar Mar 12 '22 18:03 dpi