Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Define TreeBuilder default generic type#62616

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
alexander-schranz wants to merge7 commits intosymfony:7.4
base:7.4
Choose a base branch
Loading
fromalexander-schranz:patch-10

Conversation

@alexander-schranz
Copy link
Contributor

@alexander-schranzalexander-schranz commentedDec 2, 2025
edited
Loading

QA
Branch?7.4
Bug fix?yes
New feature?no
Deprecations?no
IssuesFix #...
LicenseMIT

The generics make sense internal but are very confusing for all people not knowing about internal behaviours and hard to guess whats corrct so we should provide defaults for them. Similar to#61805 add some defaults.

Stumbled over this during upgrade StofDoctrineExtensionBundle:

  14     Method Stof\DoctrineExtensionsBundle\DependencyInjection\Configuration::getConfigTreeBuilder() return type with generic class Symfony\Component\Config\Definition\Builder\TreeBuilder does not specify its types: T         🪪  missingType.generics  40     Method Stof\DoctrineExtensionsBundle\DependencyInjection\Configuration::getVendorNode() return type with generic class Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition does not specify its types: TParent         🪪  missingType.generics  67     Method Stof\DoctrineExtensionsBundle\DependencyInjection\Configuration::getClassNode() return type with generic class Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition does not specify its types: TParent         🪪  missingType.generics  121    Method Stof\DoctrineExtensionsBundle\DependencyInjection\Configuration::getSoftDeleteableNode() return type with generic class Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition does not specify its types: TParent         🪪  missingType.generics  136    Method Stof\DoctrineExtensionsBundle\DependencyInjection\Configuration::getUploadableNode() return type with generic class Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition does not specify its types: TParent         🪪  missingType.generics

Set default template type for TreeBuilder.
@carsonbotcarsonbot added this to the7.4 milestoneDec 2, 2025
@carsonbotcarsonbot changed the titleDefine TreeBuilder default generic type Define TreeBuilder default generic typeDec 2, 2025
Add return type declaration to getConfigTreeBuilder method
/**
* Generates the configuration tree builder.
*
* @return TreeBuilder<'array'>
Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

@nicolas-grekas unsure about this, is there any case where the getConfigTreeBuilder returns something else as an array?

Choose a reason for hiding this comment

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

the interface allows it 🤷

@alexander-schranz
Copy link
ContributorAuthor

Fabbot error looks unexpected and not related to the changes.

Add PHPDoc for getConfigTreeBuilder method
Comment on lines +34 to +36
/**
* @return TreeBuilder<'array'>
*/
Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

Not sure why psalm wants this be added shouldn't it not just use interface return type here and not force redefinition?

* This class provides a fluent interface for defining an array node.
*
* @template TParent of NodeParentInterface|null
* @template TParent of NodeParentInterface|null = null
Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

Not sure about the default here?

@alexander-schranz
Copy link
ContributorAuthor

Stuck with psalm and the correct defaults if somebody has any hints to tackle this correctly to make it as easy as possible to create config builders without devs need to think about any generics.

* This is the entry class for building a config tree.
*
* @template T of 'array'|'variable'|'scalar'|'string'|'boolean'|'integer'|'float'|'enum'
* @template T of 'array'|'variable'|'scalar'|'string'|'boolean'|'integer'|'float'|'enum' = 'array'
Copy link
Member

@nicolas-grekasnicolas-grekasDec 2, 2025
edited
Loading

Choose a reason for hiding this comment

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

this shouldn't be needed, the$type = 'array' default is enough, phpstan understands it.
If other tools don't, that should be reported to them

Copy link
ContributorAuthor

@alexander-schranzalexander-schranzDec 2, 2025
edited
Loading

Choose a reason for hiding this comment

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

enough for usage ofnew TreeBuilder maybe but not for param type withfunction method(TreeBuilder $treeBuilder) or return typemethod(): TreeBuilder to defaults there to'array'.

Copy link
Contributor

Choose a reason for hiding this comment

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

I ran into the exact problem today and can confirm that PHPStan is indeed reporting an issue:

Method MyBundle\DependencyInjection\Configuration::getConfigTreeBuilder() return type with generic class Symfony\Component\Config\Definition\Builder\TreeBuilder does not specify its types: T

Co-authored-by: Nicolas Grekas <nicolas.grekas@gmail.com>
Removed unnecessary type hint comment for treeBuilder.
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@nicolas-grekasnicolas-grekasnicolas-grekas left review comments

+1 more reviewer

@stlrnzstlrnzstlrnz left review comments

Reviewers whose approvals may not affect merge requirements

Assignees

No one assigned

Projects

None yet

Milestone

7.4

Development

Successfully merging this pull request may close these issues.

4 participants

@alexander-schranz@nicolas-grekas@stlrnz@carsonbot

[8]ページ先頭

©2009-2025 Movatter.jp