Skip to content

Commit c3557b6

Browse files
javiereguiluzderrabus
authored andcommitted
Simplify some code with null coalesce operator
1 parent 9f79bdb commit c3557b6

File tree

6 files changed

+6
-10
lines changed

6 files changed

+6
-10
lines changed

Command/AssetsInstallCommand.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -278,10 +278,6 @@ private function getPublicDirectory(ContainerInterface $container): string
278278

279279
$composerConfig = json_decode(file_get_contents($composerFilePath), true);
280280

281-
if (isset($composerConfig['extra']['public-dir'])) {
282-
return $composerConfig['extra']['public-dir'];
283-
}
284-
285-
return $defaultPublicDir;
281+
return $composerConfig['extra']['public-dir'] ?? $defaultPublicDir;
286282
}
287283
}

Console/Descriptor/JsonDescriptor.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ protected function describeContainerAlias(Alias $alias, array $options = [], Con
134134

135135
protected function describeEventDispatcherListeners(EventDispatcherInterface $eventDispatcher, array $options = [])
136136
{
137-
$this->writeData($this->getEventDispatcherListenersData($eventDispatcher, \array_key_exists('event', $options) ? $options['event'] : null), $options);
137+
$this->writeData($this->getEventDispatcherListenersData($eventDispatcher, $options['event'] ?? null), $options);
138138
}
139139

140140
protected function describeCallable($callable, array $options = [])

Console/Descriptor/MarkdownDescriptor.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ protected function describeContainerEnvVars(array $envs, array $options = [])
258258

259259
protected function describeEventDispatcherListeners(EventDispatcherInterface $eventDispatcher, array $options = [])
260260
{
261-
$event = \array_key_exists('event', $options) ? $options['event'] : null;
261+
$event = $options['event'] ?? null;
262262

263263
$title = 'Registered listeners';
264264
if (null !== $event) {

Console/Descriptor/TextDescriptor.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -442,7 +442,7 @@ protected function describeContainerEnvVars(array $envs, array $options = [])
442442

443443
protected function describeEventDispatcherListeners(EventDispatcherInterface $eventDispatcher, array $options = [])
444444
{
445-
$event = \array_key_exists('event', $options) ? $options['event'] : null;
445+
$event = $options['event'] ?? null;
446446

447447
if (null !== $event) {
448448
$title = sprintf('Registered Listeners for "%s" Event', $event);

Console/Descriptor/XmlDescriptor.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ protected function describeContainerAlias(Alias $alias, array $options = [], Con
8888

8989
protected function describeEventDispatcherListeners(EventDispatcherInterface $eventDispatcher, array $options = [])
9090
{
91-
$this->writeDocument($this->getEventDispatcherListenersDocument($eventDispatcher, \array_key_exists('event', $options) ? $options['event'] : null));
91+
$this->writeDocument($this->getEventDispatcherListenersDocument($eventDispatcher, $options['event'] ?? null));
9292
}
9393

9494
protected function describeCallable($callable, array $options = [])

Controller/ControllerTrait.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ protected function json($data, int $status = 200, array $headers = [], array $co
144144
protected function file($file, string $fileName = null, string $disposition = ResponseHeaderBag::DISPOSITION_ATTACHMENT): BinaryFileResponse
145145
{
146146
$response = new BinaryFileResponse($file);
147-
$response->setContentDisposition($disposition, null === $fileName ? $response->getFile()->getFilename() : $fileName);
147+
$response->setContentDisposition($disposition, $fileName ?? $response->getFile()->getFilename());
148148

149149
return $response;
150150
}

0 commit comments

Comments
 (0)