8000 Enforce return types on all components by nicolas-grekas · Pull Request #60697 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

Enforce return types on all components #60697

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 5, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
659 changes: 0 additions & 659 deletions .github/expected-missing-return-types.diff

This file was deleted.

4 changes: 1 addition & 3 deletions .github/patch-types.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,7 @@
case false !== strpos($file, '/src/Symfony/Component/DependencyInjection/Tests/Fixtures/Prototype/BadClasses/MissingParent.php'):
case false !== strpos($file, '/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/'):
case false !== strpos($file, '/src/Symfony/Component/ErrorHandler/Tests/Fixtures/'):
case false !== strpos($file, '/src/Symfony/Component/HttpClient/Internal/') && str_contains($file, 'V5'):
case false !== strpos($file, '/src/Symfony/Component/PropertyAccess/Tests/Fixtures/AsymmetricVisibility.php'):
case false !== strpos($file, '/src/Symfony/Component/HttpClient/Internal/') && str_contains($file, 'V4'):
case false !== strpos($file, '/src/Symfony/Component/PropertyInfo/Tests/Fixtures/'):
case false !== strpos($file, '/src/Symfony/Component/Runtime/Internal/ComposerPlugin.php'):
case false !== strpos($file, '/src/Symfony/Component/Security/Http/Tests/Fixtures/IsGrantedAttributeMethodsWithClosureController.php'):
Expand All @@ -55,7 +54,6 @@
case false !== strpos($file, '/src/Symfony/Component/Validator/Tests/Constraints/Fixtures/WhenTestWithClosure.php'):
case false !== strpos($file, '/src/Symfony/Component/Validator/Tests/Fixtures/NestedAttribute/Entity.php'):
case false !== strpos($file, '/src/Symfony/Component/VarDumper/Tests/Fixtures/NotLoadableClass.php'):
case false !== strpos($file, '/src/Symfony/Component/VarDumper/Tests/Fixtures/VirtualProperty.php'):
case false !== strpos($file, '/src/Symfony/Component/VarExporter/Internal'):
case false !== strpos($file, '/src/Symfony/Component/VarExporter/Tests/Fixtures/'):
case false !== strpos($file, '/src/Symfony/Contracts/'):
Expand Down
16 changes: 3 additions & 13 deletions .github/workflows/unit-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -148,22 +148,12 @@ jobs:
./phpunit install
echo "::endgroup::"

- name: Patch return types
- name: Check return types
if: "matrix.php == '8.4' && ! matrix.mode"
run: |
patch -sp1 < .github/expected-missing-return-types.diff
git add .
sed -i 's/ *"\*\*\/Tests\/",//' composer.json
composer install -q --optimize-autoloader || composer install --optimize-autoloader
SYMFONY_PATCH_TYPE_DECLARATIONS='force=2&php=8.4' php .github/patch-types.php
git checkout composer.json src/Symfony/Contracts/Service/ResetInterface.php
SYMFONY_PATCH_TYPE_DECLARATIONS='force=2&php=8.4' php .github/patch-types.php # ensure the script is idempotent
git checkout src/Symfony/Contracts/Service/ResetInterface.php
git diff --exit-code

- name: Check return types
if: "matrix.php == '8.4' && ! matrix.mode"
run: |
git checkout composer.json
php .github/patch-types.php lint

- name: Run tests
Expand Down Expand Up @@ -209,7 +199,7 @@ jobs:
PATCHED_COMPONENTS=$(git diff --name-only src/ | grep composer.json || true)

# for 7.4 LTS, checkout and test previous major with the patched components (only for patched components)
if [[ $PATCHED_COMPONENTS && $SYMFONY_VERSION = 7.4 ]]; then
if [[ $PATCHED_COMPONENTS && $SYMFONY_VERSION = 7.4 && $FLIP = '' ]]; then
export FLIP='^'
SYMFONY_VERSION=$(echo $SYMFONY_VERSION | awk '{print $1 - 1}')
echo -e "\\n\\e[33;1mChecking out Symfony $SYMFONY_VERSION and running tests with patched components as deps\\e[0m"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,7 @@

