Skip to content

Commit 2d5dff3

Browse files
minor #33252 Fix inconsistent return points (derrabus)
This PR was merged into the 3.4 branch. Discussion ---------- Fix inconsistent return points | Q | A | ------------- | --- | Branch? | 3.4 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #17201 in preparation for #33228 | License | MIT | Doc PR | N/A Inconsistent return points in methods prevent adding return types. I thought, I'll give it a try and fix them. After this PR, PhpStorm's inspection still finds 39 issues, but as far as I can tell, they're either false positives or fixture code. Commits ------- f5b6ee9de1 Fix inconsistent return points.
2 parents 15b90f5 + beaeac2 commit 2d5dff3

15 files changed

+48
-36
lines changed

Command/ConfigDumpReferenceCommand.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
8686
'For dumping a specific option, add its path as the second argument of this command. (e.g. <comment>config:dump-reference FrameworkBundle profiler.matcher</comment> to dump the <comment>framework.profiler.matcher</comment> configuration)',
8787
]);
8888

89-
return;
89+
return null;
9090
}
9191

9292
$extension = $this->findExtension($name);
@@ -129,5 +129,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
129129
}
130130

131131
$io->writeln(null === $path ? $dumper->dump($configuration, $extension->getNamespace()) : $dumper->dumpAtPath($configuration, $path));
132+
133+
return null;
132134
}
133135
}

Command/DebugAutowiringCommand.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,5 +93,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
9393
}
9494

9595
$io->table([], $tableRows);
96+
97+
return null;
9698
}
9799
}

Command/RouterDebugCommand.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,10 +154,13 @@ private function convertController(Route $route)
154154
}
155155
}
156156

157+
/**
158+
* @return callable|null
159+
*/
157160
private function extractCallable(Route $route)
158161
{
159162
if (!$route->hasDefault('_controller')) {
160-
return;
163+
return null;
161164
}
162165

163166
$controller = $route->getDefault('_controller');
@@ -178,5 +181,7 @@ private function extractCallable(Route $route)
178181
return $controller;
179182
} catch (\InvalidArgumentException $e) {
180183
}
184+
185+
return null;
181186
}
182187
}

Command/RouterMatchCommand.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,5 +149,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
149149

150150
return 1;
151151
}
152+
153+
return null;
152154
}
153155
}

Command/TranslationUpdateCommand.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
242242
if (!\count($operation->getDomains())) {
243243
$errorIo->warning('No translation messages were found.');
244244

245-
return;
245+
return null;
246246
}
247247

248248
$resultMessage = 'Translation files were successfully updated';
@@ -307,6 +307,8 @@ protected function execute(InputInterface $input, OutputInterface $output)
307307
}
308308

309309
$errorIo->success($resultMessage.'.');
310+
311+
return null;
310312
}
311313

312314
private function filterCatalogue(MessageCatalogue $catalogue, $domain)

