8000 Add missing return types and enforce return types on all methods · symfony/symfony@189c3c8 · GitHub
[go: up one dir, main page]

Skip to content

Commit 189c3c8

Browse files
wouterjnicolas-grekas
authored andcommitted
Add missing return types and enforce return types on all methods
1 parent 48e1444 commit 189c3c8

File tree

20 files changed

+240
-126
lines changed

20 files changed

+240
-126
lines changed

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

Lines changed: 154 additions & 83 deletions
Large diffs are not rendered by default.

.github/patch-types.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,11 @@ class_exists($class);
7373
$refl = new \ReflectionClass($class);
7474
foreach ($refl->getMethods() as $method) {
7575
if (
76-
!$refl->isInterface()
77-
|| $method->getReturnType()
76+
$method->getReturnType()
7877
|| str_contains($method->getDocComment(), '@return')
7978
|| str_starts_with($method->getName(), '__')
8079
|| $method->getDeclaringClass()->getName() !== $class
80+
|| str_contains($method->getDeclaringClass()->getName(), '\\Test\\')
8181
) {
8282
continue;
8383
}

.github/workflows/unit-tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ jobs:
150150
git checkout src/Symfony/Contracts/Service/ResetInterface.php
151151
git diff --exit-code
152152
153-
- name: Check interface return types
153+
- name: Check return types
154154
if: "matrix.php == '8.1' && ! matrix.mode"
155155
run: |
156156
php .github/patch-types.php lint

src/Symfony/Bridge/Doctrine/DataCollector/DoctrineDataCollector.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,11 +113,17 @@ public function reset()
113113
}
114114
}
115115

116+
/**
117+
* @return array
118+
*/
116119
public function getManagers()
117120
{
118121
return $this->data['managers'];
119122
}
120123

124+
/**
125+
* @return array
126+
*/
121127
public function getConnections()
122128
{
123129
return $this->data['connections'];
@@ -131,11 +137,17 @@ public function getQueryCount()
131137
return array_sum(array_map('count', $this->data['queries']));
132138
}
133139

140+
/**
141+
* @return array
142+
*/
134143
public function getQueries()
135144
{
136145
return $this->data['queries'];
137146
}
138147

