8000 Add types to private/final/internal methods and constructors. · symfony/symfony@c21fbb2 · GitHub
[go: up one dir, main page]

Skip to content

Commit c21fbb2

Browse files
committed
Add types to private/final/internal methods and constructors.
1 parent 22319a9 commit c21fbb2

33 files changed

+105
-87
lines changed

src/Symfony/Bundle/FrameworkBundle/Test/TestContainer.php

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace Symfony\Bundle\FrameworkBundle\Test;
1313

14+
use Psr\Container\ContainerInterface;
1415
use Symfony\Component\DependencyInjection\Container;
1516
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
1617
use Symfony\Component\HttpKernel\KernelInterface;
@@ -34,7 +35,7 @@ public function __construct(KernelInterface $kernel, string $privateServicesLoca
3435
/**
3536
* {@inheritdoc}
3637
*/
37-
public function compile()
38+
public function compile(): void
3839
{
3940
$this->getPublicContainer()->compile();
4041
}
@@ -74,15 +75,15 @@ public function hasParameter($name): bool
7475
/**
7576
* {@inheritdoc}
7677
*/
77-
public function setParameter($name, $value)
78+
public function setParameter($name, $value): void
7879
{
7980
$this->getPublicContainer()->setParameter($name, $value);
8081
}
8182

8283
/**
8384
* {@inheritdoc}
8485
*/
85-
public function set($id, $service)
86+
public function set($id, $service): void
8687
{
8788
$this->getPublicContainer()->set($id, $service);
8889
}
@@ -114,7 +115,7 @@ public function initialized($id): bool
114115
/**
115116
* {@inheritdoc}
116117
*/
117-
public function reset()
118+
public function reset(): void
118119
{
119120
$this->getPublicContainer()->reset();
120121
}
@@ -135,7 +136,7 @@ public function getRemovedIds(): array
135136
return $this->getPublicContainer()->getRemovedIds();
136137
}
137138

