Skip to content

Commit cee0489

Browse files
Enforce return types on all components
1 parent 0144981 commit cee0489

33 files changed

+84
-920
lines changed

.github/expected-missing-return-types.diff

Lines changed: 0 additions & 659 deletions
This file was deleted.

.github/patch-types.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,7 @@
4444
case false !== strpos($file, '/src/Symfony/Component/DependencyInjection/Tests/Fixtures/Prototype/BadClasses/MissingParent.php'):
4545
case false !== strpos($file, '/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/'):
4646
case false !== strpos($file, '/src/Symfony/Component/ErrorHandler/Tests/Fixtures/'):
47-
case false !== strpos($file, '/src/Symfony/Component/HttpClient/Internal/') && str_contains($file, 'V5'):
48-
case false !== strpos($file, '/src/Symfony/Component/PropertyAccess/Tests/Fixtures/AsymmetricVisibility.php'):
47+
case false !== strpos($file, '/src/Symfony/Component/HttpClient/Internal/') && str_contains($file, 'V4'):
4948
case false !== strpos($file, '/src/Symfony/Component/PropertyInfo/Tests/Fixtures/'):
5049
case false !== strpos($file, '/src/Symfony/Component/Runtime/Internal/ComposerPlugin.php'):
5150
case false !== strpos($file, '/src/Symfony/Component/Security/Http/Tests/Fixtures/IsGrantedAttributeMethodsWithClosureController.php'):
@@ -55,7 +54,6 @@
5554
case false !== strpos($file, '/src/Symfony/Component/Validator/Tests/Constraints/Fixtures/WhenTestWithClosure.php'):
5655
case false !== strpos($file, '/src/Symfony/Component/Validator/Tests/Fixtures/NestedAttribute/Entity.php'):
5756
case false !== strpos($file, '/src/Symfony/Component/VarDumper/Tests/Fixtures/NotLoadableClass.php'):
58-
case false !== strpos($file, '/src/Symfony/Component/VarDumper/Tests/Fixtures/VirtualProperty.php'):
5957
case false !== strpos($file, '/src/Symfony/Component/VarExporter/Internal'):
6058
case false !== strpos($file, '/src/Symfony/Component/VarExporter/Tests/Fixtures/'):
6159
case false !== strpos($file, '/src/Symfony/Contracts/'):

.github/workflows/unit-tests.yml

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -148,22 +148,12 @@ jobs:
148148
./phpunit install
149149
echo "::endgroup::"
150150
151-
- name: Patch return types
151+
- name: Check return types
152152
if: "matrix.php == '8.4' && ! matrix.mode"
153153
run: |
154-
patch -sp1 < .github/expected-missing-return-types.diff
155-
git add .
156154
sed -i 's/ *"\*\*\/Tests\/",//' composer.json
157155
composer install -q --optimize-autoloader || composer install --optimize-autoloader
158-
SYMFONY_PATCH_TYPE_DECLARATIONS='force=2&php=8.4' php .github/patch-types.php
159-
git checkout composer.json src/Symfony/Contracts/Service/ResetInterface.php
160-
SYMFONY_PATCH_TYPE_DECLARATIONS='force=2&php=8.4' php .github/patch-types.php # ensure the script is idempotent
161-
git checkout src/Symfony/Contracts/Service/ResetInterface.php
162-
git diff --exit-code
163-
164-
- name: Check return types
165-
if: "matrix.php == '8.4' && ! matrix.mode"
166-
run: |
156+
git checkout composer.json
167157
php .github/patch-types.php lint
168158
169159
- name: Run tests
@@ -209,7 +199,7 @@ jobs:
209199
PATCHED_COMPONENTS=$(git diff --name-only src/ | grep composer.json || true)
210200
211201
# for 7.4 LTS, checkout and test previous major with the patched components (only for patched components)
212-
if [[ $PATCHED_COMPONENTS && $SYMFONY_VERSION = 7.4 ]]; then
202+
if [[ $PATCHED_COMPONENTS && $SYMFONY_VERSION = 7.4 && $FLIP = '' ]]; then
213203
export FLIP='^'
214204
SYMFONY_VERSION=$(echo $SYMFONY_VERSION | awk '{print $1 - 1}')
215205
echo -e "\\n\\e[33;1mChecking out Symfony $SYMFONY_VERSION and running tests with patched components as deps\\e[0m"

