Skip to content

Commit 013d0fb

Browse files
VincentLangletnicolas-grekas
authored andcommitted
[DependencyInjection] Improve array phpdoc of ContainerBuilder
1 parent 4b8d9fd commit 013d0fb

File tree

2 files changed

+51
-28
lines changed

2 files changed

+51
-28
lines changed

ContainerBuilder.php

Lines changed: 50 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -55,37 +55,43 @@
5555
class ContainerBuilder extends Container implements TaggedContainerInterface
5656
{
5757
/**
58-
* @var ExtensionInterface[]
58+
* @var array<string, ExtensionInterface>
5959
*/
6060
private $extensions = [];
6161

6262
/**
63-
* @var ExtensionInterface[]
63+
* @var array<string, ExtensionInterface>
6464
*/
6565
private $extensionsByNs = [];
6666

6767
/**
68-
* @var Definition[]
68+
* @var array<string, Definition>
6969
*/
7070
private $definitions = [];
7171

7272
/**
73-
* @var Alias[]
73+
* @var array<string, Alias>
7474
*/
7575
private $aliasDefinitions = [];
7676

7777
/**
78-
* @var ResourceInterface[]
78+
* @var array<string, ResourceInterface>
7979
*/
8080
private $resources = [];
8181

82+
/**
83+
* @var array<string, array<array<string, mixed>>>
84+
*/
8285
private $extensionConfigs = [];
8386

8487
/**
8588
* @var Compiler
8689
*/
8790
private $compiler;
8891

92+
/**
93+
* @var bool
94+
*/
8995
private $trackResources;
9096

9197
/**
@@ -123,15 +129,24 @@ class ContainerBuilder extends Container implements TaggedContainerInterface
123129
*/
124130
private $vendors;
125131

132+
/**
133+
* @var array<string, ChildDefinition>
134+
*/
126135
private $autoconfiguredInstanceof = [];
127136

128137
/**
129-
* @var callable[]
138+
* @var array<string, callable>
130139
*/
131140
private $autoconfiguredAttributes = [];
132141

142+
/**
143+
* @var array<string, bool>
144+
*/
133145
private $removedIds = [];
134146

147+
/**
148+
* @var array<int, bool>
149+
*/
135150
private $removedBindingIds = [];
136151

137152
private const INTERNAL_TYPES = [
@@ -159,7 +174,7 @@ public function __construct(ParameterBagInterface $parameterBag = null)
159174
}
160175

161176
/**
162-
* @var \ReflectionClass[] a list of class reflectors
177+
* @var array<string, \ReflectionClass>
163178
*/
164179
private $classReflectors;
165180

@@ -224,7 +239,7 @@ public function getExtension(string $name)
224239
/**
225240
* Returns all registered extensions.
226241
*
227-
* @return ExtensionInterface[]
242+
* @return array<string, ExtensionInterface>
228243
*/
229244
public function getExtensions()
230245
{
@@ -272,7 +287,7 @@ public function addResource(ResourceInterface $resource)
272287
/**
273288
* Sets the resources for this configuration.
274289
*
275-
* @param ResourceInterface[] $resources An array of resources
290+
* @param array<string, ResourceInterface> $resources
276291
*
277292
* @return $this
278293
*/
@@ -417,8 +432,8 @@ public function fileExists(string $path, $trackContents = true): bool
417432
/**
418433
* Loads the configuration for an extension.
419434
*
420-
* @param string $extension The extension alias or namespace
421-
* @param array $values An array of values that customizes the extension
435+
* @param string $extension The extension alias or namespace
436+
* @param array<string, mixed>|null $values An array of values that customizes the extension
422437
*
423438
* @return $this
424439
*
@@ -431,13 +446,9 @@ public function loadFromExtension(string $extension, array $values = null)
431446
throw new BadMethodCallException('Cannot load from an extension on a compiled container.');
432447
}
433448

434-
if (\func_num_args() < 2) {
435-
$values = [];
436-
}
437-
438449
$namespace = $this->getExtension($extension)->getAlias();
439450

440-
$this->extensionConfigs[$namespace][] = $values;
451+
$this->extensionConfigs[$namespace][] = $values ?? [];
441452

442453
return $this;
443454
}
@@ -684,7 +695,7 @@ public function merge(self $container)
684695
/**
685696
* Returns the configuration array for the given extension.
686697
*
687-
* @return array
698+
* @return array<array<string, mixed>>
688699
*/
689700
public function getExtensionConfig(string $name)
690701
{
@@ -697,6 +708,8 @@ public function getExtensionConfig(string $name)
697708

698709
/**
699710
* Prepends a config array to the configs of the given extension.
711+
*
712+
* @param array<string, mixed> $config
700713
*/
701714
public function prependExtensionConfig(string $name, array $config)
702715
{
@@ -779,7 +792,7 @@ public function getServiceIds()
779792
/**
780793
* Gets removed service or alias ids.
781794
*
782-
* @return array
795+
* @return array<string, bool>
783796
*/
784797
public function getRemovedIds()
785798
{
@@ -788,6 +801,8 @@ public function getRemovedIds()
788801

789802
/**
790803
* Adds the service aliases.
804+
*
805+
* @param array<string, string|Alias> $aliases
791806
*/
792807
public function addAliases(array $aliases)
793808
{
@@ -798,6 +813,8 @@ public function addAliases(array $aliases)
798813

799814
/**
800815
* Sets the service aliases.
816+
*
817+
* @param array<string, string|Alias> $aliases
801818
*/
802819
public function setAliases(array $aliases)
803820
{
@@ -854,7 +871,7 @@ public function hasAlias(string $id)
854871
}
855872

856873
/**
857-
* @return Alias[]
874+
* @return array<string, Alias>
858875
*/
859876
public function getAliases()
860877
{
@@ -904,7 +921,7 @@ public function autowire(string $id, string $class = null)
904921
/**
905922
* Adds the service definitions.
906923
*
907-
* @param Definition[] $definitions An array of service definitions
924+
* @param array<string, Definition> $definitions
908925
*/
909926
public function addDefinitions(array $definitions)
910927
{
@@ -916,7 +933,7 @@ public function addDefinitions(array $definitions)
916933
/**
917934
* Sets the service definitions.
918935
*
919-
* @param Definition[] $definitions An array of service definitions
936+
* @param array<string, Definition> $definitions
920937
*/
921938
public function setDefinitions(array $definitions)
922939
{
@@ -927,7 +944,7 @@ public function setDefinitions(array $definitions)
927944
/**
928945
* Gets all service definitions.
929946
*
930-
* @return Definition[]
947+
* @return array<string, Definition>
931948
*/
932949
public function getDefinitions()
933950
{
@@ -1142,7 +1159,7 @@ private function createService(Definition $definition, array &$inlineServices, b
11421159
/**
11431160
* Replaces service references by the real service instance and evaluates expressions.
11441161
*
1145-
* @param mixed $value A value
1162+
* @param mixed $value
11461163
*
11471164
* @return mixed The same value with all service references replaced by
11481165
* the real service instances and all expressions evaluated
@@ -1236,7 +1253,7 @@ private function doResolveServices($value, array &$inlineServices = [], bool $is
12361253
* }
12371254
* }
12381255
*
1239-
* @return array An array of tags with the tagged service as key, holding a list of attribute arrays
1256+
* @return array<string, array> An array of tags with the tagged service as key, holding a list of attribute arrays
12401257
*/
12411258
public function findTaggedServiceIds(string $name, bool $throwOnAbstract = false)
12421259
{
@@ -1257,7 +1274,7 @@ public function findTaggedServiceIds(string $name, bool $throwOnAbstract = false
12571274
/**
12581275
* Returns all tags the defined services use.
12591276
*
1260-
* @return array
1277+
* @return string[]
12611278
*/
12621279
public function findTags()
12631280
{
@@ -1346,15 +1363,15 @@ public function registerAliasForArgument(string $id, string $type, string $name
13461363
/**
13471364
* Returns an array of ChildDefinition[] keyed by interface.
13481365
*
1349-
* @return ChildDefinition[]
1366+
* @return array<string, ChildDefinition>
13501367
*/
13511368
public function getAutoconfiguredInstanceof()
13521369
{
13531370
return $this->autoconfiguredInstanceof;
13541371
}
13551372

13561373
/**
1357-
* @return callable[]
1374+
* @return array<string, callable>
13581375
*/
13591376
public function getAutoconfiguredAttributes(): array
13601377
{
@@ -1495,6 +1512,8 @@ final public static function willBeAvailable(string $package, string $class, arr
14951512
/**
14961513
* Gets removed binding ids.
14971514
*
1515+
* @return array<int, bool>
1516+
*
14981517
* @internal
14991518
*/
15001519
public function getRemovedBindingIds(): array
@@ -1522,6 +1541,8 @@ public function removeBindings(string $id)
15221541
*
15231542
* @param mixed $value An array of conditionals to return
15241543
*
1544+
* @return string[]
1545+
*
15251546
* @internal
15261547
*/
15271548
public static function getServiceConditionals($value): array
@@ -1544,6 +1565,8 @@ public static function getServiceConditionals($value): array
15441565
*
15451566
* @param mixed $value An array of conditionals to return
15461567
*
1568+
* @return string[]
1569+
*
15471570
* @internal
15481571
*/
15491572
public static function getInitializedConditionals($value): array

Tests/Loader/YamlFileLoaderTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,7 @@ public function testExtensionWithNullConfig()
357357
$loader->load('null_config.yml');
358358
$container->compile();
359359

360-
$this->assertSame([null], $container->getParameter('project.configs'));
360+
$this->assertSame([[]], $container->getParameter('project.configs'));
361361
}
362362

363363
public function testSupports()

0 commit comments

Comments
 (0)