138-
private function getPublicContainer()
139+
private function getPublicContainer(): Container
139140
{
140141
if (null === $container = $this->kernel->getContainer()) {
141142
throw new \LogicException('Cannot access the container on a non-booted kernel. Did you forget to boot it?');
@@ -144,7 +145,7 @@ private function getPublicContainer()
144145
return $container;
145146
}
146147

147-
private function getPrivateContainer()
148+
private function getPrivateContainer(): ContainerInterface
148149
{
149150
return $this->getPublicContainer()->get($this->privateServicesLocatorId);
150151
}

src/Symfony/Component/DependencyInjection/Argument/BoundArgument.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,15 +43,15 @@ public function __construct($value, bool $trackUsage = true, int $type = 0, stri
4343
/**
4444
* {@inheritdoc}
4545
*/
46-
public function getValues()
46+
public function getValues(): array
4747
{
4848
return [$this->value, $this->identifier, $this->used, $this->type, $this->file];
4949
}
5050

5151
/**
5252
* {@inheritdoc}
5353
*/
54-
public function setValues(array $values)
54+
public function setValues(array $values): void
5555
{
5656
if (5 === \count($values)) {
5757
list($this->value, $this->identifier, $this->used, $this->type, $this->file) = $values;

src/Symfony/Component/DependencyInjection/Argument/RewindableGenerator.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,14 @@ public function __construct(callable $generator, $count)
2828
$this->count = $count;
2929
}
3030

31-
public function getIterator()
31+
public function getIterator(): \Traversable
3232
{
3333
$g = $this->generator;
3434

3535
return $g();
3636
}
3737

38-
public function count()
38+
public function count(): int
3939
{
4040
if (\is_callable($count = $this->count)) {
4141
$this->count = $count();

src/Symfony/Component/DependencyInjection/Compiler/AbstractRecursivePass.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,15 +192,15 @@ protected function getReflectionMethod(Definition $definition, $method)
192192
return $r;
193193
}
194194

195-
private function getExpressionLanguage()
195+
private function getExpressionLanguage(): ExpressionLanguage
196196
{
197197
if (null === $this->expressionLanguage) {
198198
if (!class_exists(ExpressionLanguage::class)) {
199199
throw new LogicException('Unable to use expressions as the Symfony ExpressionLanguage component is not installed.');
200200
}
201201

202202
$providers = $this->container->getExpressionLanguageProviders();
203-
$this->expressionLanguage = new ExpressionLanguage(null, $providers, function ($arg) {
203+
$this->expressionLanguage = new ExpressionLanguage(null, $providers, function (string $arg): string {
204204
if ('""' === substr_replace($arg, '', 1, -1)) {
205205
$id = stripcslashes(substr($arg, 1, -1));
206206
$this->inExpression = true;

src/Symfony/Component/DependencyInjection/Compiler/AutowirePass.php

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,9 @@ protected function processValue($value, $isRoot = false)
8181
}
8282
}
8383

84+
/**
85+
* @return mixed
86+
*/
8487
private function doProcessValue($value, bool $isRoot = false)
8588
{
8689
if ($value instanceof TypedReference) {
@@ -311,7 +314,7 @@ private function getAutowiredReference(TypedReference $reference): ?TypedReferen
311314
/**
312315
* Populates the list of available types.
313316
*/
314-
private function populateAvailableTypes(ContainerBuilder $container)
317+
private function populateAvailableTypes(ContainerBuilder $container): void
315318
{
316319
$this->types = [];
317320
$this->ambiguousServiceTypes = [];
@@ -324,7 +327,7 @@ private function populateAvailableTypes(ContainerBuilder $container)
324327
/**
325328
* Populates the list of available types for a given definition.
326329
*/
327-
private function populateAvailableType(ContainerBuilder $container, string $id, Definition $definition)
330+
private function populateAvailableType(ContainerBuilder $container, string $id, Definition $definition): void
328331
{
329332
// Never use abstract services
330333
if ($definition->isAbstract()) {
@@ -347,7 +350,7 @@ private function populateAvailableType(ContainerBuilder $container, string $id,
347350
/**
348351
* Associates a type and a service id if applicable.
349352
*/
350-
private function set(string $type, string $id)
353+
private function set(string $type, string $id): void
351354
{
352355
// is this already a type/class that is known to match multiple services?
353356
if (isset($this->ambiguousServiceTypes[$type])) {
@@ -371,7 +374,7 @@ private function set(string $type, string $id)
371374
$this->ambiguousServiceTypes[$type][] = $id;
372375
}
373376

374-
private function createTypeNotFoundMessageCallback(TypedReference $reference, string $label)
377+
private function createTypeNotFoundMessageCallback(TypedReference $reference, string $label): callable
375378
{
376379
if (null === $this->typesClone->container) {
377380
$this->typesClone->container = new ContainerBuilder($this->container->getParameterBag());
@@ -386,7 +389,7 @@ private function createTypeNotFoundMessageCallback(TypedReference $reference, st
386389
})->bindTo($this->typesClone);
387390
}
388391

389-
private function createTypeNotFoundMessage(TypedReference $reference, string $label, string $currentId)
392+
private function createTypeNotFoundMessage(TypedReference $reference, string $label, string $currentId): string
390393
{
391394
if (!$r = $this->container->getReflectionClass($type = $reference->getType(), false)) {
392395
// either $type does not exist or a parent class does not exist
@@ -420,7 +423,7 @@ private function createTypeNotFoundMessage(TypedReference $reference, string $la
420423
return $message;
421424
}
422425

423-
private function createTypeAlternatives(ContainerBuilder $container, TypedReference $reference)
426+
private function createTypeAlternatives(ContainerBuilder $container, TypedReference $reference): string
424427
{
425428
// try suggesting available aliases first
426429
if ($message = $this->getAliasesSuggestionForType($container, $type = $reference->getType())) {
@@ -444,7 +447,7 @@ private function createTypeAlternatives(ContainerBuilder $container, TypedRefere
444447
return sprintf(' You should maybe alias this %s to %s.', class_exists($type, false) ? 'class' : 'interface', $message);
445448
}
446449

447-
private function getAliasesSuggestionForType(ContainerBuilder $container, string $type)
450+
private function getAliasesSuggestionForType(ContainerBuilder $container, string $type): ?string
448451
{
449452
$aliases = [];
450453
foreach (class_parents($type) + class_implements($type) as $parent) {

src/Symfony/Component/DependencyInjection/Compiler/CheckCircularReferencesPass.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public function process(ContainerBuilder $container)
5151
*
5252
* @throws ServiceCircularReferenceException when a circular reference is found
5353
*/
54-
private function checkOutEdges(array $edges)
54+
private function checkOutEdges(array $edges): void
5555
{
5656
foreach ($edges as $edge) {
5757
$node = $edge->getDestNode();

src/Symfony/Component/DependencyInjection/Compiler/Compiler.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public function addPass(CompilerPassInterface $pass, $type = PassConfig::TYPE_BE
6565
/**
6666
* @final
6767
*/
68-
public function log(CompilerPassInterface $pass, string $message)
68+
public function log(CompilerPassInterface $pass, string $message): void
6969
{
7070
if (false !== strpos($message, "\n")) {
7171
$message = str_replace("\n", "\n".\get_class($pass).': ', trim($message));

src/Symfony/Component/DependencyInjection/Compiler/MergeExtensionConfigurationPass.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ public function __construct(parent $parameterBag)
113113
$this->mergeEnvPlaceholders($parameterBag);
114114
}
115115

116-
public function freezeAfterProcessing(Extension $extension, ContainerBuilder $container)
116+
public function freezeAfterProcessing(Extension $extension, ContainerBuilder $container): void
117117
{
118118
if (!$config = $extension->getProcessedConfigs()) {
119119
// Extension::processConfiguration() wasn't called, we cannot know how configs were merged
@@ -175,15 +175,15 @@ public function addCompilerPass(CompilerPassInterface $pass, $type = PassConfig:
175175
/**
176176
* {@inheritdoc}
177177
*/
178-
public function registerExtension(ExtensionInterface $extension)
178+
public function registerExtension(ExtensionInterface $extension): void
179179
{
180180
throw new LogicException(sprintf('You cannot register extension "%s" from "%s". Extensions must be registered before the container is compiled.', \get_class($extension), $this->extensionClass));
181181
}
182182

183183 10000
/**
184184
* {@inheritdoc}
185185
*/
186-
public function compile(bool $resolveEnvPlaceholders = false)
186+
public function compile(bool $resolveEnvPlaceholders = false): void
187187
{
188188
throw new LogicException(sprintf('Cannot compile the container in extension "%s".', $this->extensionClass));
189189
}

src/Symfony/Component/DependencyInjection/Compiler/RegisterEnvVarProcessorsPass.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public function process(ContainerBuilder $container)
6060
}
6161
}
6262

63-
private static function validateProvidedTypes($types, $class)
63+
private static function validateProvidedTypes(string $types, string $class): array
6464
{
6565
$types = explode('|', $types);
6666

src/Symfony/Component/DependencyInjection/Compiler/ResolveBindingsPass.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,9 @@ protected function processValue($value, $isRoot = false)
205205
return parent::processValue($value, $isRoot);
206206
}
207207

208+
/**
209+
* @return mixed
210+
*/
208211
private function getBindingValue(BoundArgument $binding)
209212
{
210213
list($bindingValue, $bindingId) = $binding->getValues();

src/Symfony/Component/DependencyInjection/Compiler/ResolveHotPathPass.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class ResolveHotPathPass extends AbstractRecursivePass
2626
private $tagName;
2727
private $resolvedIds = [];
2828

29-
public function __construct($tagName = 'container.hot_path')
29+
public function __construct(string $tagName = 'container.hot_path')
3030
{
3131
$this->tagName = $tagName;
3232
}

src/Symfony/Component/DependencyInjection/Compiler/ResolveInstanceofConditionalsPass.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public function process(ContainerBuilder $container)
4444
}
4545
}
4646

47-
private function processDefinition(ContainerBuilder $container, string $id, Definition $definition)
47+
private function processDefinition(ContainerBuilder $container, string $id, Definition $definition): Definition
4848
{
4949
$instanceofConditionals = $definition->getInstanceofConditionals();
5050
$autoconfiguredInstanceof = $definition->isAutoconfigured() ? $container->getAutoconfiguredInstanceof() : [];
@@ -144,7 +144,7 @@ private function processDefinition(ContainerBuilder $container, string $id, Defi
144144
return $definition;
145145
}
146146

147-
private function mergeConditionals(array $autoconfiguredInstanceof, array $instanceofConditionals, ContainerBuilder $container)
147+
private function mergeConditionals(array $autoconfiguredInstanceof, array $instanceofConditionals, ContainerBuilder $container): array
148148
{
149149
// make each value an array of ChildDefinition
150150
$conditionals = array_map(function ($childDef) { return [$childDef]; }, $autoconfiguredInstanceof);

src/Symfony/Component/DependencyInjection/Compiler/ResolveInvalidReferencesPass.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ public function process(ContainerBuilder $container)
5151
/**
5252
* Processes arguments to determine invalid references.
5353
*
54+
* @return mixed
55+
*
5456
* @throws RuntimeException When an invalid reference is found
5557
*/
5658
private function processValue($value, int $rootLevel = 0, int $level = 0)

src/Symfony/Component/DependencyInjection/Compiler/ServiceLocatorTagPass.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,11 +88,8 @@ protected function processValue($value, $isRoot = false)
8888

8989
/**
9090
* @param Reference[] $refMap
91-
* @param string|null $callerId
92-
*
93-
* @return Reference
9491
*/
95-
public static function register(ContainerBuilder $container, array $refMap, $callerId = null)
92+
public static function register(ContainerBuilder $container, array $refMap, string $callerId = null): Reference
9693
{
9794
foreach ($refMap as $id => $ref) {
9895
if (!$ref instanceof Reference) {

src/Symfony/Component/DependencyInjection/Compiler/ServiceReferenceGraph.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public function getNodes(): array
6262
/**
6363
* Clears all nodes.
6464
*/
65-
public function clear()
65+
public function clear(): void
6666
{
6767
foreach ($this->nodes as $node) {
6868
$node->clear();
@@ -73,7 +73,7 @@ public function clear()
7373
/**
7474
* Connects 2 nodes together in the Graph.
7575
*/
76-
public function connect(?string $sourceId, $sourceValue, ?string $destId, $destValue = null, $reference = null, bool $lazy = false, bool $weak = false, bool $byConstructor = false)
76+
public function connect(?string $sourceId, $sourceValue, ?string $destId, $destValue = null, $reference = null, bool $lazy = false, bool $weak = false, bool $byConstructor = false): void
7777
{
7878
if (null === $sourceId || null === $destId) {
7979
return;

src/Symfony/Component/DependencyInjection/Container.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -424,9 +424,14 @@ protected function getEnv($name)
424424
}
425425

426426
/**
427+
* @param string|false $registry
428+
* @param string|bool $load
429+
*
430+
* @return mixed
431+
*
427432
* @internal
428433
*/
429-
final protected function getService($registry, $id, $method, $load)
434+
final protected function getService($registry, string $id, ?string $method, $load)
430435
{
431436
if ('service_container' === $id) {
432437
return $this;

src/Symfony/Component/DependencyInjection/ContainerBuilder.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1236,7 +1236,7 @@ private function doResolveServices($value, array &$inlineServices = [], bool $is
12361236

12371237
yield $k => $this->resolveServices($v);
12381238
}
1239-
}, function () use ($value) {
1239+
}, function () use ($value): int {
12401240
$count = 0;
12411241
foreach ($value->getValues() as $v) {
12421242
foreach (self::getServiceConditionals($v) as $s) {
@@ -1488,7 +1488,7 @@ public function getEnvCounters()
14881488
/**
14891489
* @final
14901490
*/
1491-
public function log(CompilerPassInterface $pass, string $message)
1491+
public function log(CompilerPassInterface $pass, string $message): void
14921492
{
14931493
$this->getCompiler()->log($pass, $this->resolveEnvPlaceholders($message));
14941494
}
@@ -1508,7 +1508,7 @@ public function getRemovedBindingIds(): array
15081508
*
15091509
* @internal
15101510
*/
1511-
public function removeBindings(string $id)
1511+
public function removeBindings(string $id): void
15121512
{
15131513
if ($this->hasDefinition($id)) {
15141514
foreach ($this->getDefinition($id)->getBindings() as $key => $binding) {
@@ -1631,7 +1631,7 @@ private function callMethod($service, array $call, array &$inlineServices)
16311631
*
16321632
* @param mixed $service
16331633
*/
1634-
private function shareService(Definition $definition, $service, ?string $id, array &$inlineServices)
1634+
private function shareService(Definition $definition, $service, ?string $id, array &$inlineServices): void
16351635
{
16361636
$inlineServices[null !== $id ? $id : spl_object_hash($definition)] = $service;
16371637

@@ -1641,7 +1641,7 @@ private function shareService(Definition $definition, $service, ?string $id, arr
16411641
}
16421642
}
16431643

1644-
private function getExpressionLanguage()
1644+
private function getExpressionLanguage(): ExpressionLanguage
16451645
{
16461646
if (null === $this->expressionLanguage) {
16471647
if (!class_exists('Symfony\Component\ExpressionLanguage\ExpressionLanguage')) {
@@ -1653,7 +1653,7 @@ private function getExpressionLanguage()
16531653
return $this->expressionLanguage;
16541654
}
16551655

1656-
private function inVendors(string $path)
1656+
private function inVendors(string $path): bool
16571657
{
16581658
if (null === $this->vendors) {
16591659
$resource = new ComposerResource();

src/Symfony/Component/DependencyInjection/Dumper/GraphvizDumper.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ private function findNodes(): array
183183
return $nodes;
184184
}
185185

186-
private function cloneContainer()
186+
private function cloneContainer(): ContainerBuilder
187187
{
188188
$parameterBag = new ParameterBag($this->container->getParameterBag()->all());
189189

0 commit comments

Comments
 (0)
0