-
Notifications
You must be signed in to change notification settings - Fork 98
Refactor to remove repeated code. #157
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
Changes from all commits
a30e873
9778ae2
f48c9df
4fd86df
afa4fab
4e99b9b
06f1743
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -94,22 +94,10 @@ public function set_up_environment() { | |
| if ( is_wp_error( $valid_request ) ) { | ||
| wp_send_json_error( $valid_request, 403 ); | ||
| } | ||
| $runner = Plugin_Request_Utility::get_runner(); | ||
|
|
||
| if ( is_null( $runner ) ) { | ||
| $runner = new AJAX_Runner(); | ||
| } | ||
|
|
||
| // Make sure we are using the correct runner instance. | ||
| if ( ! ( $runner instanceof AJAX_Runner ) ) { | ||
| wp_send_json_error( | ||
| new WP_Error( 'invalid-runner', __( 'AJAX Runner was not initialized correctly.', 'plugin-check' ) ), | ||
| 500 | ||
| ); | ||
| } | ||
|
|
||
| $checks = filter_input( INPUT_POST, 'checks', FILTER_DEFAULT, FILTER_FORCE_ARRAY ); | ||
| $plugin = filter_input( INPUT_POST, 'plugin', FILTER_SANITIZE_FULL_SPECIAL_CHARS ); | ||
| $runner = $this->get_runner(); | ||
| $checks = $this->get_checks(); | ||
| $plugin = $this->get_plugin(); | ||
|
|
||
| try { | ||
| $runner->set_check_slugs( $checks ); | ||
|
|
@@ -189,22 +177,9 @@ public function get_checks_to_run() { | |
| wp_send_json_error( $valid_request, 403 ); | ||
| } | ||
|
|
||
| $checks = filter_input( INPUT_POST, 'checks', FILTER_DEFAULT, FILTER_FORCE_ARRAY ); | ||
| $checks = is_null( $checks ) ? array() : $checks; | ||
| $plugin = filter_input( INPUT_POST, 'plugin', FILTER_SANITIZE_FULL_SPECIAL_CHARS ); | ||
| $runner = Plugin_Request_Utility::get_runner(); | ||
|
|
||
| if ( is_null( $runner ) ) { | ||
| $runner = new AJAX_Runner(); | ||
| } | ||
|
|
||
| // Make sure we are using the correct runner instance. | ||
| if ( ! ( $runner instanceof AJAX_Runner ) ) { | ||
| wp_send_json_error( | ||
| new WP_Error( 'invalid-runner', __( 'AJAX Runner was not initialized correctly.', 'plugin-check' ) ), | ||
| 403 | ||
| ); | ||
| } | ||
| $runner = $this->get_runner(); | ||
| $checks = $this->get_checks(); | ||
| $plugin = $this->get_plugin(); | ||
|
|
||
| try { | ||
| $runner->set_check_slugs( $checks ); | ||
|
|
@@ -240,23 +215,9 @@ public function run_checks() { | |
| wp_send_json_error( $valid_request, 403 ); | ||
| } | ||
|
|
||
| $runner = Plugin_Request_Utility::get_runner(); | ||
|
|
||
| if ( is_null( $runner ) ) { | ||
| $runner = new AJAX_Runner(); | ||
| } | ||
|
|
||
| // Make sure we are using the correct runner instance. | ||
| if ( ! ( $runner instanceof AJAX_Runner ) ) { | ||
| wp_send_json_error( | ||
| new WP_Error( 'invalid-runner', __( 'AJAX Runner was not initialized correctly.', 'plugin-check' ) ), | ||
| 500 | ||
| ); | ||
| } | ||
|
|
||
| $checks = filter_input( INPUT_POST, 'checks', FILTER_DEFAULT, FILTER_FORCE_ARRAY ); | ||
| $checks = is_null( $checks ) ? array() : $checks; | ||
| $plugin = filter_input( INPUT_POST, 'plugin', FILTER_SANITIZE_FULL_SPECIAL_CHARS ); | ||
| $runner = $this->get_runner(); | ||
| $checks = $this->get_checks(); | ||
| $plugin = $this->get_plugin(); | ||
|
|
||
| try { | ||
| $runner->set_check_slugs( $checks ); | ||
|
|
@@ -278,6 +239,48 @@ public function run_checks() { | |
| ); | ||
| } | ||
|
|
||
|
|
||
| /** | ||
| * Get the AJAX_Runner runner. | ||
| * | ||
| * @since n.e.x.t | ||
| * | ||
| * @return AJAX_Runner | ||
| */ | ||
| protected function get_runner() { | ||
| $runner = Plugin_Request_Utility::get_runner(); | ||
|
|
||
| if ( ! ( $runner instanceof AJAX_Runner ) ) { | ||
| $runner = new AJAX_Runner(); | ||
| } | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a functional change we shouldn't make: This method should only instantiate a new
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why would we want to do that? If it returns null, it is okay to create a new runner right? If |
||
|
|
||
| return $runner; | ||
| } | ||
|
|
||
| /** | ||
| * Get array of checks to run. | ||
| * | ||
| * @since n.e.x.t | ||
| * | ||
| * @return array | ||
| */ | ||
| protected function get_checks() { | ||
| $checks = filter_input( INPUT_POST, 'checks', FILTER_DEFAULT, FILTER_FORCE_ARRAY ); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Similar function present in AJAX_Runner::get_check_slugs_param() |
||
|
|
||
| return is_null( $checks ) ? array() : (array) $checks; | ||
| } | ||
|
|
||
| /** | ||
| * Get requested plugin. | ||
| * | ||
| * @since n.e.x.t | ||
| * | ||
| * @return string | ||
| */ | ||
| protected function get_plugin() { | ||
| return filter_input( INPUT_POST, 'plugin', FILTER_SANITIZE_FULL_SPECIAL_CHARS ); | ||
| } | ||
|
|
||
| /** | ||
| * Verify the request. | ||
| * | ||
|
|
||
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.
Remove extra line.