-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
docs: fix PHPDoc types in Filter
class.
#7451
Conversation
I don't change the return type in |
I think the filter return values need to remain https://codeigniter4.github.io/CodeIgniter4/incoming/filters.html#creating-a-filter |
Ok I got it. Thanks you @MGatner ! |
I don't think a filter returns |
Personally, I would like to reduce the number of allowed types like the following. --- a/system/Filters/FilterInterface.php
+++ b/system/Filters/FilterInterface.php
@@ -31,7 +31,7 @@ interface FilterInterface
*
* @param array|null $arguments
*
- * @return mixed
+ * @return RequestInterface|ResponseInterface|string|void
*/
public function before(RequestInterface $request, $arguments = null);
@@ -43,7 +43,7 @@ interface FilterInterface
*
* @param array|null $arguments
*
- * @return mixed
+ * @return ResponseInterface|void
*/
public function after(RequestInterface $request, ResponseInterface $response, $arguments = null);
} |
I changed the PHPDoc return type first, then I will open another PR to handle this. |
@kenjis I want to check what will need to be change in Filter class if we want to stopping filters only non-empty string. |
If we change the code, It is a breaking change. |
I am willing to help with this BC feature in the future!
So do I need to modify the user guide in this PR? Or need to another PR to handle this pre-work. And I wonder if there is anything else that needs to be modified in this PR. |
system/Filters/FilterInterface.php
Outdated
@@ -31,7 +31,7 @@ interface FilterInterface | |||
* | |||
* @param array|null $arguments | |||
* | |||
* @return mixed | |||
* @return RequestInterface|ResponseInterface|string|void |
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.
This is a bit odd, but correct because now we can return any non-empty value.
* @return RequestInterface|ResponseInterface|string|void | |
* @return mixed|RequestInterface|ResponseInterface|void |
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'm okay with this change, but I would not mind if we left it as it was (only mixed
).
I don't have a strong opinion.
I agree with the future change to only allow non-empty strings, but I don't know if the team would agree to that. @codeigniter4/core-team Any comment? |
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.
If we want to introduce these return-type changes, can we do it once, without breaking it down into further releases? Are we afraid that this would break people's code entirely?
I was thinking about a scenario where this could break the app for good, and I couldn't find anything.
system/Filters/FilterInterface.php
Outdated
@@ -31,7 +31,7 @@ interface FilterInterface | |||
* | |||
* @param array|null $arguments | |||
* | |||
* @return mixed | |||
* @return RequestInterface|ResponseInterface|string|void |
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'm okay with this change, but I would not mind if we left it as it was (only mixed
).
I don't have a strong opinion.
@kenjis @michalsn @MGatner I have been change the return type
I will open the other PR to handle this after this PR is merged.
I think the better way is add a notice at user guide page first and may be update non-empty string in next version as Kenjis says. |
@michalsn Changing the return type means changing the CodeIgniter4/system/Filters/Filters.php Lines 187 to 192 in 729634c
This is a breaking change. |
@kenjis If we want to change the return type, we can't avoid a breaking change. Adding a note to the user guide first and then changing it in the future gives us nothing. Developers who already have built their apps most likely won't see the note. They will notice it when we introduce a change into the code - hopefully reading the release notes. The real question is if other developers take advantage of the current implementation. Because for me, that's the only real problem. |
I don't know. But it is documented as non-empty value, some devs may be using It is possible that this change could actually break existing applications. So I don't strongly advocate making the change. However, I don't think there is a need to allow any non-empty value. We don't even use the return value itself, so if we want to stop later filters, I think one type value for it is sufficient. |
So... Is there a consensus here? Or can we have a notice for user guide first and change return type to non-empty string in I think have a notice in user guide may not make the developers who have been implemented to make changes, but it can prevent future devs who need this method from defining other types. |
The current changes seem fine. I don't see a good reason to change the return signature for I'm okay with adding a note to the user guide to return only non-empty strings. |
This PR is okay. |
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.
Considering that PSR-15 was already 5 years ago, the use of the approach applied in CI surprises me a little.
In addition, the implementation of filter processing directly contradicts the description of filter methods.
system/Filters/FilterInterface.php
Outdated
@@ -31,7 +31,7 @@ interface FilterInterface | |||
* | |||
* @param array|null $arguments | |||
* | |||
* @return RequestInterface|ResponseInterface|string|void | |||
* @return mixed |
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 think the return type should be like this. Which corresponds to the description of the method.
That is, either we complete the processing of the request by returning a response. Or further processing of the request continues and the method returns nothing.
* @return mixed | |
* @return ResponseInterface|void |
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.
How to stop the later filters?
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 did not understand the question.
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.
It will return other types that are used for stop later filters.
https://codeigniter4.github.io/CodeIgniter4/incoming/filters.html#before-filters
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 filter that returns a non-empty result dequeues filters that, for example, are responsible for access.
I think this is a stupid idea.
But if such an implementation is needed (to shoot yourself in the foot), then you can throw a FilterStopPropagation exception.
system/Filters/FilterInterface.php
Outdated
@@ -43,7 +43,7 @@ public function before(RequestInterface $request, $arguments = null); | |||
* | |||
* @param array|null $arguments | |||
* | |||
* @return ResponseInterface|void | |||
* @return mixed |
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 think that it is more acceptable to return only ResponeInterface here.
* @return mixed | |
* @return ResponseInterface |
Description
See #6310
Checklist: