diff --git a/src/Error/ExceptionRenderer.php b/src/Error/ExceptionRenderer.php index df1fc0e703f..38d12f859ee 100644 --- a/src/Error/ExceptionRenderer.php +++ b/src/Error/ExceptionRenderer.php @@ -83,9 +83,9 @@ class ExceptionRenderer implements ExceptionRendererInterface * If set, this will be request used to create the controller that will render * the error. * - * @var ServerRequestInterface + * @var \Psr\Http\Message\ServerRequestInterface */ - public $request = ''; + protected $request = null; /** * Creates the controller to perform rendering on the error response. @@ -125,11 +125,8 @@ protected function _unwrap($exception) */ protected function _getController() { - $request = $this->request; - if (!$request) { - if (!$request = Router::getRequest(true)) { - $request = ServerRequestFactory::fromGlobals(); - } + if (!$request = $this->request ?: Router::getRequest(true)) { + $request = ServerRequestFactory::fromGlobals(); } $response = new Response(); diff --git a/tests/test_app/TestApp/Error/TestAppsExceptionRenderer.php b/tests/test_app/TestApp/Error/TestAppsExceptionRenderer.php index 1bfb7b86ce0..d4fdc410351 100644 --- a/tests/test_app/TestApp/Error/TestAppsExceptionRenderer.php +++ b/tests/test_app/TestApp/Error/TestAppsExceptionRenderer.php @@ -7,7 +7,6 @@ use Cake\Http\Response; use Cake\Http\ServerRequest; use Cake\Routing\Router; -use Psr\Http\Message\ServerRequestInterface; use TestApp\Controller\TestAppsErrorController; class TestAppsExceptionRenderer extends ExceptionRenderer @@ -18,11 +17,8 @@ class TestAppsExceptionRenderer extends ExceptionRenderer */ protected function _getController() { - $request = $this->request; - if (!$request) { - if (!$request = Router::getRequest(true)) { - $request = new ServerRequest(); - } + if (!$request = $this->request ?: Router::getRequest(true)) { + $request = new ServerRequest(); } $response = new Response(); try {