1 | <?php namespace Anomaly\Streams\Platform\Exception; |
||
17 | class ExceptionHandler extends \Illuminate\Foundation\Exceptions\Handler |
||
18 | { |
||
19 | |||
20 | /** |
||
21 | * A list of the exception types that should not be reported. |
||
22 | * |
||
23 | * @var array |
||
24 | */ |
||
25 | protected $dontReport = [ |
||
26 | \Illuminate\Auth\AuthenticationException::class, |
||
27 | \Illuminate\Auth\Access\AuthorizationException::class, |
||
28 | \Symfony\Component\HttpKernel\Exception\HttpException::class, |
||
29 | \Illuminate\Database\Eloquent\ModelNotFoundException::class, |
||
30 | \Illuminate\Session\TokenMismatchException::class, |
||
31 | \Illuminate\Validation\ValidationException::class, |
||
32 | ]; |
||
33 | |||
34 | /** |
||
35 | * Render an exception into an HTTP response. |
||
36 | * |
||
37 | * @param Request $request |
||
38 | * @param Exception $e |
||
39 | * @return Response |
||
40 | */ |
||
41 | public function render($request, Exception $e) |
||
59 | |||
60 | /** |
||
61 | * Render the given HttpException. |
||
62 | * |
||
63 | * @param \Symfony\Component\HttpKernel\Exception\HttpException $e |
||
64 | * @return \Symfony\Component\HttpFoundation\Response |
||
65 | */ |
||
66 | protected function renderHttpException(HttpException $e) |
||
76 | |||
77 | /** |
||
78 | * Convert an authentication exception into an unauthenticated response. |
||
79 | * |
||
80 | * @param \Illuminate\Http\Request $request |
||
81 | * @param \Illuminate\Auth\AuthenticationException $exception |
||
82 | * @return \Illuminate\Http\Response |
||
83 | */ |
||
84 | protected function unauthenticated($request, AuthenticationException $exception) |
||
96 | } |
||
97 |
If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.
Let’s take a look at an example:
Our function
my_function
expects aPost
object, and outputs the author of the post. The base classPost
returns a simple string and outputting a simple string will work just fine. However, the child classBlogPost
which is a sub-type ofPost
instead decided to return anobject
, and is therefore violating the SOLID principles. If aBlogPost
were passed tomy_function
, PHP would not complain, but ultimately fail when executing thestrtoupper
call in its body.