Console/Descriptor/JsonDescriptor.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,9 @@ protected function describeContainerDefinition(Definition $definition, array $op
142142
protected function describeContainerAlias(Alias $alias, array $options = [], ContainerBuilder $builder = null)
143143
{
144144
if (!$builder) {
145-
return $this->writeData($this->getContainerAliasData($alias), $options);
145+
$this->writeData($this->getContainerAliasData($alias), $options);
146+
147+
return;
146148
}
147149

148150
$this->writeData(

Console/Descriptor/MarkdownDescriptor.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,9 @@ protected function describeContainerAlias(Alias $alias, array $options = [], Con
249249
."\n".'- Public: '.($alias->isPublic() && !$alias->isPrivate() ? 'yes' : 'no');
250250

251251
if (!isset($options['id'])) {
252-
return $this->write($output);
252+
$this->write($output);
253+
254+
return;
253255
}
254256

255257
$this->write(sprintf("### %s\n\n%s\n", $options['id'], $output));

Console/Descriptor/TextDescriptor.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,7 @@ protected function describeContainerAlias(Alias $alias, array $options = [], Con
369369
return;
370370
}
371371

372-
return $this->describeContainerDefinition($builder->getDefinition((string) $alias), array_merge($options, ['id' => (string) $alias]));
372+
$this->describeContainerDefinition($builder->getDefinition((string) $alias), array_merge($options, ['id' => (string) $alias]));
373373
}
374374

375375
/**

Console/Descriptor/XmlDescriptor.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,9 @@ protected function describeContainerAlias(Alias $alias, array $options = [], Con
9898
$dom->appendChild($dom->importNode($this->getContainerAliasDocument($alias, isset($options['id']) ? $options['id'] : null)->childNodes->item(0), true));
9999

100100
if (!$builder) {
101-
return $this->writeDocument($dom);
101+
$this->writeDocument($dom);
102+
103+
return;
102104
}
103105

104106
$dom->appendChild($dom->importNode($this->getContainerDefinitionDocument($builder->getDefinition((string) $alias), (string) $alias)->childNodes->item(0), true));

EventListener/SessionListener.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,6 @@ public function __construct(ContainerInterface $container)
3434

3535
protected function getSession()
3636
{
37-
if (!$this->container->has('session')) {
38-
return;
39-
}
40-
41-
return $this->container->get('session');
37+
return $this->container->get('session', ContainerInterface::NULL_ON_INVALID_REFERENCE);
4238
}
4339
}

EventListener/TestSessionListener.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,6 @@ public function __construct(ContainerInterface $container)
3434

3535
protected function getSession()
3636
{
37-
if (!$this->container->has('session')) {
38-
return;
39-
}
40-
41-
return $this->container->get('session');
37+
return $this->container->get('session', ContainerInterface::NULL_ON_INVALID_REFERENCE);
4238
}
4339
}

Templating/GlobalVariables.php

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -45,35 +45,28 @@ public function getToken()
4545
public function getUser()
4646
{
4747
if (!$token = $this->getToken()) {
48-
return;
48+
return null;
4949
}
5050

5151
$user = $token->getUser();
52-
if (!\is_object($user)) {
53-
return;
54-
}
5552

56-
return $user;
53+
return \is_object($user) ? $user : null;
5754
}
5855

5956
/**
6057
* @return Request|null The HTTP request object
6158
*/
6259
public function getRequest()
6360
{
64-
if ($this->container->has('request_stack')) {
65-
return $this->container->get('request_stack')->getCurrentRequest();
66-
}
61+
return $this->container->has('request_stack') ? $this->container->get('request_stack')->getCurrentRequest() : null;
6762
}
6863

6964
/**
7065
* @return Session|null The session
7166
*/
7267
public function getSession()
7368
{
74-
if ($request = $this->getRequest()) {
75-
return $request->getSession();
76-
}
69+
return ($request = $this->getRequest()) ? $request->getSession() : null;
7770
}
7871

7972
/**

Templating/Helper/CodeHelper.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ public function formatArgs(array $args)
110110
* @param string $file A file path
111111
* @param int $line The selected line number
112112
*
113-
* @return string An HTML string
113+
* @return string|null An HTML string
114114
*/
115115
public function fileExcerpt($file, $line)
116116
{
@@ -138,6 +138,8 @@ public function fileExcerpt($file, $line)
138138

139139
return '<ol start="'.max($line - 3, 1).'">'.implode("\n", $lines).'</ol>';
140140
}
141+
142+
return null;
141143
}
142144

143145
/**

Templating/Helper/StopwatchHelper.php

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,14 @@ public function getName()
3535

3636
public function __call($method, $arguments = [])
3737
{
38-
if (null !== $this->stopwatch) {
39-
if (method_exists($this->stopwatch, $method)) {
40-
return \call_user_func_array([$this->stopwatch, $method], $arguments);
41-
}
38+
if (null === $this->stopwatch) {
39+
return null;
40+
}
4241

43-
throw new \BadMethodCallException(sprintf('Method "%s" of Stopwatch does not exist', $method));
42+
if (method_exists($this->stopwatch, $method)) {
43+
return \call_user_func_array([$this->stopwatch, $method], $arguments);
4444
}
45+
46+
throw new \BadMethodCallException(sprintf('Method "%s" of Stopwatch does not exist', $method));
4547
}
4648
}

Tests/DependencyInjection/FrameworkExtensionTest.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,9 @@ public function testPropertyAccessCache()
8585
$container = $this->createContainerFromFile('property_accessor');
8686

8787
if (!method_exists(PropertyAccessor::class, 'createCache')) {
88-
return $this->assertFalse($container->hasDefinition('cache.property_access'));
88+
$this->assertFalse($container->hasDefinition('cache.property_access'));
89+
90+
return;
8991
}
9092

9193
$cache = $container->getDefinition('cache.property_access');
@@ -98,7 +100,9 @@ public function testPropertyAccessCacheWithDebug()
98100
$container = $this->createContainerFromFile('property_accessor', ['kernel.debug' => true]);
99101

100102
if (!method_exists(PropertyAccessor::class, 'createCache')) {
101-
return $this->assertFalse($container->hasDefinition('cache.property_access'));
103+
$this->assertFalse($container->hasDefinition('cache.property_access'));
104+
105+
return;
102106
}
103107

104108
$cache = $container->getDefinition('cache.property_access');

0 commit comments

Comments
 (0)