Skip to content

Commit 4c99658

Browse files
committed
Make use of the nullsafe operator
1 parent 0831881 commit 4c99658

File tree

8 files changed

+15
-33
lines changed

8 files changed

+15
-33
lines changed

Controller/ControllerResolver.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,7 @@ public function __construct(LoggerInterface $logger = null)
3636
public function getController(Request $request): callable|false
3737
{
3838
if (!$controller = $request->attributes->get('_controller')) {
39-
if (null !== $this->logger) {
40-
$this->logger->warning('Unable to look for the controller as the "_controller" parameter is missing.');
41-
}
39+
$this->logger?->warning('Unable to look for the controller as the "_controller" parameter is missing.');
4240

4341
return false;
4442
}

DataCollector/DumpDataCollector.php

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,7 @@ public function __clone()
6969

7070
public function dump(Data $data)
7171
{
72-
if ($this->stopwatch) {
73-
$this->stopwatch->start('dump');
74-
}
72+
$this->stopwatch?->start('dump');
7573

7674
['name' => $name, 'file' => $file, 'line' => $line, 'file_excerpt' => $fileExcerpt] = $this->sourceContextProvider->getContext();
7775

@@ -91,9 +89,7 @@ public function dump(Data $data)
9189
$this->data[] = compact('data', 'name', 'file', 'line', 'fileExcerpt');
9290
++$this->dataCount;
9391

94-
if ($this->stopwatch) {
95-
$this->stopwatch->stop('dump');
96-
}
92+
$this->stopwatch?->stop('dump');
9793
}
9894

9995
public function collect(Request $request, Response $response, \Throwable $exception = null)
@@ -133,9 +129,7 @@ public function collect(Request $request, Response $response, \Throwable $except
133129

134130
public function reset()
135131
{
136-
if ($this->stopwatch) {
137-
$this->stopwatch->reset();
138-
}
132+
$this->stopwatch?->reset();
139133
$this->data = [];
140134
$this->dataCount = 0;
141135
$this->isCollected = true;

DataCollector/TimeDataCollector.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,7 @@ public function reset()
5959
{
6060
$this->data = [];
6161

62-
if (null !== $this->stopwatch) {
63-
$this->stopwatch->reset();
64-
}
62+
$this->stopwatch?->reset();
6563
}
6664

6765
/**

EventListener/LocaleListener.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,7 @@ private function setLocale(Request $request)
7676

7777
private function setRouterContext(Request $request)
7878
{
79-
if (null !== $this->router) {
80-
$this->router->getContext()->setParameter('_locale', $request->getLocale());
81-
}
79+
$this->router?->getContext()->setParameter('_locale', $request->getLocale());
8280
}
8381

8482
public static function getSubscribedEvents(): array

EventListener/RouterListener.php

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -108,14 +108,12 @@ public function onKernelRequest(RequestEvent $event)
108108
$parameters = $this->matcher->match($request->getPathInfo());
109109
}
110110

111-
if (null !== $this->logger) {
112-
$this->logger->info('Matched route "{route}".', [
113-
'route' => $parameters['_route'] ?? 'n/a',
114-
'route_parameters' => $parameters,
115-
'request_uri' => $request->getUri(),
116-
'method' => $request->getMethod(),
117-
]);
118-
}
111+
$this->logger?->info('Matched route "{route}".', [
112+
'route' => $parameters['_route'] ?? 'n/a',
113+
'route_parameters' => $parameters,
114+
'request_uri' => $request->getUri(),
115+
'method' => $request->getMethod(),
116+
]);
119117

120118
$request->attributes->add($parameters);
121119
unset($parameters['_route'], $parameters['_controller']);

HttpCache/HttpCache.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -449,9 +449,7 @@ protected function fetch(Request $request, bool $catch = false): Response
449449
*/
450450
protected function forward(Request $request, bool $catch = false, Response $entry = null)
451451
{
452-
if ($this->surrogate) {
453-
$this->surrogate->addSurrogateCapability($request);
454-
}
452+
$this->surrogate?->addSurrogateCapability($request);
455453

456454
// always a "master" request (as the real master request can be in cache)
457455
$response = SubRequestHandler::handle($this->kernel, $request, HttpKernelInterface::MAIN_REQUEST, $catch);

Profiler/Profile.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ public function getParent(): ?self
7878
*/
7979
public function getParentToken(): ?string
8080
{
81-
return $this->parent ? $this->parent->getToken() : null;
81+
return $this->parent?->getToken();
8282
}
8383

8484
/**

Tests/HttpCache/HttpCacheTestCase.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,7 @@ protected function setUp(): void
5555

5656
protected function tearDown(): void
5757
{
58-
if ($this->cache) {
59-
$this->cache->getStore()->cleanup();
60-
}
58+
$this->cache?->getStore()->cleanup();
6159
$this->kernel = null;
6260
$this->cache = null;
6361
$this->caches = null;

0 commit comments

Comments
 (0)