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 ea56ad0 + 6e7c383 commit b0eb9ba
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Firewall/RememberMeListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public function __construct(TokenStorageInterface $tokenStorage, RememberMeServi
}

$this->catchExceptions = $catchExceptions;
$this->sessionStrategy = null === $sessionStrategy ? new SessionAuthenticationStrategy(SessionAuthenticationStrategy::MIGRATE) : $sessionStrategy;
$this->sessionStrategy = $sessionStrategy ?? new SessionAuthenticationStrategy(SessionAuthenticationStrategy::MIGRATE);
}

/**
Expand Down
8 changes: 4 additions & 4 deletions Tests/Firewall/ExceptionListenerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public function testAccessDeniedExceptionFullFledgedAndWithoutAccessDeniedHandle
$listener->onKernelException($event);

$this->assertNull($event->getResponse());
$this->assertSame(null === $eventException ? $exception : $eventException, $event->getThrowable()->getPrevious());
$this->assertSame($eventException ?? $exception, $event->getThrowable()->getPrevious());
}

/**
Expand All @@ -122,7 +122,7 @@ public function testAccessDeniedExceptionFullFledgedAndWithoutAccessDeniedHandle

$this->assertEquals('Unauthorized', $event->getResponse()->getContent());
$this->assertEquals(401, $event->getResponse()->getStatusCode());
$this->assertSame(null === $eventException ? $exception : $eventException, $event->getThrowable()->getPrevious());
$this->assertSame($eventException ?? $exception, $event->getThrowable()->getPrevious());
}

/**
Expand All @@ -139,7 +139,7 @@ public function testAccessDeniedExceptionFullFledgedAndWithAccessDeniedHandlerAn
$listener->onKernelException($event);

$this->assertEquals('error', $event->getResponse()->getContent());
$this->assertSame(null === $eventException ? $exception : $eventException, $event->getThrowable()->getPrevious());
$this->assertSame($eventException ?? $exception, $event->getThrowable()->getPrevious());
}

/**
Expand All @@ -156,7 +156,7 @@ public function testAccessDeniedExceptionNotFullFledged(\Exception $exception, \
$listener->onKernelException($event);

$this->assertEquals('OK', $event->getResponse()->getContent());
$this->assertSame(null === $eventException ? $exception : $eventException, $event->getThrowable()->getPrevious());
$this->assertSame($eventException ?? $exception, $event->getThrowable()->getPrevious());
}

public function testLogoutException()
Expand Down

0 comments on commit b0eb9ba

Please sign in to comment.