Skip to content

Conversation

@alexander-schranz
Copy link
Contributor

@alexander-schranz alexander-schranz commented Dec 2, 2025

Q A
Branch? 7.4
Bug fix? yes
New feature? no
Deprecations? no
Issues Fix #...
License MIT

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

@carsonbot carsonbot added this to the 7.4 milestone Dec 2, 2025
@carsonbot carsonbot changed the title Define TreeBuilder default generic type Define TreeBuilder default generic type Dec 2, 2025
/**
* Generates the configuration tree builder.
*
* @return TreeBuilder<'array'>
Copy link
Contributor Author

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?

Copy link
Member

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
Contributor Author

Fabbot error looks unexpected and not related to the changes.

Comment on lines +34 to +36
/**
* @return TreeBuilder<'array'>
*/
Copy link
Contributor Author

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
Contributor Author

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
Contributor Author

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-grekas nicolas-grekas Dec 2, 2025

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
Contributor Author

@alexander-schranz alexander-schranz Dec 2, 2025

Choose a reason for hiding this comment

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

enough for usage of new TreeBuilder maybe but not for param type with function method(TreeBuilder $treeBuilder) or return type method(): 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

@carsonbot carsonbot changed the title Define TreeBuilder default generic type [Config] Define TreeBuilder default generic type Dec 3, 2025
@alexander-schranz
Copy link
Contributor Author

alexander-schranz commented Dec 3, 2025

I'm kind of stucked here as not correctly understanding here the generics in all cases. But we sure should find a solution this kind of PHPStan errors not appear for everybody try to create a bundle config.

If somebody want to take this over I'm fine.

@OskarStark OskarStark changed the title [Config] Define TreeBuilder default generic type [Config] Define TreeBuilder default generic type Dec 4, 2025
Copy link
Member

@nicolas-grekas nicolas-grekas left a comment

Choose a reason for hiding this comment

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

Let's merge this and iterate as needed.
psalm reports are about the internals, but once merged, it won't propagate to userland AFAIK.

@nicolas-grekas
Copy link
Member

Thank you @alexander-schranz.

@nicolas-grekas nicolas-grekas merged commit 2a6721a into symfony:7.4 Dec 5, 2025
5 of 12 checks passed
@alexander-schranz alexander-schranz deleted the patch-10 branch December 5, 2025 07:48
nicolas-grekas added a commit that referenced this pull request Dec 10, 2025
… generic (alexander-schranz)

This PR was squashed before being merged into the 7.4 branch.

Discussion
----------

[Config] Add default generic to Configuration to TParent generic

| Q             | A
| ------------- | ---
| Branch?       | 7.4
| Bug fix?      | no
| New feature?  | no <!-- if yes, also update src/**/CHANGELOG.md -->
| Deprecations? |no <!-- if yes, also update UPGRADE-*.md and src/**/CHANGELOG.md -->
| Issues        | Fix #... <!-- prefix each issue number with "Fix #"; no need to create an issue if none exists, explain below -->
| License       | MIT

Missed in #62616.

Define all TParent which are nullable as default null.

Commits
-------

c6ff984 [Config] Add default generic to Configuration to TParent generic
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants