Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Add missing return types and enforce return types on all methods #50821

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 30, 2023
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
237 changes: 154 additions & 83 deletions .github/expected-missing-return-types.diff

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions .github/patch-types.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,11 @@ class_exists($class);
$refl = new \ReflectionClass($class);
foreach ($refl->getMethods() as $method) {
if (
!$refl->isInterface()
|| $method->getReturnType()
$method->getReturnType()
|| str_contains($method->getDocComment(), '@return')
|| str_starts_with($method->getName(), '__')
|| $method->getDeclaringClass()->getName() !== $class
|| str_contains($method->getDeclaringClass()->getName(), '\\Test\\')
) {
continue;
}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/unit-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ jobs:
git checkout src/Symfony/Contracts/Service/ResetInterface.php
git diff --exit-code

- name: Check interface return types
- name: Check return types
if: "matrix.php == '8.1' && ! matrix.mode"
run: |
php .github/patch-types.php lint
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,11 +113,17 @@ public function reset()
}
}

/**
* @return array
*/
public function getManagers()
{
return $this->data['managers'];
}

/**
* @return array
*/
public function getConnections()
{
return $this->data['connections'];
Expand All @@ -131,11 +137,17 @@ public function getQueryCount()
return array_sum(array_map('count', $this->data['queries']));
}

/**
* @return array
*/
public function getQueries()
{
return $this->data['queries'];
}

