Skip to content

Add stubs for core field types #344

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 18, 2022
Merged

Add stubs for core field types #344

merged 1 commit into from
Feb 18, 2022

Conversation

mglaman
Copy link
Owner

@mglaman mglaman commented Feb 18, 2022

Fixes #342

Comment on lines +27 to +33
// LinkItem.
$link_field = $node->get('field_link')->first();
assert($link_field instanceof LinkItem);
assertType(LinkItem::class, $link_field);
assertType('string', $link_field->title);
assertType('string', $link_field->uri);
assertType('array<string, mixed>', $link_field->options);
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@neclimdul this should fix your errors :)

@mglaman
Copy link
Owner Author

mglaman commented Feb 18, 2022

Stub files are analysed independently from the rest of your codebase. This means that any type they’re referencing must also be present as a stub, even if you don’t want to override any of its PHPDocs.

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

All dependency classes need to be stubbed

@mglaman mglaman force-pushed the field-type-stubs branch 6 times, most recently from 6ae8de0 to 944d9ea Compare February 18, 2022 18:11
@mglaman
Copy link
Owner Author

mglaman commented Feb 18, 2022

 ------ ------------------------------------------------------------------------------------ 
  Line   vendor/mglaman/phpstan-drupal/stubs/Drupal/Core/TypedData/Plugin/DataType/Map.stub  
 ------ ------------------------------------------------------------------------------------ 
  8      Class Drupal\Core\TypedData\Plugin\DataType\Map extends unknown class               
         Drupal\Core\TypedData\TypedData.                                                    
  8      Class Drupal\Core\TypedData\Plugin\DataType\Map implements generic                  
         interface IteratorAggregate but does not specify its types: TKey,                   
         TValue                                                                              
 ------ ------------------------------------------------------------------------------------ 

@mglaman mglaman force-pushed the field-type-stubs branch 7 times, most recently from c997cea to ff32b96 Compare February 18, 2022 21:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Provide stub files for field types
1 participant