10000 Add return types everywhere possible by nicolas-grekas · Pull Request #42496 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

Add return types everywhere possible #42496

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

Closed
wants to merge 1 commit into from
Closed
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
16 changes: 4 additions & 12 deletions src/Symfony/Component/BrowserKit/AbstractBrowser.php
Original file line number Diff line number Diff line change
Expand Up @@ -403,11 +403,9 @@ public function request(string $method, string $uri, array $parameters = [], arr
/**
* Makes a request in another process.
*
* @return object
*
* @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 @@ -437,10 +435,8 @@ protected function doRequestInProcess(object $request)

/**
* Makes a request.
*
* @return object
*/
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 @@ -456,20 +452,16 @@ protected function getScript(object $request)

/**
* Filters the BrowserKit request to the origin one.
*
* @return object
*/
protected function filterRequest(Request $request)
protected function filterRequest(Request $request): object
{
return $request;
}

/**
* Filters the origin response to the BrowserKit one.
*
* @return Response
*/
protected function filterResponse(object $response)
protected function filterResponse(object $response): Response
{
return $response;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ interface ConfigurationInterface
{
/**
* Generates the configuration tree builder.
*
* @return TreeBuilder
*/
public function getConfigTreeBuilder();
public function getConfigTreeBuilder(): TreeBuilder;
}
2 changes: 1 addition & 1 deletion src/Symfony/Component/Config/FileLocator.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public function __construct(string|array $paths = [])
/**
* {@inheritdoc}
*/
public function locate(string $name, string $currentPath = null, bool $first = true)
public function locate(string $name, string $currentPath = null, bool $first = true): string|array
{
if ('' === $name) {
throw new \InvalidArgumentException('An empty file name is not valid to be located.');
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/Config/FileLocatorInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,5 @@ interface FileLocatorInterface
* @throws \InvalidArgumentException If $name is empty
* @throws FileLocatorFileNotFoundException If a file is not found
*/
public function locate(string $name, string $currentPath = null, bool $first = true);
public function locate(string $name, string $currentPath = null, bool $first = true): string|array;
}
4 changes: 1 addition & 3 deletions src/Symfony/Component/Config/Loader/FileLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,11 @@ public function getLocator(): FileLocatorInterface
* @param string|null $sourceResource The original resource importing the new resource
* @param string|string[]|null $exclude Glob patterns to exclude from the import
*
* @return mixed
*
* @throws LoaderLoadException
* @throws FileLoaderImportCircularReferenceException
* @throws FileLocatorFileNotFoundException
*/
public function import(mixed $resource, string $type = null, bool $ignoreErrors = false, string $sourceResource = null, string|array $exclude = null)
public function import(mixed $resource, string $type = null, bool $ignoreErrors = false, string $sourceResource = null, string|array $exclude = null): mixed
{
if (\is_string($resource) && \strlen($resource) !== ($i = strcspn($resource, '*?{[')) && !str_contains($resource, "\n")) {
$excluded = [];
Expand Down
4 changes: 1 addition & 3 deletions src/Symfony/Component/Config/Loader/Loader.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,8 @@ public function setResolver(LoaderResolverInterface $resolver)

/**
* Imports a resource.
*
* @return mixed
*/
public function import(mixed $resource, string $type = null)
public function import(mixed $resource, string $type = null): mixed
{
return $this->resolve($resource, $type)->load($resource, $type);
}
Expand Down
12 changes: 3 additions & 9 deletions src/Symfony/Component/Config/Loader/LoaderInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,27 +21,21 @@ interface LoaderInterface
/**
* Loads a resource.
*
* @return mixed
*
* @throws \Exception If something went wrong
*/
public function load(mixed $resource, string $type = null);
public function load(mixed $resource, string $type = null): mixed;

/**
* Returns whether this class supports the given resource.
*
* @param mixed $resource A resource
*
* @return bool
*/
public function supports(mixed $resource, string $type = null);
public function supports(mixed $resource, string $type = null): bool;

/**
* Gets the loader resolver.
*
* @return LoaderResolverInterface
*/
public function getResolver();
public function getResolver(): LoaderResolverInterface;

/**
* Sets the loader resolver.
Expand Down
8 changes: 2 additions & 6 deletions src/Symfony/Component/Config/ResourceCheckerInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,13 @@ interface ResourceCheckerInterface
/**
* Queries the ResourceChecker whether it can validate a given
* resource or not.
*
* @return bool
*/
public function supports(ResourceInterface $metadata);
public function supports(ResourceInterface $metadata): bool;

/**
* Validates the resource.
*
* @param int $timestamp The timestamp at which the cache associated with this resource was created
*
* @return bool
*/
public function isFresh(ResourceInterface $resource, int $timestamp);
public function isFresh(ResourceInterface $resource, int $timestamp): bool;
}
22 changes: 7 additions & 15 deletions src/Symfony/Component/Console/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ public function run(InputInterface $input = null, OutputInterface $output = null
*
* @return int 0 if everything went fine, or an error code
*/
public function doRun(InputInterface $input, OutputInterface $output)
public function doRun(InputInterface $input, OutputInterface $output): int
{
if (true === $input->hasParameterOption(['--version', '-V'], true)) {
$output->writeln($this->getLongVersion());
Expand Down Expand Up @@ -420,10 +420,8 @@ public function setVersion(string $version)

/**
* Returns the long version of the application.
*
* @return string
*/
public function getLongVersion()
public function getLongVersion(): string
{
if ('UNKNOWN' !== $this->getName()) {
if ('UNKNOWN' !== $this->getVersion()) {
Expand Down Expand Up @@ -463,10 +461,8 @@ public function addCommands(array $commands)
*
* If a command with the same name already exists, it will be overridden.
* If the command is not enabled it will not be added.
*
* @return Command|null
*/
public function add(Command $command)
public function add(Command $command): ?Command
{
$this->init();

Expand Down Expand Up @@ -499,11 +495,9 @@ public function add(Command $command)
/**
* Returns a registered command by name or alias.
*
* @return Command
*
* @throws CommandNotFoundException When given command name does not exist
*/
public function get(string $name)
public function get(string $name): Command
{
$this->init();

Expand Down Expand Up @@ -606,11 +600,9 @@ public function findNamespace(string $namespace): string
* Contrary to get, this command tries to find the best
* match if you give it an abbreviation of a name or alias.
*
* @return Command
*
* @throws CommandNotFoundException When command name is incorrect or ambiguous
*/
public function find(string $name)
public function find(string $name): Command
{
$this->init();

Expand Down Expand Up @@ -720,7 +712,7 @@ public function find(string $name)
*
* @return Command[]
*/
public function all(string $namespace = null)
public function all(string $namespace = null): array
{
$this->init();

Expand Down Expand Up @@ -919,7 +911,7 @@ protected function configureIO(InputInterface $input, OutputInterface $output)
*
* @return int 0 if everything went fine, or an error code
*/
protected function doRunCommand(Command $command, InputInterface $input, OutputInterface $output)
protected function doRunCommand(Command $command, InputInterface $input, OutputInterface $output): int
{
foreach ($command->getHelperSet() as $helper) {
if ($helper instanceof InputAwareInterface) {
Expand Down
6 changes: 2 additions & 4 deletions src/Symfony/Component/Console/Command/Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -165,10 +165,8 @@ public function getApplication(): ?Application
*
* Override this to check for x or y and return false if the command can not
* run properly under the current conditions.
*
* @return bool
*/
public function isEnabled()
public function isEnabled(): bool
{
return true;
}
Expand All @@ -194,7 +192,7 @@ protected function configure()
*
* @see setCode()
*/
protected function execute(InputInterface $input, OutputInterface $output)
protected function execute(InputInterface $input, OutputInterface $output): int
{
throw new LogicException('You must override the execute() method in the concrete command class.');
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ protected function inExpression(bool $reset = true): bool
*
* @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
4 changes: 1 addition & 3 deletions src/Symfony/Component/DependencyInjection/Container.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,9 @@ public function getParameterBag(): ParameterBagInterface
/**
* Gets a parameter.
*
* @return array|bool|string|int|float|null
*
* @throws InvalidArgumentException if the parameter is not defined
*/
public function getParameter(string $name)
public function getParameter(string $name): array|bool|string|int|float|null
{
return $this->parameterBag->get($name);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,9 @@ public function has(string $id): bool;
public function initialized(string $id): bool;

/**
* @return array|bool|string|int|float|null
*
* @throws InvalidArgumentException if the parameter is not defined
*/
public function getParameter(string $name);
public function getParameter(string $name): array|bool|string|int|float|null;

public function hasParameter(string $name): bool;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ interface ConfigurationExtensionInterface
{
/**
* Returns extension configuration.
*
* @return ConfigurationInterface|null
*/
public function getConfiguration(array $config, ContainerBuilder $container);
public function getConfiguration(array $config, ContainerBuilder $container): ?ConfigurationInterface;
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,15 @@ abstract class Extension implements ExtensionInterface, ConfigurationExtensionIn
/**
* {@inheritdoc}
*/
public function getXsdValidationBasePath()
public function getXsdValidationBasePath(): string|false
{
return false;
}

/**
* {@inheritdoc}
*/
public function getNamespace()
public function getNamespace(): string
{
return 'http://example.org/schema/dic/'.$this->getAlias();
}
Expand Down Expand Up @@ -76,7 +76,7 @@ public function getAlias(): string
/**
* {@inheritdoc}
*/
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 @@ -29,24 +29,18 @@ public function load(array $configs, ContainerBuilder $container);

/**
* 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 @@ -27,8 +27,6 @@ interface InstantiatorInterface
*
* @param string $id Identifier of the requested service
* @param callable $realInstantiator Zero-argument callback that is capable of producing the real service instance
*
* @return object
*/
public function instantiateProxy(ContainerInterface $container, Definition $definition, string $id, callable $realInstantiator);
public function instantiateProxy(ContainerInterface $container, Definition $definition, string $id, callable $realInstantiator): object;
}
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 @@ -19,5 +19,5 @@ interface ExpressionFunctionProviderInterface
/**
* @return ExpressionFunction[]
*/
public function getFunctions();
public function getFunctions(): array;
}
6 changes: 2 additions & 4 deletions src/Symfony/Component/Form/AbstractExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ public function getTypeGuesser(): ?FormTypeGuesserInterface
*
* @return FormTypeInterface[]
*/
protected function loadTypes()
protected function loadTypes(): array
{
return [];
}
Expand All @@ -130,10 +130,8 @@ protected function loadTypeExtensions(): array

/**
* Registers the type guesser.
*
* @return FormTypeGuesserInterface|null
*/
protected function loadTypeGuesser()
protected function loadTypeGuesser(): ?FormTypeGuesserInterface
{
return null;
}
Expand Down
Loading
0