Skip to content

Commit

Permalink
Add remaining missing return types to safe methods
Browse files Browse the repository at this point in the history
  • Loading branch information
wouterj authored and nicolas-grekas committed Apr 24, 2023
1 parent 4ee55b0 commit 978e623
Show file tree
Hide file tree
Showing 52 changed files with 119 additions and 145 deletions.
61 changes: 5 additions & 56 deletions .github/expected-missing-return-types.diff
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ index 8bfaa0a22c..745ba6aff3 100644
{
$this->debug = $debug;
diff --git a/src/Symfony/Bridge/Twig/Command/DebugCommand.php b/src/Symfony/Bridge/Twig/Command/DebugCommand.php
index fe581b5987..8109e7c68d 100644
index 43e4d9c9f1..ea0116870b 100644
--- a/src/Symfony/Bridge/Twig/Command/DebugCommand.php
+++ b/src/Symfony/Bridge/Twig/Command/DebugCommand.php
@@ -63,5 +63,5 @@ class DebugCommand extends Command
Expand All @@ -397,7 +397,7 @@ index fe581b5987..8109e7c68d 100644
{
$this
diff --git a/src/Symfony/Bridge/Twig/Command/LintCommand.php b/src/Symfony/Bridge/Twig/Command/LintCommand.php
index fa8effc12a..deced50a90 100644
index e059740a13..e7d6fbdd05 100644
--- a/src/Symfony/Bridge/Twig/Command/LintCommand.php
+++ b/src/Symfony/Bridge/Twig/Command/LintCommand.php
@@ -52,5 +52,5 @@ class LintCommand extends Command
Expand Down Expand Up @@ -1500,7 +1500,7 @@ index 00e912686b..58872ec2bc 100644
{
if (!$container->hasDefinition('console.command.cache_pool_prune')) {
diff --git a/src/Symfony/Component/Cache/Traits/FilesystemCommonTrait.php b/src/Symfony/Component/Cache/Traits/FilesystemCommonTrait.php
index 2ee96e9b37..f49ed24f68 100644
index 200406a564..0bad73fe6a 100644
--- a/src/Symfony/Component/Cache/Traits/FilesystemCommonTrait.php
+++ b/src/Symfony/Component/Cache/Traits/FilesystemCommonTrait.php
@@ -81,5 +81,5 @@ trait FilesystemCommonTrait
Expand Down Expand Up @@ -5038,28 +5038,10 @@ index 9e107401a2..7f92321a2b 100644
+ protected function registerFunctions(): void
{
$this->addFunction(ExpressionFunction::fromPhp('constant'));
diff --git a/src/Symfony/Component/ExpressionLanguage/Node/ConditionalNode.php b/src/Symfony/Component/ExpressionLanguage/Node/ConditionalNode.php
index fec02abaae..7d02544275 100644
--- a/src/Symfony/Component/ExpressionLanguage/Node/ConditionalNode.php
+++ b/src/Symfony/Component/ExpressionLanguage/Node/ConditionalNode.php
@@ -41,5 +41,5 @@ class ConditionalNode extends Node
}

- public function evaluate(array $functions, array $values)
+ public function evaluate(array $functions, array $values): mixed
{
if ($this->nodes['expr1']->evaluate($functions, $values)) {
diff --git a/src/Symfony/Component/ExpressionLanguage/Node/FunctionNode.php b/src/Symfony/Component/ExpressionLanguage/Node/FunctionNode.php
index d4ab3e0922..811fec7e2e 100644
index 33323f388f..811fec7e2e 100644
--- a/src/Symfony/Component/ExpressionLanguage/Node/FunctionNode.php
+++ b/src/Symfony/Component/ExpressionLanguage/Node/FunctionNode.php
@@ -41,5 +41,5 @@ class FunctionNode extends Node
}

- public function evaluate(array $functions, array $values)
+ public function evaluate(array $functions, array $values): mixed
{
$arguments = [$values];
@@ -54,5 +54,5 @@ class FunctionNode extends Node
* @return array
*/
Expand Down Expand Up @@ -5106,17 +5088,6 @@ index f6fff09b1e..4661f7d165 100644
+ protected function isHash(array $value): bool
{
$expectedKey = 0;
diff --git a/src/Symfony/Component/ExpressionLanguage/Node/UnaryNode.php b/src/Symfony/Component/ExpressionLanguage/Node/UnaryNode.php
index 580ee13095..55e2121fcf 100644
--- a/src/Symfony/Component/ExpressionLanguage/Node/UnaryNode.php
+++ b/src/Symfony/Component/ExpressionLanguage/Node/UnaryNode.php
@@ -46,5 +46,5 @@ class UnaryNode extends Node
}

- public function evaluate(array $functions, array $values)
+ public function evaluate(array $functions, array $values): mixed
{
$value = $this->nodes['node']->evaluate($functions, $values);
diff --git a/src/Symfony/Component/ExpressionLanguage/ParsedExpression.php b/src/Symfony/Component/ExpressionLanguage/ParsedExpression.php
index 239624ec2c..3b497d5ccf 100644
--- a/src/Symfony/Component/ExpressionLanguage/ParsedExpression.php
Expand Down Expand Up @@ -10730,7 +10701,7 @@ index cf41e0c507..61f7397734 100644
+ public function createNewToken(PersistentTokenInterface $token): void;
}
diff --git a/src/Symfony/Component/Security/Core/Authentication/Token/AbstractToken.php b/src/Symfony/Component/Security/Core/Authentication/Token/AbstractToken.php
index 4416cda616..0fcf4303e0 100644
index 10cb8f776e..0da1b3330e 100644
--- a/src/Symfony/Component/Security/Core/Authentication/Token/AbstractToken.php
+++ b/src/Symfony/Component/Security/Core/Authentication/Token/AbstractToken.php
@@ -57,5 +57,5 @@ abstract class AbstractToken implements TokenInterface, \Serializable
Expand Down Expand Up @@ -11173,17 +11144,6 @@ index 91271d14a3..100c2fb549 100644
- public function start(Request $request, AuthenticationException $authException = null);
+ public function start(Request $request, AuthenticationException $authException = null): Response;
}
diff --git a/src/Symfony/Component/Security/Http/Event/LazyResponseEvent.php b/src/Symfony/Component/Security/Http/Event/LazyResponseEvent.php
index 46a25eed07..b3e25f1af3 100644
--- a/src/Symfony/Component/Security/Http/Event/LazyResponseEvent.php
+++ b/src/Symfony/Component/Security/Http/Event/LazyResponseEvent.php
@@ -32,5 +32,5 @@ final class LazyResponseEvent extends RequestEvent
}

- public function setResponse(Response $response)
+ public function setResponse(Response $response): void
{
$this->stopPropagation();
diff --git a/src/Symfony/Component/Security/Http/Event/LoginFailureEvent.php b/src/Symfony/Component/Security/Http/Event/LoginFailureEvent.php
index 3b7c5086f2..97fb99f0b5 100644
--- a/src/Symfony/Component/Security/Http/Event/LoginFailureEvent.php
Expand Down Expand Up @@ -11238,17 +11198,6 @@ index fc56733efa..8538f5f821 100644
+ protected function callListeners(RequestEvent $event, iterable $listeners): void
{
foreach ($listeners as $listener) {
diff --git a/src/Symfony/Component/Security/Http/Firewall/AccessListener.php b/src/Symfony/Component/Security/Http/Firewall/AccessListener.php
index ad343ef085..9a1a2563c4 100644
--- a/src/Symfony/Component/Security/Http/Firewall/AccessListener.php
+++ b/src/Symfony/Component/Security/Http/Firewall/AccessListener.php
@@ -65,5 +65,5 @@ class AccessListener extends AbstractListener
* @throws AccessDeniedException
*/
- public function authenticate(RequestEvent $event)
+ public function authenticate(RequestEvent $event): void
{
$request = $event->getRequest();
diff --git a/src/Symfony/Component/Security/Http/Firewall/FirewallListenerInterface.php b/src/Symfony/Component/Security/Http/Firewall/FirewallListenerInterface.php
index be200c0d12..69483f8f1d 100644
--- a/src/Symfony/Component/Security/Http/Firewall/FirewallListenerInterface.php
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Bridge/Monolog/Handler/NotifierHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ private function notify(array $records): void
$this->notifier->send($notification, ...$this->notifier->getAdminRecipients());
}

private function getHighestRecord(array $records)
private function getHighestRecord(array $records): array
{
$highestRecord = null;
foreach ($records as $record) {
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Bridge/Monolog/Handler/ServerLogHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ protected function getDefaultFormatter(): FormatterInterface
return new VarDumperFormatter();
}

private static function nullErrorHandler()
private static function nullErrorHandler(): void
{
}

Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Bridge/Twig/Command/DebugCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ private function getLoaderPaths(string $name = null): array
return $loaderPaths;
}

private function getMetadata(string $type, mixed $entity)
private function getMetadata(string $type, mixed $entity): mixed
{
if ('globals' === $type) {
return $entity;
Expand Down
8 changes: 4 additions & 4 deletions src/Symfony/Bridge/Twig/Command/LintCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ private function getFilesInfo(array $filenames): array
return $filesInfo;
}

protected function findFiles(string $filename)
protected function findFiles(string $filename): iterable
{
if (is_file($filename)) {
return [$filename];
Expand Down Expand Up @@ -172,7 +172,7 @@ private function validate(string $template, string $file): array
return ['template' => $template, 'file' => $file, 'valid' => true];
}

private function display(InputInterface $input, OutputInterface $output, SymfonyStyle $io, array $files)
private function display(InputInterface $input, OutputInterface $output, SymfonyStyle $io, array $files): int
{
return match ($this->format) {
'txt' => $this->displayTxt($output, $io, $files),
Expand Down Expand Up @@ -205,7 +205,7 @@ private function displayTxt(OutputInterface $output, SymfonyStyle $io, array $fi
return min($errors, 1);
}

private function displayJson(OutputInterface $output, array $filesInfo)
private function displayJson(OutputInterface $output, array $filesInfo): int
{
$errors = 0;

Expand All @@ -224,7 +224,7 @@ private function displayJson(OutputInterface $output, array $filesInfo)
return min($errors, 1);
}

private function renderException(SymfonyStyle $output, string $template, Error $exception, string $file = null, GithubActionReporter $githubReporter = null)
private function renderException(SymfonyStyle $output, string $template, Error $exception, string $file = null, GithubActionReporter $githubReporter = null): void
{
$line = $exception->getTemplateLine();

Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Bridge/Twig/Extension/WorkflowExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public function getMarkedPlaces(object $subject, bool $placesNameOnly = true, st
* Use a string (the place name) to get place metadata
* Use a Transition instance to get transition metadata
*/
public function getMetadata(object $subject, string $key, string|Transition $metadataSubject = null, string $name = null)
public function getMetadata(object $subject, string $key, string|Transition $metadataSubject = null, string $name = null): mixed
{
return $this
->workflowRegistry
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ private function getAvailableBundles(bool $alias): array
return $availableBundles;
}

private function getConfig(ExtensionInterface $extension, ContainerBuilder $container, bool $resolveEnvs = false)
private function getConfig(ExtensionInterface $extension, ContainerBuilder $container, bool $resolveEnvs = false): mixed
{
return $container->resolveEnvPlaceholders(
$container->getParameterBag()->resolveValue(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,9 @@ abstract protected function describeContainerEnvVars(array $envs, array $options
* Common options are:
* * name: name of listened event
*/
abstract protected function describeEventDispatcherListeners(EventDispatcherInterface $eventDispatcher, array $options = []);
abstract protected function describeEventDispatcherListeners(EventDispatcherInterface $eventDispatcher, array $options = []): void;

abstract protected function describeCallable(mixed $callable, array $options = []);
abstract protected function describeCallable(mixed $callable, array $options = []): void;

protected function formatValue(mixed $value): string
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ protected function describeEventDispatcherListeners(EventDispatcherInterface $ev
}
}

protected function describeCallable(mixed $callable, array $options = [])
protected function describeCallable(mixed $callable, array $options = []): void
{
$string = '';

Expand All @@ -359,7 +359,9 @@ protected function describeCallable(mixed $callable, array $options = [])
}
}

return $this->write($string."\n");
$this->write($string."\n");

return;
}

if (\is_string($callable)) {
Expand All @@ -375,15 +377,19 @@ protected function describeCallable(mixed $callable, array $options = [])
$string .= "\n- Static: yes";
}

return $this->write($string."\n");
$this->write($string."\n");

return;
}

if ($callable instanceof \Closure) {
$string .= "\n- Type: `closure`";

$r = new \ReflectionFunction($callable);
if (str_contains($r->name, '{closure}')) {
return $this->write($string."\n");
$this->write($string."\n");

return;
}
$string .= "\n".sprintf('- Name: `%s`', $r->name);

Expand All @@ -394,14 +400,18 @@ protected function describeCallable(mixed $callable, array $options = [])
}
}

return $this->write($string."\n");
$this->write($string."\n");

return;
}

if (method_exists($callable, '__invoke')) {
$string .= "\n- Type: `object`";
$string .= "\n".sprintf('- Name: `%s`', $callable::class);

return $this->write($string."\n");
$this->write($string."\n");

return;
}

throw new \InvalidArgumentException('Callable is not describable.');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@ trait TraceableListenerTrait
/**
* Proxies all method calls to the original listener.
*/
public function __call(string $method, array $arguments)
public function __call(string $method, array $arguments): mixed
{
return $this->listener->{$method}(...$arguments);
}

public function getWrappedListener()
public function getWrappedListener(): mixed
{
return $this->listener;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ private function hasHashOrNonce(array $directives): bool
return false;
}

private function getDirectiveFallback(array $directiveSet, string $type)
private function getDirectiveFallback(array $directiveSet, string $type): ?array
{
if (\in_array($type, ['script-src-elem', 'style-src-elem'], true) || !isset($directiveSet['default-src'])) {
// Let the browser fallback on it's own
Expand Down
5 changes: 4 additions & 1 deletion src/Symfony/Component/Cache/LockRegistry.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public static function setFiles(array $files): array
return $previousFiles;
}

public static function compute(callable $callback, ItemInterface $item, bool &$save, CacheInterface $pool, \Closure $setMetadata = null, LoggerInterface $logger = null)
public static function compute(callable $callback, ItemInterface $item, bool &$save, CacheInterface $pool, \Closure $setMetadata = null, LoggerInterface $logger = null): mixed
{
if ('\\' === \DIRECTORY_SEPARATOR && null === self::$lockedFiles) {
// disable locking on Windows by default
Expand Down Expand Up @@ -146,6 +146,9 @@ public static function compute(callable $callback, ItemInterface $item, bool &$s
return null;
}

/**
* @return resource|false
*/
private static function open(int $key)
{
if (null !== $h = self::$openedFiles[$key] ?? null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public function unmarshall(string $value): mixed
/**
* @internal
*/
public static function handleUnserializeCallback(string $class)
public static function handleUnserializeCallback(string $class): never
{
throw new \DomainException('Class not found: '.$class);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ protected function getId(mixed $key): string
/**
* @internal
*/
public static function handleUnserializeCallback(string $class)
public static function handleUnserializeCallback(string $class): never
{
throw new \DomainException('Class not found: '.$class);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/Cache/Traits/ContractsTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public function setCallbackWrapper(?callable $callbackWrapper): callable
return $previousWrapper;
}

private function doGet(AdapterInterface $pool, string $key, callable $callback, ?float $beta, array &$metadata = null)
private function doGet(AdapterInterface $pool, string $key, callable $callback, ?float $beta, array &$metadata = null): mixed
{
if (0 > $beta ??= 1.0) {
throw new InvalidArgumentException(sprintf('Argument "$beta" provided to "%s::get()" must be a positive number, %f given.', static::class, $beta));
Expand Down
4 changes: 2 additions & 2 deletions src/Symfony/Component/Cache/Traits/FilesystemCommonTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ trait FilesystemCommonTrait
private string $directory;
private string $tmpSuffix;

private function init(string $namespace, ?string $directory)
private function init(string $namespace, ?string $directory): void
{
if (!isset($directory[0])) {
$directory = sys_get_temp_dir().\DIRECTORY_SEPARATOR.'symfony-cache';
Expand Down Expand Up @@ -161,7 +161,7 @@ private function scanHashDir(string $directory): \Generator
/**
* @internal
*/
public static function throwError(int $type, string $message, string $file, int $line)
public static function throwError(int $type, string $message, string $file, int $line): never
{
throw new \ErrorException($message, 0, $type, $file, $line);
}
Expand Down
10 changes: 5 additions & 5 deletions src/Symfony/Component/Console/Descriptor/Descriptor.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,25 +50,25 @@ protected function write(string $content, bool $decorated = false): void
/**
* Describes an InputArgument instance.
*/
abstract protected function describeInputArgument(InputArgument $argument, array $options = []);
abstract protected function describeInputArgument(InputArgument $argument, array $options = []): void;

/**
* Describes an InputOption instance.
*/
abstract protected function describeInputOption(InputOption $option, array $options = []);
abstract protected function describeInputOption(InputOption $option, array $options = []): void;

/**
* Describes an InputDefinition instance.
*/
abstract protected function describeInputDefinition(InputDefinition $definition, array $options = []);
abstract protected function describeInputDefinition(InputDefinition $definition, array $options = []): void;

/**
* Describes a Command instance.
*/
abstract protected function describeCommand(Command $command, array $options = []);
abstract protected function describeCommand(Command $command, array $options = []): void;

/**
* Describes an Application instance.
*/
abstract protected function describeApplication(Application $application, array $options = []);
abstract protected function describeApplication(Application $application, array $options = []): void;
}
Loading

0 comments on commit 978e623

Please sign in to comment.