run_check_with_result( $check, $result ); } ); return $result; } /** * Runs a given check with the given result object to amend. * * @since 1.0.0 * * @param Check $check The check to run. * @param Check_Result $result The result object to amend. * * @throws Exception Thrown when check fails with critical error. */ private function run_check_with_result( Check $check, Check_Result $result ) { // If $check implements Preparation interface, ensure the preparation and clean up is run. if ( $check instanceof Preparation ) { $cleanup = $check->prepare(); try { $check->run( $result ); } catch ( Exception $e ) { // Run clean up in case of any exception thrown from check. $cleanup(); throw $e; } $cleanup(); return; } // Otherwise, just run the check. $check->run( $result ); } }