148+
/**
149+
* @return int
150+
*/
139151
public function getTime()
140152
{
141153
$time = 0;

src/Symfony/Bridge/Doctrine/DependencyInjection/CompilerPass/RegisterEventListenersAndSubscribersPass.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,9 @@ public function __construct(string $connectionsParameter, string $managerTemplat
5353
$this->tagPrefix = $tagPrefix;
5454
}
5555

56+
/**
57+
* @return void
58+
*/
5659
public function process(ContainerBuilder $container)
5760
{
5861
if (!$container->hasParameter($this->connectionsParameter)) {

src/Symfony/Bridge/Doctrine/Form/DoctrineOrmTypeGuesser.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Symfony\Bridge\Doctrine\Form;
1313

1414
use Doctrine\DBAL\Types\Types;
15+
use Doctrine\ORM\Mapping\ClassMetadata;
1516
use Doctrine\ORM\Mapping\ClassMetadataInfo;
1617
use Doctrine\ORM\Mapping\MappingException as LegacyMappingException;
1718
use Doctrine\Persistence\ManagerRegistry;
@@ -151,6 +152,13 @@ public function guessPattern(string $class, string $property): ?ValueGuess
151152
return null;
152153
}
153154

155+
/**
156+
* @template T of object
157+
*
158+
* @param class-string<T> $class
159+
*
160+
* @return array{0:ClassMetadata<T>, 1:string}|null
161+
*/
154162
protected function getMetadata(string $class)
155163
{
156164
// normalize class name

src/Symfony/Bridge/Monolog/Handler/ConsoleHandler.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,8 @@ private function doHandle(array|LogRecord $record): bool
129129

130130
/**
131131
* Sets the console output to use for printing logs.
132+
*
133+
* @return void
132134
*/
133135
public function setOutput(OutputInterface $output)
134136
{
@@ -148,6 +150,8 @@ public function close(): void
148150
/**
149151
* Before a command is executed, the handler gets activated and the console output
150152
* is set in order to know where to write the logs.
153+
*
154+
* @return void
151155
*/
152156
public function onCommand(ConsoleCommandEvent $event)
153157
{
@@ -161,6 +165,8 @@ public function onCommand(ConsoleCommandEvent $event)
161165

162166
/**
163167
* After a command has been executed, it disables the output.
168+
*
169+
* @return void
164170
*/
165171
public function onTerminate(ConsoleTerminateEvent $event)
166172
{

src/Symfony/Bridge/Monolog/Handler/ServerLogHandler.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,9 @@ private static function nullErrorHandler(): void
130130
{
131131
}
132132

133+
/**
134+
* @return resource
135+
*/
133136
private function createSocket()
134137
{
135138
$socket = stream_socket_client($this->host, $errno, $errstr, 0, \STREAM_CLIENT_CONNECT | \STREAM_CLIENT_ASYNC_CONNECT | \STREAM_CLIENT_PERSISTENT, $this->context);

src/Symfony/Bridge/Twig/DataCollector/TwigDataCollector.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ public function getProfile(): Profile
134134
return $this->profile ??= unserialize($this->data['profile'], ['allowed_classes' => ['Twig_Profiler_Profile', Profile::class]]);
135135
}
136136

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

src/Symfony/Bundle/FrameworkBundle/Command/AbstractConfigCommand.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@
2828
*/
2929
abstract class AbstractConfigCommand extends ContainerDebugCommand
3030
{
31+
/**
32+
* @return void
33+
*/
3134
protected function listBundles(OutputInterface|StyleInterface $output)
3235
{
3336
$title = 'Available registered bundles with their extension alias if available';
@@ -63,14 +66,14 @@ protected function listNonBundleExtensions(OutputInterface|StyleInterface $outpu
6366
$bundleExtensions = [];
6467
foreach ($kernel->getBundles() as $bundle) {
6568
if ($extension = $bundle->getContainerExtension()) {
66-
$bundleExtensions[\get_class($extension)] = true;
69+
$bundleExtensions[$extension::class] = true;
6770
}
6871
}
6972

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

7275
foreach ($extensions as $alias => $extension) {
73-
if (isset($bundleExtensions[\get_class($extension)])) {
76+
if (isset($bundleExtensions[$extension::class])) {
7477
continue;
7578
}
7679
$rows[] = [$alias];
@@ -156,6 +159,9 @@ protected function findExtension(string $name): ExtensionInterface
156159
throw new LogicException($message);
157160
}
158161

162+
/**
163+
* @return void
164+
*/
159165
public function validateConfiguration(ExtensionInterface $extension, mixed $configuration)
160166
{
161167
if (!$configuration) {

src/Symfony/Bundle/FrameworkBundle/DataCollector/RouterDataCollector.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
*/
2323
class RouterDataCollector extends BaseRouterDataCollector
2424
{
25-
public function guessRoute(Request $request, mixed $controller)
25+
public function guessRoute(Request $request, mixed $controller): string
2626
{
2727
if (\is_array($controller)) {
2828
$controller = $controller[0];

src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1864,7 +1864,7 @@ private function addHttpClientSection(ArrayNodeDefinition $rootNode, callable $e
18641864
->normalizeKeys(false)
18651865
->variablePrototype()->end()
18661866
->end()
1867-
->append($this->addHttpClientRetrySection())
1867+
->append($this->createHttpClientRetrySection())
18681868
->end()
18691869
->end()
18701870
->scalarNode('mock_response_factory')
@@ -2012,7 +2012,7 @@ private function addHttpClientSection(ArrayNodeDefinition $rootNode, callable $e
20122012
->normalizeKeys(false)
20132013
->variablePrototype()->end()
20142014
->end()
2015-
->append($this->addHttpClientRetrySection())
2015+
->append($this->createHttpClientRetrySection())
20162016
->end()
20172017
->end()
20182018
->end()
@@ -2022,7 +2022,7 @@ private function addHttpClientSection(ArrayNodeDefinition $rootNode, callable $e
20222022
;
20232023
}
20242024

2025-
private function addHttpClientRetrySection()
2025+
private function createHttpClientRetrySection(): ArrayNodeDefinition
20262026
{
20272027
$root = new NodeBuilder();
20282028

@@ -2226,7 +2226,7 @@ private function addWebhookSection(ArrayNodeDefinition $rootNode, callable $enab
22262226
;
22272227
}
22282228

2229-
private function addRemoteEventSection(ArrayNodeDefinition $rootNode, callable $enableIfStandalone)
2229+
private function addRemoteEventSection(ArrayNodeDefinition $rootNode, callable $enableIfStandalone): void
22302230
{
22312231
$rootNode
22322232
->children()

src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2831,7 +2831,7 @@ private function registerNotifierConfiguration(array $config, ContainerBuilder $
28312831
}
28322832
}
28332833

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

2855-
private function registerRemoteEventConfiguration(array $config, ContainerBuilder $container, PhpFileLoader $loader)
2855+
private function registerRemoteEventConfiguration(array $config, ContainerBuilder $container, PhpFileLoader $loader): void
28562856
{
28572857
if (!class_exists(RemoteEvent::class)) {
28582858
throw new LogicException('RemoteEvent support cannot be enabled as the component is not installed. Try running "composer require symfony/remote-event".');

src/Symfony/Bundle/SecurityBundle/DependencyInjection/SecurityExtension.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -593,7 +593,7 @@ private function createFirewall(ContainerBuilder $container, string $id, array $
593593
return [$matcher, $listeners, $exceptionListener, null !== $logoutListenerId ? new Reference($logoutListenerId) : null, $firewallAuthenticationProviders];
594594
}
595595

596-
private function createContextListener(ContainerBuilder $container, string $contextKey, ?string $firewallEventDispatcherId)
596+
private function createContextListener(ContainerBuilder $container, string $contextKey, ?string $firewallEventDispatcherId): string
597597
{
598598
if (isset($this->contextListeners[$contextKey])) {
599599
return $this->contextListeners[$contextKey];

src/Symfony/Component/Form/Extension/DataCollector/FormDataCollector.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ protected function getCasters(): array
242242
];
243243
}
244244

245-
private function &recursiveBuildPreliminaryFormTree(FormInterface $form, array &$outputByHash)
245+
private function &recursiveBuildPreliminaryFormTree(FormInterface $form, array &$outputByHash): array
246246
{
247247
$hash = spl_object_hash($form);
248248

@@ -259,7 +259,7 @@ private function &recursiveBuildPreliminaryFormTree(FormInterface $form, array &
259259
return $output;
260260
}
261261

262-
private function &recursiveBuildFinalFormTree(FormInterface $form = null, FormView $view, array &$outputByHash)
262+
private function &recursiveBuildFinalFormTree(FormInterface $form = null, FormView $view, array &$outputByHash): array
263263
{
264264
$viewHash = spl_object_hash($view);
265265
$formHash = null;

src/Symfony/Component/HttpKernel/DataCollector/ConfigDataCollector.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use Symfony\Component\HttpKernel\Kernel;
1717
use Symfony\Component\HttpKernel\KernelInterface;
1818
use Symfony\Component\VarDumper\Caster\ClassStub;
19+
use Symfony\Component\VarDumper\Cloner\Data;
1920

2021
/**
2122
* @author Fabien Potencier <fabien@symfony.com>
@@ -224,7 +225,7 @@ public function hasZendOpcache(): bool
224225
return $this->data['zend_opcache_enabled'];
225226
}
226227

227-
public function getBundles()
228+
public function getBundles(): array|Data
228229
{
229230
return $this->data['bundles'];
230231
}

src/Symfony/Component/HttpKernel/DataCollector/LoggerDataCollector.php

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use Symfony\Component\HttpFoundation\RequestStack;
1717
use Symfony\Component\HttpFoundation\Response;
1818
use Symfony\Component\HttpKernel\Log\DebugLoggerInterface;
19+
use Symfony\Component\VarDumper\Cloner\Data;
1920

2021
/**
2122
* @author Fabien Potencier <fabien@symfony.com>
@@ -67,12 +68,12 @@ public function lateCollect(): void
6768
$this->currentRequest = null;
6869
}
6970

70-
public function getLogs()
71+
public function getLogs(): Data|array
7172
{
7273
return $this->data['logs'] ?? [];
7374
}
7475

75-
public function getProcessedLogs()
76+
public function getProcessedLogs(): array
7677
{
7778
if (null !== $this->processedLogs) {
7879
return $this->processedLogs;
@@ -115,7 +116,7 @@ public function getProcessedLogs()
115116
return $this->processedLogs = $logs;
116117
}
117118

118-
public function getFilters()
119+
public function getFilters(): array
119120
{
120121
$filters = [
121122
'channel' => [],
@@ -146,32 +147,32 @@ public function getFilters()
146147
return $filters;
147148
}
148149

149-
public function getPriorities()
150+
public function getPriorities(): Data|array
150151
{
151152
return $this->data['priorities'] ?? [];
152153
}
153154

154-
public function countErrors()
155+
public function countErrors(): int
155156
{
156157
return $this->data['error_count'] ?? 0;
157158
}
158159

159-
public function countDeprecations()
160+
public function countDeprecations(): int
160161
{
161162
return $this->data['deprecation_count'] ?? 0;
162163
}
163164

164-
public function countWarnings()
165+
public function countWarnings(): int
165166
{
166167
return $this->data['warning_count'] ?? 0;
167168
}
168169

169-
public function countScreams()
170+
public function countScreams(): int
170171
{
171172
return $this->data['scream_count'] ?? 0;
172173
}
173174

174-
public function getCompilerLogs()
175+
public function getCompilerLogs(): Data
175176
{
176177
return $this->cloneVar($this->getContainerCompilerLogs($this->data['compiler_logs_filepath'] ?? null));
177178
}

0 commit comments

Comments
 (0)
0