Skip to content

Commit 913a728

Browse files
committed
Fix errors reported by phpstan in Error package
1 parent 60b224b commit 913a728

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

src/Error/ExceptionRenderer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ public function render()
170170
$message = $this->_message($exception, $code);
171171
$url = $this->controller->request->getRequestTarget();
172172

173-
if (method_exists($exception, 'responseHeader')) {
173+
if ($exception instanceof CakeException) {
174174
$this->controller->response->header($exception->responseHeader());
175175
}
176176
$this->controller->response->statusCode($code);

src/Error/Middleware/ErrorHandlerMiddleware.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
use Cake\Core\App;
1818
use Cake\Core\Configure;
19+
use Cake\Core\Exception\Exception as CakeException;
1920
use Cake\Core\InstanceConfigTrait;
2021
use Cake\Error\ExceptionRenderer;
2122
use Cake\Log\Log;
@@ -90,7 +91,7 @@ public function __invoke($request, $response, $next)
9091
{
9192
try {
9293
return $next($request, $response);
93-
} catch (\Exception $e) {
94+
} catch (Exception $e) {
9495
return $this->handleException($e, $request, $response);
9596
}
9697
}
@@ -111,7 +112,7 @@ public function handleException($exception, $request, $response)
111112
$this->logException($request, $exception);
112113

113114
return $res;
114-
} catch (\Exception $e) {
115+
} catch (Exception $e) {
115116
$this->logException($request, $e);
116117

117118
$body = $response->getBody();
@@ -193,7 +194,7 @@ protected function getMessage($request, $exception)
193194
);
194195
$debug = Configure::read('debug');
195196

196-
if ($debug && method_exists($exception, 'getAttributes')) {
197+
if ($debug && $exception instanceof CakeException) {
197198
$attributes = $exception->getAttributes();
198199
if ($attributes) {
199200
$message .= "\nException Attributes: " . var_export($exception->getAttributes(), true);

0 commit comments

Comments
 (0)