/**
* @return int
*/
public function getTime()
{
$time = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ public function __construct(string $connectionsParameter, string $managerTemplat
$this->tagPrefix = $tagPrefix;
}

/**
* @return void
*/
public function process(ContainerBuilder $container)
{
if (!$container->hasParameter($this->connectionsParameter)) {
Expand Down
8 changes: 8 additions & 0 deletions src/Symfony/Bridge/Doctrine/Form/DoctrineOrmTypeGuesser.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
namespace Symfony\Bridge\Doctrine\Form;

use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping\ClassMetadata;
use Doctrine\ORM\Mapping\ClassMetadataInfo;
use Doctrine\ORM\Mapping\MappingException as LegacyMappingException;
use Doctrine\Persistence\ManagerRegistry;
Expand Down Expand Up @@ -151,6 +152,13 @@ public function guessPattern(string $class, string $property): ?ValueGuess
return null;
}

/**
* @template T of object
*
* @param class-string<T> $class
*
* @return array{0:ClassMetadata<T>, 1:string}|null
*/
protected function getMetadata(string $class)
{
// normalize class name
Expand Down
6 changes: 6 additions & 0 deletions src/Symfony/Bridge/Monolog/Handler/ConsoleHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,8 @@ private function doHandle(array|LogRecord $record): bool

/**
* Sets the console output to use for printing logs.
*
* @return void
*/
public function setOutput(OutputInterface $output)
{
Expand All @@ -148,6 +150,8 @@ public function close(): void
/**
* Before a command is executed, the handler gets activated and the console output
* is set in order to know where to write the logs.
*
* @return void
*/
public function onCommand(ConsoleCommandEvent $event)
{
Expand All @@ -161,6 +165,8 @@ public function onCommand(ConsoleCommandEvent $event)

/**
* After a command has been executed, it disables the output.
*
* @return void
*/
public function onTerminate(ConsoleTerminateEvent $event)
{
Expand Down
3 changes: 3 additions & 0 deletions src/Symfony/Bridge/Monolog/Handler/ServerLogHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,9 @@ private static function nullErrorHandler(): void
{
}

/**
* @return resource
*/
private function createSocket()
{
$socket = stream_socket_client($this->host, $errno, $errstr, 0, \STREAM_CLIENT_CONNECT | \STREAM_CLIENT_ASYNC_CONNECT | \STREAM_CLIENT_PERSISTENT, $this->context);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ public function getProfile(): Profile
return $this->profile ??= unserialize($this->data['profile'], ['allowed_classes' => ['Twig_Profiler_Profile', Profile::class]]);
}

private function getComputedData(string $index)
private function getComputedData(string $index): mixed
{
$this->computed ??= $this->computeData($this->getProfile());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@
*/
abstract class AbstractConfigCommand extends ContainerDebugCommand
{
/**
* @return void
*/
protected function listBundles(OutputInterface|StyleInterface $output)
{
$title = 'Available registered bundles with their extension alias if available';
Expand Down Expand Up @@ -63,14 +66,14 @@ protected function listNonBundleExtensions(OutputInterface|StyleInterface $outpu
$bundleExtensions = [];
foreach ($kernel->getBundles() as $bundle) {
if ($extension = $bundle->getContainerExtension()) {
$bundleExtensions[\get_class($extension)] = true;
$bundleExtensions[$extension::class] = true;
}
}

$extensions = $this->getContainerBuilder($kernel)->getExtensions();

foreach ($extensions as $alias => $extension) {
if (isset($bundleExtensions[\get_class($extension)])) {
if (isset($bundleExtensions[$extension::class])) {
continue;
}
$rows[] = [$alias];
Expand Down Expand Up @@ -156,6 +159,9 @@ protected function findExtension(string $name): ExtensionInterface
throw new LogicException($message);
}

/**
* @return void
*/
public function validateConfiguration(ExtensionInterface $extension, mixed $configuration)
{
if (!$configuration) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
*/
class RouterDataCollector extends BaseRouterDataCollector
{
public function guessRoute(Request $request, mixed $controller)
public function guessRoute(Request $request, mixed $controller): string
{
if (\is_array($controller)) {
$controller = $controller[0];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1864,7 +1864,7 @@ private function addHttpClientSection(ArrayNodeDefinition $rootNode, callable $e
->normalizeKeys(false)
->variablePrototype()->end()
->end()
->append($this->addHttpClientRetrySection())
->append($this->createHttpClientRetrySection())
->end()
->end()
->scalarNode('mock_response_factory')
Expand Down Expand Up @@ -2012,7 +2012,7 @@ private function addHttpClientSection(ArrayNodeDefinition $rootNode, callable $e
->normalizeKeys(false)
->variablePrototype()->end()
->end()
->append($this->addHttpClientRetrySection())
->append($this->createHttpClientRetrySection())
->end()
->end()
->end()
Expand All @@ -2022,7 +2022,7 @@ private function addHttpClientSection(ArrayNodeDefinition $rootNode, callable $e
;
}

private function addHttpClientRetrySection()
private function createHttpClientRetrySection(): ArrayNodeDefinition
{
$root = new NodeBuilder();

Expand Down Expand Up @@ -2226,7 +2226,7 @@ private function addWebhookSection(ArrayNodeDefinition $rootNode, callable $enab
;
}

private function addRemoteEventSection(ArrayNodeDefinition $rootNode, callable $enableIfStandalone)
private function addRemoteEventSection(ArrayNodeDefinition $rootNode, callable $enableIfStandalone): void
{
$rootNode
->children()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2831,7 +2831,7 @@ private function registerNotifierConfiguration(array $config, ContainerBuilder $
}
}

private function registerWebhookConfiguration(array $config, ContainerBuilder $container, PhpFileLoader $loader)
private function registerWebhookConfiguration(array $config, ContainerBuilder $container, PhpFileLoader $loader): void
{
if (!class_exists(WebhookController::class)) {
throw new LogicException('Webhook support cannot be enabled as the component is not installed. Try running "composer require symfony/webhook".');
Expand All @@ -2852,7 +2852,7 @@ private function registerWebhookConfiguration(array $config, ContainerBuilder $c
$controller->replaceArgument(1, new Reference($config['message_bus']));
}

private function registerRemoteEventConfiguration(array $config, ContainerBuilder $container, PhpFileLoader $loader)
private function registerRemoteEventConfiguration(array $config, ContainerBuilder $container, PhpFileLoader $loader): void
{
if (!class_exists(RemoteEvent::class)) {
throw new LogicException('RemoteEvent support cannot be enabled as the component is not installed. Try running "composer require symfony/remote-event".');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -593,7 +593,7 @@ private function createFirewall(ContainerBuilder $container, string $id, array $
return [$matcher, $listeners, $exceptionListener, null !== $logoutListenerId ? new Reference($logoutListenerId) : null, $firewallAuthenticationProviders];
}

private function createContextListener(ContainerBuilder $container, string $contextKey, ?string $firewallEventDispatcherId)
private function createContextListener(ContainerBuilder $container, string $contextKey, ?string $firewallEventDispatcherId): string
{
if (isset($this->contextListeners[$contextKey])) {
return $this->contextListeners[$contextKey];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ protected function getCasters(): array
];
}

private function &recursiveBuildPreliminaryFormTree(FormInterface $form, array &$outputByHash)
private function &recursiveBuildPreliminaryFormTree(FormInterface $form, array &$outputByHash): array
{
$hash = spl_object_hash($form);

Expand All @@ -259,7 +259,7 @@ private function &recursiveBuildPreliminaryFormTree(FormInterface $form, array &
return $output;
}

private function &recursiveBuildFinalFormTree(FormInterface $form = null, FormView $view, array &$outputByHash)
private function &recursiveBuildFinalFormTree(FormInterface $form = null, FormView $view, array &$outputByHash): array
{
$viewHash = spl_object_hash($view);
$formHash = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use Symfony\Component\HttpKernel\Kernel;
use Symfony\Component\HttpKernel\KernelInterface;
use Symfony\Component\VarDumper\Caster\ClassStub;
use Symfony\Component\VarDumper\Cloner\Data;

/**
* @author Fabien Potencier <[email protected]>
Expand Down Expand Up @@ -224,7 +225,7 @@ public function hasZendOpcache(): bool
return $this->data['zend_opcache_enabled'];
}

public function getBundles()
public function getBundles(): array|Data
{
return $this->data['bundles'];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Log\DebugLoggerInterface;
use Symfony\Component\VarDumper\Cloner\Data;

/**
* @author Fabien Potencier <[email protected]>
Expand Down Expand Up @@ -67,12 +68,12 @@ public function lateCollect(): void
$this->currentRequest = null;
}

public function getLogs()
public function getLogs(): Data|array
{
return $this->data['logs'] ?? [];
}

public function getProcessedLogs()
public function getProcessedLogs(): array
{
if (null !== $this->processedLogs) {
return $this->processedLogs;
Expand Down Expand Up @@ -115,7 +116,7 @@ public function getProcessedLogs()
return $this->processedLogs = $logs;
}

public function getFilters()
public function getFilters(): array
{
$filters = [
'channel' => [],
Expand Down Expand Up @@ -146,32 +147,32 @@ public function getFilters()
return $filters;
}

public function getPriorities()
public function getPriorities(): Data|array
{
return $this->data['priorities'] ?? [];
}

public function countErrors()
public function countErrors(): int
{
return $this->data['error_count'] ?? 0;
}

public function countDeprecations()
public function countDeprecations(): int
{
return $this->data['deprecation_count'] ?? 0;
}

public function countWarnings()
public function countWarnings(): int
{
return $this->data['warning_count'] ?? 0;
}

public function countScreams()
public function countScreams(): int
{
return $this->data['scream_count'] ?? 0;
}

public function getCompilerLogs()
public function getCompilerLogs(): Data
{
return $this->cloneVar($this->getContainerCompilerLogs($this->data['compiler_logs_filepath'] ?? null));
}
Expand Down
Loading