src/Symfony/Bridge/Twig/Test/Traits/RuntimeLoaderProvider.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,7 @@
1717

1818
trait RuntimeLoaderProvider
1919
{
20-
/**
21-
* @return void
22-
*/
23-
protected function registerTwigRuntimeLoader(Environment $environment, FormRenderer $renderer)
20+
protected function registerTwigRuntimeLoader(Environment $environment, FormRenderer $renderer): void
2421
{
2522
$loader = $this->createMock(RuntimeLoaderInterface::class);
2623
$loader->expects($this->any())->method('load')->willReturnMap([

src/Symfony/Component/BrowserKit/AbstractBrowser.php

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -413,13 +413,11 @@ public function request(string $method, string $uri, array $parameters = [], arr
413413
*
414414
* @psalm-param TRequest $request
415415
*
416-
* @return object
417-
*
418416
* @psalm-return TResponse
419417
*
420418
* @throws \RuntimeException When processing returns exit code
421419
*/
422-
protected function doRequestInProcess(object $request)
420+
protected function doRequestInProcess(object $request): object
423421
{
424422
$deprecationsFile = tempnam(sys_get_temp_dir(), 'deprec');
425423
putenv('SYMFONY_DEPRECATIONS_SERIALIZE='.$deprecationsFile);
@@ -452,11 +450,9 @@ protected function doRequestInProcess(object $request)
452450
*
453451
* @psalm-param TRequest $request
454452
*
455-
* @return object
456-
*
457453
* @psalm-return TResponse
458454
*/
459-
abstract protected function doRequest(object $request);
455+
abstract protected function doRequest(object $request): object;
460456

461457
/**
462458
* Returns the script to execute when the request must be insulated.
@@ -465,23 +461,19 @@ abstract protected function doRequest(object $request);
465461
*
466462
* @param object $request An origin request instance
467463
*
468-
* @return string
469-
*
470464
* @throws LogicException When this abstract class is not implemented
471465
*/
472-
protected function getScript(object $request)
466+
protected function getScript(object $request): string
473467
{
474468
throw new LogicException('To insulate requests, you need to override the getScript() method.');
475469
}
476470

477471
/**
478472
* Filters the BrowserKit request to the origin one.
479473
*
480-
* @return object
481-
*
482474
* @psalm-return TRequest
483475
*/
484-
protected function filterRequest(Request $request)
476+
protected function filterRequest(Request $request): object
485477
{
486478
return $request;
487479
}
@@ -490,10 +482,8 @@ protected function filterRequest(Request $request)
490482
* Filters the origin response to the BrowserKit one.
491483
*
492484
* @psalm-param TResponse $response
493-
*
494-
* @return Response
495485
*/
496-
protected function filterResponse(object $response)
486+
protected function filterResponse(object $response): Response
497487
{
498488
return $response;
499489
}

src/Symfony/Component/Console/Command/Command.php

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -197,10 +197,8 @@ public function isEnabled(): bool
197197

198198
/**
199199
* Configures the current command.
200-
*
201-
* @return void
202200
*/
203-
protected function configure()
201+
protected function configure(): void
204202
{
205203
}
206204

@@ -229,10 +227,8 @@ protected function execute(InputInterface $input, OutputInterface $output): int
229227
* This method is executed before the InputDefinition is validated.
230228
* This means that this is the only place where the command can
231229
* interactively ask for values of missing required arguments.
232-
*
233-
* @return void
234230
*/
235-
protected function interact(InputInterface $input, OutputInterface $output)
231+
protected function interact(InputInterface $input, OutputInterface $output): void
236232
{
237233
}
238234

@@ -245,10 +241,8 @@ protected function interact(InputInterface $input, OutputInterface $output)
245241
*
246242
* @see InputInterface::bind()
247243
* @see InputInterface::validate()
248-
*
249-
* @return void
250244
*/
251-
protected function initialize(InputInterface $input, OutputInterface $output)
245+
protected function initialize(InputInterface $input, OutputInterface $output): void
252246
{
253247
}
254248

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

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,7 @@ abstract class AbstractRecursivePass implements CompilerPassInterface
3434
private ExpressionLanguage $expressionLanguage;
3535
private bool $inExpression = false;
3636

37-
/**
38-
* @return void
39-
*/
40-
public function process(ContainerBuilder $container)
37+
public function process(ContainerBuilder $container): void
4138
{
4239
$this->container = $container;
4340

@@ -65,10 +62,8 @@ protected function inExpression(bool $reset = true): bool
6562

6663
/**
6764
* Processes a value found in a definition tree.
68-
*
69-
* @return mixed
7065
*/
71-
protected function processValue(mixed $value, bool $isRoot = false)
66+
protected function processValue(mixed $value, bool $isRoot = false): mixed
7267
{
7368
if (\is_array($value)) {
7469
foreach ($value as $k => $v) {

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@ interface CompilerPassInterface
2222
{
2323
/**
2424
* You can modify the container here before it is dumped to PHP code.
25-
*
26-
* @return void
2725
*/
28-
public function process(ContainerBuilder $container);
26+
public function process(ContainerBuilder $container): void;
2927
}

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

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,5 @@
2121
*/
2222
interface ConfigurationExtensionInterface
2323
{
24-
/**
25-
* Returns extension configuration.
26-
*
27-
* @return ConfigurationInterface|null
28-
*/
29-
public function getConfiguration(array $config, ContainerBuilder $container);
24+
public function getConfiguration(array $config, ContainerBuilder $container): ?ConfigurationInterface;
3025
}

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

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -28,18 +28,12 @@ abstract class Extension implements ExtensionInterface, ConfigurationExtensionIn
2828
{
2929
private array $processedConfigs = [];
3030

31-
/**
32-
* @return string|false
33-
*/
34-
public function getXsdValidationBasePath()
31+
public function getXsdValidationBasePath(): string|false
3532
{
3633
return false;
3734
}
3835

39-
/**
40-
* @return string
41-
*/
42-
public function getNamespace()
36+
public function getNamespace(): string
4337
{
4438
return 'http://example.org/schema/dic/'.$this->getAlias();
4539
}
@@ -73,10 +67,7 @@ public function getAlias(): string
7367
return Container::underscore($classBaseName);
7468
}
7569

76-
/**
77-
* @return ConfigurationInterface|null
78-
*/
79-
public function getConfiguration(array $config, ContainerBuilder $container)
70+
public function getConfiguration(array $config, ContainerBuilder $container): ?ConfigurationInterface
8071
{
8172
$class = static::class;
8273

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

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -25,32 +25,24 @@ interface ExtensionInterface
2525
*
2626
* @param array<array<mixed>> $configs
2727
*
28-
* @return void
29-
*
3028
* @throws \InvalidArgumentException When provided tag is not defined in this extension
3129
*/
32-
public function load(array $configs, ContainerBuilder $container);
30+
public function load(array $configs, ContainerBuilder $container): void;
3331

3432
/**
3533
* Returns the namespace to be used for this extension (XML namespace).
36-
*
37-
* @return string
3834
*/
39-
public function getNamespace();
35+
public function getNamespace(): string;
4036

4137
/**
4238
* Returns the base path for the XSD files.
43-
*
44-
* @return string|false
4539
*/
46-
public function getXsdValidationBasePath();
40+
public function getXsdValidationBasePath(): string|false;
4741

4842
/**
4943
* Returns the recommended alias to use in XML.
5044
*
5145
* This alias is also the mandatory prefix to use when using YAML.
52-
*
53-
* @return string
5446
*/
55-
public function getAlias();
47+
public function getAlias(): string;
5648
}

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@ interface PrependExtensionInterface
1717
{
1818
/**
1919
* Allow an extension to prepend the extension configurations.
20-
*
21-
* @return void
2220
*/
23-
public function prepend(ContainerBuilder $container);
21+
public function prepend(ContainerBuilder $container): void;
2422
}

src/Symfony/Component/Emoji/EmojiTransliterator.php

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -83,20 +83,12 @@ public function createInverse(): self
8383
return self::create($this->id, \Transliterator::REVERSE);
8484
}
8585

86-
/**
87-
* @return int
88-
*/
89-
#[\ReturnTypeWillChange]
90-
public function getErrorCode(): int|false
86+
public function getErrorCode(): int
9187
{
9288
return isset($this->transliterator) ? $this->transliterator->getErrorCode() : 0;
9389
}
9490

95-
/**
96-
* @return string
97-
*/
98-
#[\ReturnTypeWillChange]
99-
public function getErrorMessage(): string|false
91+
public function getErrorMessage(): string
10092
{
10193
return isset($this->transliterator) ? $this->transliterator->getErrorMessage() : '';
10294
}

src/Symfony/Component/EventDispatcher/EventSubscriberInterface.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,5 +45,5 @@ interface EventSubscriberInterface
4545
*
4646
* @return array<string, string|array{0: string, 1: int}|list<array{0: string, 1?: int}>>
4747
*/
48-
public static function getSubscribedEvents();
48+
public static function getSubscribedEvents(): array;
4949
}

src/Symfony/Component/ExpressionLanguage/ExpressionLanguage.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -145,10 +145,7 @@ public function registerProvider(ExpressionFunctionProviderInterface $provider):
145145
}
146146
}
147147

148-
/**
149-
* @return void
150-
*/
151-
protected function registerFunctions()
148+
protected function registerFunctions(): void
152149
{
153150
$basicPhpFunctions = ['constant', 'min', 'max'];
154151
foreach ($basicPhpFunctions as $function) {

src/Symfony/Component/Form/AbstractType.php

Lines changed: 6 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -20,46 +20,28 @@
2020
*/
2121
abstract class AbstractType implements FormTypeInterface
2222
{
23-
/**
24-
* @return string|null
25-
*/
26-
public function getParent()
23+
public function getParent(): ?string
2724
{
2825
return FormType::class;
2926
}
3027

31-
/**
32-
* @return void
33-
*/
34-
public function configureOptions(OptionsResolver $resolver)
28+
public function configureOptions(OptionsResolver $resolver): void
3529
{
3630
}
3731

38-
/**
39-
* @return void
40-
*/
41-
public function buildForm(FormBuilderInterface $builder, array $options)
32+
public function buildForm(FormBuilderInterface $builder, array $options): void
4233
{
4334
}
4435

45-
/**
46-
* @return void
47-
*/
48-
public function buildView(FormView $view, FormInterface $form, array $options)
36+
public function buildView(FormView $view, FormInterface $form, array $options): void
4937
{
5038
}
5139

52-
/**
53-
* @return void
54-
*/
55-
public function finishView(FormView $view, FormInterface $form, array $options)
40+
public function finishView(FormView $view, FormInterface $form, array $options): void
5641
{
5742
}
5843

59-
/**
60-
* @return string
61-
*/
62-
public function getBlockPrefix()
44+
public function getBlockPrefix(): string
6345
{
6446
return StringUtil::fqcnToBlockPrefix(static::class) ?: '';
6547
}

0 commit comments

Comments
 (0)