Browse Source

Fix errors reported by phpstan in Error package

ADmad 8 years ago
parent
commit
913a7284e1

+ 1 - 1
src/Error/ExceptionRenderer.php

@@ -170,7 +170,7 @@ class ExceptionRenderer implements ExceptionRendererInterface
         $message = $this->_message($exception, $code);
         $url = $this->controller->request->getRequestTarget();
 
-        if (method_exists($exception, 'responseHeader')) {
+        if ($exception instanceof CakeException) {
             $this->controller->response->header($exception->responseHeader());
         }
         $this->controller->response->statusCode($code);

+ 4 - 3
src/Error/Middleware/ErrorHandlerMiddleware.php

@@ -16,6 +16,7 @@ namespace Cake\Error\Middleware;
 
 use Cake\Core\App;
 use Cake\Core\Configure;
+use Cake\Core\Exception\Exception as CakeException;
 use Cake\Core\InstanceConfigTrait;
 use Cake\Error\ExceptionRenderer;
 use Cake\Log\Log;
@@ -90,7 +91,7 @@ class ErrorHandlerMiddleware
     {
         try {
             return $next($request, $response);
-        } catch (\Exception $e) {
+        } catch (Exception $e) {
             return $this->handleException($e, $request, $response);
         }
     }
@@ -111,7 +112,7 @@ class ErrorHandlerMiddleware
             $this->logException($request, $exception);
 
             return $res;
-        } catch (\Exception $e) {
+        } catch (Exception $e) {
             $this->logException($request, $e);
 
             $body = $response->getBody();
@@ -193,7 +194,7 @@ class ErrorHandlerMiddleware
         );
         $debug = Configure::read('debug');
 
-        if ($debug && method_exists($exception, 'getAttributes')) {
+        if ($debug && $exception instanceof CakeException) {
             $attributes = $exception->getAttributes();
             if ($attributes) {
                 $message .= "\nException Attributes: " . var_export($exception->getAttributes(), true);