Skip to content

Commit

Permalink
minor #42165 Simplify some code with null coalesce operator (javiereg…
Browse files Browse the repository at this point in the history
…uiluz)

This PR was squashed before being merged into the 4.4 branch.

Discussion
----------

Simplify some code with null coalesce operator

| Q             | A
| ------------- | ---
| Branch?       | 4.4
| Bug fix?      | no
| New feature?  | no
| Deprecations? | no
| Tickets       | -
| License       | MIT
| Doc PR        | -

For your consideration. There are many other possible usages of null coalesce operator, but the result is not very readable ... so this PR only contains the changes where the result is clearly better.

Commits
-------

17ad5b75fa Simplify some code with null coalesce operator
  • Loading branch information
derrabus committed Jul 18, 2021
2 parents f96639d + 0b693cf commit 6dfb6c5
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 7 deletions.
2 changes: 1 addition & 1 deletion EventListener/DebugHandlersListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public function __construct(callable $exceptionHandler = null, LoggerInterface $

$this->exceptionHandler = $exceptionHandler;
$this->logger = $logger;
$this->levels = null === $levels ? \E_ALL : $levels;
$this->levels = $levels ?? \E_ALL;
$this->throwAt = \is_int($throwAt) ? $throwAt : (null === $throwAt ? null : ($throwAt ? \E_ALL : null));
$this->scream = $scream;
$this->fileLinkFormat = $fileLinkFormat;
Expand Down
6 changes: 1 addition & 5 deletions Profiler/Profile.php
Original file line number Diff line number Diff line change
Expand Up @@ -156,11 +156,7 @@ public function setUrl($url)
*/
public function getTime()
{
if (null === $this->time) {
return 0;
}

return $this->time;
return $this->time ?? 0;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion Tests/KernelTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -709,7 +709,7 @@ protected function getBundle($dir = null, $parent = null, $className = null, $bu
$bundle
->expects($this->any())
->method('getName')
->willReturn(null === $bundleName ? \get_class($bundle) : $bundleName)
->willReturn($bundleName ?? \get_class($bundle))
;

$bundle
Expand Down

0 comments on commit 6dfb6c5

Please sign in to comment.