-
Notifications
You must be signed in to change notification settings - Fork 3.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Move default into class so simpler ::class syntax can be used. #9806
Conversation
* @param array $config Configuration options to use. If empty, `Configure::read('Error')` | ||
* will be used. | ||
*/ | ||
public function __construct($renderer = null, array $config = []) | ||
{ | ||
if ($renderer === null) { | ||
$renderer = Configure::read('Error.exceptionRenderer'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Couple of lines below there's Configure::read('Error')
which would return array containing exceptionRenderer
so a separate call seems unnecessary.
Personally I would avoid setting $this->renderer
unless explicitly passed and then get the renderer directly from $this->_config
in getRenderer()
method if $this->renderer
is unset.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That makes indeed more sense alltogether. Wanna help me adjust the PR here?
Current coverage is 94.86% (diff: 100%)@@ 3.next #9806 diff @@
==========================================
Files 417 417
Lines 29367 29535 +168
Methods 3616 3647 +31
Messages 0 0
Branches 0 0
==========================================
+ Hits 27863 28017 +154
- Misses 1504 1518 +14
Partials 0 0
|
Looks good to me. |
@@ -121,6 +133,10 @@ public function handleException($exception, $request, $response) | |||
*/ | |||
protected function getRenderer($exception) | |||
{ | |||
if (!$this->renderer) { | |||
$this->renderer = $this->config('exceptionRender') ?: ExceptionRenderer::class; | |||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any reason this couldn't be done in the constructor? Are you trying to avoid the class load?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't see the need to check for default / fallback class so early until it needs to be actually instantiated.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't this a case for using $_defaultConfig
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point, but that would introduce strings again, which is what I think @dereuromark is trying to remove.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, I only wanted to not have it outside to be a requirement to be passed in :) See the linked app PR
@@ -121,6 +133,10 @@ public function handleException($exception, $request, $response) | |||
*/ | |||
protected function getRenderer($exception) | |||
{ | |||
if (!$this->renderer) { | |||
$this->renderer = $this->config('exceptionRender') ?: ExceptionRenderer::class; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't this be exceptionRenderer
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yup, typo, I'll fix it.
63a5ab5
to
f4f8100
Compare
I rebased and fixed the name. |
if (is_string($this->renderer)) { | ||
$class = App::className($this->renderer, 'Error'); | ||
if (!$this->exceptionRenderer) { | ||
$this->exceptionRenderer = $this->config('exceptionRender') ?: ExceptionRenderer::class; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Still needs to be exceptionRenderer
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh that name.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah the config value doesn't!atch the one in the app skeleton
The default should be moved inside the class to allow simpler Application setup:
etc
No need to force instantiation here.