-
Notifications
You must be signed in to change notification settings - Fork 63
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
Rewrite WPFunctions methods [MAILPOET-1920] #1896
Conversation
57a6303
to
cd6ed76
Compare
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 like the change since IDE will give me parameter hints.
Just want to ask why did you kept firs 6 functions called using call_user_func_array
?
I kept using |
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 realized that some functions are from wooCommerce during the first review. I think we should move those to their own wrapper.
lib/WP/Functions.php
Outdated
} | ||
|
||
function wpRemoteRetrieveResponseCode() { | ||
return call_user_func_array('wp_remote_retrieve_response_code', func_get_args()); | ||
function wcGetCustomerOrderCount($user_id) { |
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 thinking about WooCommerce functions. We already have a service WooCommerce\Helper
so I what about putting woo commerce functions into this helper? They are not WordPress functions.
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.
PHP Stan doesn't support function_exist check :( but the author mentions here that we can use is_callable
as a workaround.
lib/WP/Functions.php
Outdated
} | ||
|
||
function wpRemoteRetrieveBody() { | ||
return call_user_func_array('wp_remote_retrieve_body', func_get_args()); | ||
function addAction() { |
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.
Add action has not dynamic number of arguments so I think this one can be refactored
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.
When I refactor addAction
tests start failing and I don't know why, I kept it that way.
lib/WP/Functions.php
Outdated
@@ -19,486 +19,499 @@ static function set(Functions $instance) { | |||
self::$instance = $instance; | |||
} | |||
|
|||
function wpRemotePost() { | |||
return call_user_func_array('wp_remote_post', func_get_args()); | |||
function doAction() { |
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 for this and applyFilters
we could do at least this:
/**
* @param string $tag
* @param mixed ...$args
* @return mixed
*/
function doAction($tag, ...$args) {
...
}
eb95d41
to
c68cee5
Compare
c68cee5
to
e6e5eaa
Compare
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 rewrote the whole
WP/Functions.php
file and sorted methods alphabetically.To review, please read the file as if it's a new one, because the diff doesn't make sense due to the reordering.