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

Skip to content

Commit def0ac7

Browse files
committed
Add types to private/final/internal methods and constructors.
1 parent afad962 commit def0ac7

23 files changed

+59
-36
lines changed

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

Lines changed: 3 additions & 2 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;
@@ -137,7 +138,7 @@ public function getRemovedIds(): array
137138
return $this->getPublicContainer()->getRemovedIds();
138139
}
139140

140-
private function getPublicContainer()
141+
private function getPublicContainer(): Container
141142
{
142143
if (null === $container = $this->kernel->getContainer()) {
143144
throw new \LogicException('Cannot access the container on a non-booted kernel. Did you forget to boot it?');
@@ -146,7 +147,7 @@ private function getPublicContainer()
146147
return $container;
147148
}
148149

149-
private function getPrivateContainer()
150+
private function getPrivateContainer(): ContainerInterface
150151
{
151152
return $this->getPublicContainer()->get($this->privateServicesLocatorId);
152153
}

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: 7 additions & 4 deletions
< F42D /table>

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

Lines changed: 1 addition & 1 deletion
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) {
@@ -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) {
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 & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,8 @@ protected function processValue($value, $isRoot = false)
8888

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

src/Symfony/Component/DependencyInjection/Container.php

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

424424
/**
425+
* @param string|false $registry
426+
* @param string|bool $load
427+
*
428+
* @return mixed
429+
*
425430
* @internal
426431
*/
427-
final protected function getService($registry, $id, $method, $load)
432+
final protected function getService($registry, string $id, ?string $method, $load)
428433
{
429434
if ('service_container' === $id) {
430435
return $this;

src/Symfony/Component/DependencyInjection/ContainerBuilder.php

Lines changed: 3 additions & 3 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) {
@@ -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

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

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -684,7 +684,7 @@ private function addServiceMethodCalls(Definition $definition, string $variableN
684684
return $calls;
685685
}
686686

687-
private function addServiceProperties(Definition $definition, string $variableName = 'instance')
687+
private function addServiceProperties(Definition $definition, string $variableName = 'instance'): string
688688
{
689689
$code = '';
690690
foreach ($definition->getProperties() as $name => $value) {
@@ -967,7 +967,7 @@ private function addServices(array &$services = null): string
967967
return $publicServices.$privateServices;
968968
}
969969

970-
private function generateServiceFiles(array $services)
970+
private function generateServiceFiles(array $services): iterable
971971
{
972972
$definitions = $this->container->getDefinitions();
973973
ksort($definitions);
@@ -993,7 +993,7 @@ private function generateServiceFiles(array $services)
993993
}
994994
}
995995

996-
private function addNewInstance(Definition $definition, string $return = '', string $id = null)
996+
private function addNewInstance(Definition $definition, string $return = '', string $id = null): string
997997
{
998998
$tail = $return ? ";\n" : '';
999999

@@ -1914,7 +1914,7 @@ private function getNextVariableName(): string
19141914
}
19151915
}
19161916

1917-
private function getExpressionLanguage()
1917+
private function getExpressionLanguage(): ExpressionLanguage
19181918
{
19191919
if (null === $this->expressionLanguage) {
19201920
if (!class_exists('Symfony\Component\ExpressionLanguage\ExpressionLanguage')) {
@@ -1941,7 +1941,7 @@ private function getExpressionLanguage()
19411941
return $this->expressionLanguage;
19421942
}
19431943

1944-
private function isHotPath(Definition $definition)
1944+
private function isHotPath(Definition $definition): bool
19451945
{
19461946
return $this->hotPathTag && $definition->hasTag($this->hotPathTag) && !$definition->isDeprecated();
19471947
}
@@ -1965,6 +1965,9 @@ private function isSingleUsePrivateNode(ServiceReferenceGraphNode $node): bool
19651965
return 1 === \count($ids);
19661966
}
19671967

1968+
/**
1969+
* @return mixed
1970+
*/
19681971
private function export($value)
19691972
{
19701973
if (null !== $this->targetDirRegex && \is_string($value) && preg_match($this->targetDirRegex, $value, $matches, PREG_OFFSET_CAPTURE)) {
@@ -1988,6 +1991,9 @@ private function export($value)
19881991
return $this->doExport($value, true);
19891992
}
19901993

1994+
/**
1995+
* @return mixed
1996+
*/
19911997
private function doExport($value, bool $resolveEnv = false)
19921998
{
19931999
$shouldCacheValue = $resolveEnv && \is_string($value);

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -338,11 +338,9 @@ private function escape(array $arguments): array
338338
*
339339
* @param mixed $value Value to convert
340340
*
341-
* @return string
342-
*
343341
* @throws RuntimeException When trying to dump object or resource
344342
*/
345-
public static function phpToXml($value)
343+
public static function phpToXml($value): string
346344
{
347345
switch (true) {
348346
case null === $value:

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,8 @@ private function addParameters(): string
201201
* Dumps callable to YAML format.
202202
*
203203
* @param mixed $callable
204+
*
205+
* @return mixed
204206
*/
205207
private function dumpCallable($callable)
206208
{
@@ -299,7 +301,7 @@ private function getParameterCall(string $id): string
299301
return sprintf('%%%s%%', $id);
300302
}
301303

302-
private function getExpressionCall(string $expression)
304+
private function getExpressionCall(string $expression): string
303305
{
304306
return sprintf('@=%s', $expression);
305307
}

src/Symfony/Component/DependencyInjection/Extension/Extension.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ final protected function processConfiguration(ConfigurationInterface $configurat
111111
/**
112112
* @internal
113113
*/
114-
final public function getProcessedConfigs()
114+
final public function getProcessedConfigs(): array
115115
{
116116
try {
117117
return $this->processedConfigs;

src/Symfony/Component/DependencyInjection/Loader/Configurator/PrototypeConfigurator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ public function __destruct()
7575
*
7676
* @return $this
7777
*/
78-
final public function exclude($excludes)
78+
final public function exclude($excludes): self
7979
{
8080
$this->excludes = (array) $excludes;
8181

src/Symfony/Component/DependencyInjection/Loader/FileLoader.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ protected function setDefinition($id, Definition $definition)
102102
}
103103
}
104104

105-
private function findClasses(string $namespace, string $pattern, array $excludePatterns)
105+
private function findClasses(string $namespace, string $pattern, array $excludePatterns): array
106106
{
107107
$parameterBag = $this->container->getParameterBag();
108108

src/Symfony/Component/DependencyInjection/Loader/IniFileLoader.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ public function supports($resource, $type = null)
6666
* Note that the following features are not supported:
6767
* * strings with escaped quotes are not supported "foo\"bar";
6868
* * string concatenation ("foo" "bar").
69+
*
70+
* @return mixed
6971
*/
7072
private function phpize(string $value)
7173
{

src/Symfony/Component/DependencyInjection/Loader/XmlFileLoader.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -435,7 +435,7 @@ private function processAnonymousServices(\DOMDocument $xml, string $file)
435435
}
436436
}
437437

438-
private function getArgumentsAsPhp(\DOMElement $node, string $name, string $file, bool $isChildDefinition = false)
438+
private function getArgumentsAsPhp(\DOMElement $node, string $name, string $file, bool $isChildDefinition = false): array
439439
{
440440
$arguments = [];
441441
foreach ($this->getChildren($node, $name) as $arg) {

src/Symfony/Component/DependencyInjection/ServiceLocator.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,10 @@ public function __invoke($id)
6464

6565
/**
6666
* @internal
67+
*
68+
* @return static
6769
*/
68-
public function withContext($externalId, Container $container)
70+
10000 public function withContext(string $externalId, Container $container)
6971
{
7072
$locator = clone $this;
7173
$locator->externalId = $externalId;
@@ -127,7 +129,7 @@ private function createCircularReferenceException(string $id, array $path): Cont
127129
return new ServiceCircularReferenceException($id, $path);
128130
}
129131

130-
private function formatAlternatives(array $alternatives = null, string $separator = 'and')
132+
private function formatAlternatives(array $alternatives = null, string $separator = 'and'): string
131133
{
132134
$format = '"%s"%s';
133135
if (null === $alternatives) {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public function testBindingsShouldBeResolved()
7171
$this->assertSame($this->container->getParameterBag()->resolveValue('%env(BAZ)%'), $boundValue);
7272
}
7373

74-
private function createContainerBuilder()
74+
private function createContainerBuilder(): ContainerBuilder
7575
{
7676
$containerBuilder = new ContainerBuilder();
7777

src/Symfony/Component/DependencyInjection/Tests/Dumper/YamlDumperTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ public function testTaggedArguments()
110110
$this->assertStringEqualsFile(self::$fixturesPath.'/yaml/services_with_tagged_argument.yml', $dumper->dump());
111111
}
112112

113-
private function assertEqualYamlStructure($expected, $yaml, $message = '')
113+
private function assertEqualYamlStructure(string $expected, string $yaml, string $message = '')
114114
{
115115
$parser = new Parser();
116116

0 commit comments

Comments
 (0)
0