-
Notifications
You must be signed in to change notification settings - Fork 40
Refactor for reuse of functions elsewhere #150
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
Conversation
Signed-off-by: Andy Fragen <[email protected]>
Signed-off-by: Andy Fragen <[email protected]>
| */ | ||
| function run( $package_arr ) { | ||
| foreach ( $package_arr as $package ) { | ||
| function run() { |
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.
Is there any scenario where we may want to call run( $packages ) like the function was before? Maybe for tests?
If so, it might be worth having:
function bootstrap() {
add_action( 'init', __NAMESPACE__ . '\\init' );
}
function init() {
run( get_packages() );
}
function get_packages() {
...
}
function run( $packages ) {
...
}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.
Is that over complicating things? I'm having a difficult time understanding what you're trying to solve there.
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 was just noticing that previously, run() could be called from anywhere using any packages, which may come in useful at another point during runtime, and having get_packages() and run() being independent of each other may be best.
Since the PR removes the parameter from run(), they're now tightly coupled, to each other and to get_file_data(), which also makes testing a little more awkward and can't independently verify each function as well as before.
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.
What would help make it more testable?
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.
Keeping an open mind and looking at it again. If there was more going on, then there might be more benefit in separating them. But there's not much going on in run() that someone couldn't achieve in a few lines.
Since this was more a thought and not a blocker, I think it's fine to keep as-is and if we want to open stuff up later or there's an issue in testing, we can revisit it.
Refactor allows for calling of init() elsewhere. Yes, I have a WIP for making slug-did show as true for
is_plugin_active(slug)