Skip to content

Commit 2a6721a

Browse files
minor #62616 [Config] Define TreeBuilder default generic type (alexander-schranz)
This PR was squashed before being merged into the 7.4 branch. Discussion ---------- [Config] Define `TreeBuilder` default generic type | Q | A | ------------- | --- | Branch? | 7.4 | Bug fix? | yes | 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 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 ``` Commits ------- d21ad61 [Config] Define `TreeBuilder` default generic type
2 parents 0834f9a + d21ad61 commit 2a6721a

File tree

4 files changed

+8
-3
lines changed

4 files changed

+8
-3
lines changed

src/Symfony/Component/Config/Definition/Builder/ArrayNodeDefinition.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
/**
2020
* This class provides a fluent interface for defining an array node.
2121
*
22-
* @template TParent of NodeParentInterface|null
22+
* @template TParent of NodeParentInterface|null = null
2323
*
2424
* @extends NodeDefinition<TParent>
2525
*

src/Symfony/Component/Config/Definition/Builder/TreeBuilder.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
/**
1717
* This is the entry class for building a config tree.
1818
*
19-
* @template T of 'array'|'variable'|'scalar'|'string'|'boolean'|'integer'|'float'|'enum'
19+
* @template T of 'array'|'variable'|'scalar'|'string'|'boolean'|'integer'|'float'|'enum' = 'array'
2020
*
2121
* @author Johannes M. Schmitt <[email protected]>
2222
*/

src/Symfony/Component/Config/Definition/Configuration.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,12 @@ public function __construct(
3131
) {
3232
}
3333

34+
/**
35+
* @return TreeBuilder<'array'>
36+
*/
3437
public function getConfigTreeBuilder(): TreeBuilder
3538
{
36-
$treeBuilder = new TreeBuilder($this->alias);
39+
$treeBuilder = new TreeBuilder($this->alias, 'array');
3740
$file = (new \ReflectionObject($this->subject))->getFileName();
3841
$loader = new DefinitionFileLoader($treeBuilder, new FileLocator(\dirname($file)), $this->container);
3942
$configurator = new DefinitionConfigurator($treeBuilder, $loader, $file, $file);

src/Symfony/Component/Config/Definition/ConfigurationInterface.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ interface ConfigurationInterface
2222
{
2323
/**
2424
* Generates the configuration tree builder.
25+
*
26+
* @return TreeBuilder<'array'>
2527
*/
2628
public function getConfigTreeBuilder(): TreeBuilder;
2729
}

0 commit comments

Comments
 (0)