trait RuntimeLoaderProvider
{
/**
* @return void
*/
protected function registerTwigRuntimeLoader(Environment $environment, FormRenderer $renderer)
protected function registerTwigRuntimeLoader(Environment $environment, FormRenderer $renderer): void
{
$loader = $this->createMock(RuntimeLoaderInterface::class);
$loader->expects($this->any())->method('load')->willReturnMap([
Expand Down
20 changes: 5 additions & 15 deletions src/Symfony/Component/BrowserKit/AbstractBrowser.php
Original file line number Diff line number Diff line change
Expand Up @@ -413,13 +413,11 @@ public function request(string $method, string $uri, array $parameters = [], arr
*
* @psalm-param TRequest $request
*
* @return object
*
* @psalm-return TResponse
*
* @throws \RuntimeException When processing returns exit code
*/
protected function doRequestInProcess(object $request)
protected function doRequestInProcess(object $request): object
{
$deprecationsFile = tempnam(sys_get_temp_dir(), 'deprec');
putenv('SYMFONY_DEPRECATIONS_SERIALIZE='.$deprecationsFile);
Expand Down Expand Up @@ -452,11 +450,9 @@ protected function doRequestInProcess(object $request)
*
* @psalm-param TRequest $request
*
* @return object
*
* @psalm-return TResponse
*/
abstract protected function doRequest(object $request);
abstract protected function doRequest(object $request): object;

/**
* Returns the script to execute when the request must be insulated.
Expand All @@ -465,23 +461,19 @@ abstract protected function doRequest(object $request);
*
* @param object $request An origin request instance
*
* @return string
*
* @throws LogicException When this abstract class is not implemented
*/
protected function getScript(object $request)
protected function getScript(object $request): string
{
throw new LogicException('To insulate requests, you need to override the getScript() method.');
}

/**
* Filters the BrowserKit request to the origin one.
*
* @return object
*
* @psalm-return TRequest
*/
protected function filterRequest(Request $request)
protected function filterRequest(Request $request): object
{
return $request;
}
Expand All @@ -490,10 +482,8 @@ protected function filterRequest(Request $request)
* Filters the origin response to the BrowserKit one.
*
* @psalm-param TResponse $response
*
* @return Response
*/
protected function filterResponse(object $response)
protected function filterResponse(object $response): Response
{
return $response;
}
Expand Down
12 changes: 3 additions & 9 deletions src/Symfony/Component/Console/Command/Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -197,10 +197,8 @@ public function isEnabled(): bool

/**
* Configures the current command.
*
* @return void
*/
protected function configure()
protected function configure(): void
{
}

Expand Down Expand Up @@ -229,10 +227,8 @@ protected function execute(InputInterface $input, OutputInterface $output): int
* This method is executed before the InputDefinition is validated.
* This means that this is the only place where the command can
* interactively ask for values of missing required arguments.
*
* @return void
*/
protected function interact(InputInterface $input, OutputInterface $output)
protected function interact(InputInterface $input, OutputInterface $output): void
{
}

Expand All @@ -245,10 +241,8 @@ protected function interact(InputInterface $input, OutputInterface $output)
*
* @see InputInterface::bind()
* @see InputInterface::validate()
*
* @return void
*/
protected function initialize(InputInterface $input, OutputInterface $output)
protected function initialize(InputInterface $input, OutputInterface $output): void
{
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,7 @@ abstract class AbstractRecursivePass implements CompilerPassInterface
private ExpressionLanguage $expressionLanguage;
private bool $inExpression = false;

/**
* @return void
*/
public function process(ContainerBuilder $container)
public function process(ContainerBuilder $container): void
{
$this->container = $container;

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

/**
* Processes a value found in a definition tree.
*
* @return mixed
*/
protected function processValue(mixed $value, bool $isRoot = false)
protected function processValue(mixed $value, bool $isRoot = false): mixed
{
if (\is_array($value)) {
foreach ($value as $k => $v) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ interface CompilerPassInterface
{
/**
* You can modify the container here before it is dumped to PHP code.
*
* @return void
*/
public function process(ContainerBuilder $container);
public function process(ContainerBuilder $container): void;
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,5 @@
*/
interface ConfigurationExtensionInterface
{
/**
* Returns extension configuration.
*
* @return ConfigurationInterface|null
*/
public function getConfiguration(array $config, ContainerBuilder $container);
public function getConfiguration(array $config, ContainerBuilder $container): ?ConfigurationInterface;
}
15 changes: 3 additions & 12 deletions src/Symfony/Component/DependencyInjection/Extension/Extension.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,12 @@ abstract class Extension implements ExtensionInterface, ConfigurationExtensionIn
{
private array $processedConfigs = [];

/**
* @return string|false
*/
public function getXsdValidationBasePath()
public function getXsdValidationBasePath(): string|false
{
return false;
}

/**
* @return string
*/
public function getNamespace()
public function getNamespace(): string
{
return 'http://example.org/schema/dic/'.$this->getAlias();
}
Expand Down Expand Up @@ -73,10 +67,7 @@ public function getAlias(): string
return Container::underscore($classBaseName);
}

/**
* @return ConfigurationInterface|null
*/
public function getConfiguration(array $config, ContainerBuilder $container)
public function getConfiguration(array $config, ContainerBuilder $container): ?ConfigurationInterface
{
$class = static::class;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,32 +25,24 @@ interface ExtensionInterface
*
* @param array<array<mixed>> $configs
*
* @return void
*
* @throws \InvalidArgumentException When provided tag is not defined in this extension
*/
public function load(array $configs, ContainerBuilder $container);
public function load(array $configs, ContainerBuilder $container): void;

/**
* Returns the namespace to be used for this extension (XML namespace).
*
* @return string
*/
public function getNamespace();
public function getNamespace(): string;

/**
* Returns the base path for the XSD files.
*
* @return string|false
*/
public function getXsdValidationBasePath();
public function getXsdValidationBasePath(): string|false;

/**
* Returns the recommended alias to use in XML.
*
* This alias is also the mandatory prefix to use when using YAML.
*
* @return string
*/
public function getAlias();
public function getAlias(): string;
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ interface PrependExtensionInterface
{
/**
* Allow an extension to prepend the extension configurations.
*
* @return void
*/
public function prepend(ContainerBuilder $container);
public function prepend(ContainerBuilder $container): void;
}
12 changes: 2 additions & 10 deletions src/Symfony/Component/Emoji/EmojiTransliterator.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,20 +83,12 @@ public function createInverse(): self
return self::create($this->id, \Transliterator::REVERSE);
}

/**
* @return int
*/
#[\ReturnTypeWillChange]
public function getErrorCode(): int|false
public function getErrorCode(): int
{
return isset($this->transliterator) ? $this->transliterator->getErrorCode() : 0;
}

/**
* @return string
*/
#[\ReturnTypeWillChange]
public function getErrorMessage(): string|false
public function getErrorMessage(): string
{
return isset($this->transliterator) ? $this->transliterator->getErrorMessage() : '';
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,5 @@ interface EventSubscriberInterface
*
* @return array<string, string|array{0: string, 1: int}|list<array{0: string, 1?: int}>>
*/
public static function getSubscribedEvents();
public static function getSubscribedEvents(): array;
}
Original file line number Diff line number Diff line change
Expand Up @@ -145,10 +145,7 @@ public function registerProvider(ExpressionFunctionProviderInterface $provider):
}
}

/**
* @return void
*/
protected function registerFunctions()
protected function registerFunctions(): void
{
$basicPhpFunctions = ['constant', 'min', 'max'];
foreach ($basicPhpFunctions as $function) {
Expand Down
30 changes: 6 additions & 24 deletions src/Symfony/Component/Form/AbstractType.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,46 +20,28 @@
*/
abstract class AbstractType implements FormTypeInterface
{
/**
* @return string|null
*/
public function getParent()
public function getParent(): ?string
{
return FormType::class;
}

/**
* @return void
*/
public function configureOptions(OptionsResolver $resolver)
public function configureOptions(OptionsResolver $resolver): void
{
}

/**
* @return void
*/
public function buildForm(FormBuilderInterface $builder, array $options)
public function buildForm(FormBuilderInterface $builder, array $options): void
{
}

/**
* @return void
*/
public function buildView(FormView $view, FormInterface $form, array $options)
public function buildView(FormView $view, FormInterface $form, array $options): void
{
}

/**
* @return void
*/
public function finishView(FormView $view, FormInterface $form, array $options)
public function finishView(FormView $view, FormInterface $form, array $options): void
{
}

/**
* @return string
*/
public function getBlockPrefix()
public function getBlockPrefix(): string
{
return StringUtil::fqcnToBlockPrefix(static::class) ?: '';
}
Expand Down
Loading
Loading
0