Skip to content

Commit

Permalink
Ignore safety checks in code coverage.
Browse files Browse the repository at this point in the history
  • Loading branch information
Dan0sz committed Mar 27, 2024
1 parent 4d04e1f commit a0ff8e9
Show file tree
Hide file tree
Showing 7 changed files with 78 additions and 55 deletions.
19 changes: 14 additions & 5 deletions src/Admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ private function do_optimize_settings() {

/**
* Detection Settings tab
*
* @return void
*/
private function do_detection_settings() {
Expand All @@ -77,6 +78,7 @@ private function do_detection_settings() {

/**
* Advanced Settings tab
*
* @return void
*/
private function do_advanced_settings() {
Expand All @@ -85,6 +87,7 @@ private function do_advanced_settings() {

/**
* Help Tab
*
* @return void
*/
private function do_help() {
Expand All @@ -93,6 +96,7 @@ private function do_help() {

/**
* Add failsafe for failing premium plugin updates.
*
* @return Updates
*/
private function maybe_handle_failed_premium_plugin_updates() {
Expand All @@ -114,6 +118,8 @@ private function maybe_handle_failed_premium_plugin_updates() {

/**
* Checks if an update notice should be displayed after updating.
*
* @codeCoverageIgnore
*/
private function maybe_do_after_update_notice() {
if ( OMGF_CURRENT_DB_VERSION != false && version_compare( OMGF_CURRENT_DB_VERSION, OMGF_DB_VERSION, '<' ) ) {
Expand Down Expand Up @@ -157,6 +163,8 @@ public function enqueue_admin_scripts( $hook ) {

/**
* Add notice to admin screen.
*
* @codeCoverageIgnore
*/
public function print_notices() {
Notice::print_notices();
Expand Down Expand Up @@ -186,11 +194,11 @@ public function force_optimized_fonts_from_db( $alloptions ) {
*/
public function clean_up_cache( $value, $old_value ) {
if ( $old_value == $value ) {
return;
return; // @codeCoverageIgnore
}

if ( $old_value == null ) {
return;
return; // @codeCoverageIgnore
}

$cache_keys = explode( ',', $old_value );
Expand All @@ -206,6 +214,7 @@ public function clean_up_cache( $value, $old_value ) {

/**
* Shows notice if $option_name is in $show_notice array.
*
* @see $show_message
*
* @param $old_values
Expand All @@ -218,14 +227,14 @@ public function maybe_show_stale_cache_notice( $old_values, $values ) {
* Don't show this message on the Main tab.
*/
if ( ! array_key_exists( 'tab', $_GET ) || ( $_GET[ 'tab' ] === Settings::OMGF_SETTINGS_FIELD_OPTIMIZE ) ) {
return;
return; // @codeCoverageIgnore
}

/**
* If either of these isn't an array, this means they haven't been set before.
*/
if ( ! is_array( $old_values ) || ! is_array( $values ) ) {
return;
return; // @codeCoverageIgnore
}

/**
Expand Down Expand Up @@ -266,7 +275,7 @@ function ( $key ) {
}

if ( $show_message ) {
$wp_settings_errors = [];
$wp_settings_errors = []; // @codeCoverageIgnore
}
}

Expand Down
5 changes: 3 additions & 2 deletions src/Download.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,14 @@ public function __construct(

/**
* Download $url to $path and return OMGF_UPLOAD_URL to $filename.
*
* @return string
* @throws SodiumException
* @throws TypeError
*/
public function download() {
if ( ! function_exists( 'download_url' ) ) {
require_once ABSPATH . 'wp-admin/includes/file.php';
require_once ABSPATH . 'wp-admin/includes/file.php'; // @codeCoverageIgnore
}

wp_mkdir_p( $this->path );
Expand All @@ -69,7 +70,7 @@ public function download() {
}

if ( str_starts_with( $this->url, '//' ) ) {
$this->url = 'https:' . $this->url;
$this->url = 'https:' . $this->url; // @codeCoverageIgnore
}

$tmp = download_url( $this->url );
Expand Down
2 changes: 1 addition & 1 deletion src/Filters.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public function force_ssl( $url ) {
* If the user entered https:// in the Home URL option, it's safe to assume that SSL is used.
*/
if ( ! is_ssl() && str_contains( get_home_url(), 'https://' ) ) {
$url = str_replace( 'http://', 'https://', $url );
$url = str_replace( 'http://', 'https://', $url ); // @codeCoverageIgnore
}

return $url;
Expand Down
31 changes: 18 additions & 13 deletions src/Helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public static function update_option( $setting, $value, $autoload = true ) {
}

if ( self::$settings === null ) {
self::$settings = self::get_settings();
self::$settings = self::get_settings(); // @codeCoverageIgnore
}

self::$settings[ $setting ] = $value;
Expand Down Expand Up @@ -76,7 +76,7 @@ public static function get_settings() {
);

if ( empty( self::$settings ) ) {
self::$settings = get_option( 'omgf_settings', [] );
self::$settings = get_option( 'omgf_settings', [] ); // @codeCoverageIgnore
}

return apply_filters( 'omgf_settings', wp_parse_args( self::$settings, $defaults ) );
Expand All @@ -99,7 +99,7 @@ public static function delete_option( $setting ) {

// This prevents settings from 'mysteriously' returning after being unset.
if ( empty( self::$settings ) ) {
self::$settings = self::get_settings();
self::$settings = self::get_settings(); // @codeCoverageIgnore
}

unset( self::$settings[ $setting ] );
Expand Down Expand Up @@ -218,9 +218,9 @@ public static function cache_keys() {
* the (default) stylesheet handles from the optimized fonts option.
*/
if ( empty( $cache_keys ) ) {
$optimized_fonts = self::admin_optimized_fonts();
$optimized_fonts = self::admin_optimized_fonts(); // @codeCoverageIgnore

$cache_keys = array_keys( $optimized_fonts );
$cache_keys = array_keys( $optimized_fonts ); //@codeCoverageIgnore
}

return $cache_keys;
Expand Down Expand Up @@ -253,7 +253,7 @@ public static function admin_optimized_fonts( $maybe_add = [], $force_add = fals
* @since v4.5.6
*/
if ( is_string( $optimized_fonts ) ) {
$optimized_fonts = unserialize( $optimized_fonts );
$optimized_fonts = unserialize( $optimized_fonts ); // @codeCoverageIgnore
}

/**
Expand Down Expand Up @@ -302,8 +302,7 @@ public static function optimized_fonts( $maybe_add = [], $force_add = false ) {
* @since v4.5.6
*/
if ( is_string( $optimized_fonts ) ) {
// phpcs:ignore
$optimized_fonts = unserialize( $optimized_fonts );
$optimized_fonts = unserialize( $optimized_fonts ); // @codeCoverageIgnore
}

/**
Expand Down Expand Up @@ -334,7 +333,7 @@ public static function available_used_subsets( $maybe_add = [], $intersect = fal
* get_option() should take care of this, but sometimes it doesn't.
*/
if ( is_string( $subsets ) ) {
$subsets = unserialize( $subsets );
$subsets = unserialize( $subsets ); // @codeCoverageIgnore
}

/**
Expand All @@ -359,7 +358,7 @@ public static function available_used_subsets( $maybe_add = [], $intersect = fal
self::debug_array( __( 'Filtered Subsets', 'host-webfonts-local' ), $filtered_subsets );

if ( count( $filtered_subsets ) === 1 ) {
return reset( $filtered_subsets );
return reset( $filtered_subsets ); // @codeCoverageIgnore
}

if ( ! empty( $filtered_subsets ) ) {
Expand All @@ -378,10 +377,12 @@ public static function available_used_subsets( $maybe_add = [], $intersect = fal
*
* @since v5.3.7
*
* @param array $array The array to be displayed in the debug log
* @param string $name A descriptive name to be shown in the debug log
* @param array|object $array The array to be displayed in the debug log
* @param string $name A descriptive name to be shown in the debug log
*
* @return void
*
* @codeCoverageIgnore
*/
public static function debug_array( $name, $array ) {
if ( ! self::get_option( Settings::OMGF_ADV_SETTING_DEBUG_MODE ) ||
Expand Down Expand Up @@ -419,6 +420,8 @@ public static function debug_array( $name, $array ) {
* Returns the absolute path to the log file.
*
* @return string
*
* @codeCoverageIgnore
*/
public static function log_file() {
static $log_file;
Expand All @@ -436,6 +439,8 @@ public static function log_file() {
* @param mixed $message
*
* @return void
*
* @codeCoverageIgnore
*/
public static function debug( $message ) {
if ( ! self::get_option( Settings::OMGF_ADV_SETTING_DEBUG_MODE ) ||
Expand All @@ -445,7 +450,7 @@ public static function debug( $message ) {
return;
}

error_log( current_time( 'Y-m-d H:i:s' ) . ' ' . microtime() . ": $message\n", 3, self::log_file() );
error_log( current_time( 'Y-m-d H:i:s' ) . ' ' . microtime() . ": $message\n", 3, self::log_file() ); // @codeCoverageIgnore
}

/**
Expand Down
Loading

0 comments on commit a0ff8e9

Please sign in to comment.