Skip to content

Commit

Permalink
Add assert helper method with logging
Browse files Browse the repository at this point in the history
  • Loading branch information
nmolham-godaddy committed Aug 29, 2024
1 parent 146dc3b commit 4689185
Showing 1 changed file with 18 additions and 9 deletions.
27 changes: 18 additions & 9 deletions woocommerce/class-sv-wc-plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@

use Automattic\WooCommerce\Utilities\FeaturesUtil;
use stdClass;
use Throwable;
use WC_Logger_Interface;

defined( 'ABSPATH' ) or exit;

Expand Down Expand Up @@ -67,8 +69,8 @@ abstract class SV_WC_Plugin {
/** @var string template path, without trailing slash */
private $template_path;

/** @var \WC_Logger instance */
private $logger;
/** @var WC_Logger_Interface|null instance */
private ?WC_Logger_Interface $logger = null;

/** @var SV_WP_Admin_Message_Handler instance */
private $message_handler;
Expand Down Expand Up @@ -548,7 +550,7 @@ private function get_framework_deprecated_hooks() {
$deprecated_hooks[ $deprecated_filter ] = [
'removed' => true,
'replacement' => false,
'version' => '5.8.1'
'version' => '5.8.1',
];
}

Expand Down Expand Up @@ -825,13 +827,22 @@ public function log( $message, $log_id = null ) {
$log_id = $this->get_id();
}

if ( ! is_object( $this->logger ) ) {
$this->logger = new \WC_Logger();
}
$this->logger()->add( $log_id, $message );
}

$this->logger->add( $log_id, $message );
protected function logger() : WC_Logger_Interface
{
return $this->logger ??= wc_get_logger();
}

public function assert($assertion) : void
{
try {
assert($assertion);
} catch (Throwable $exception) {
$this->logger()->debug('Assertion failed, backtrace summery: '.wp_debug_backtrace_summary());
}
}

/**
* Require and instantiate a class
Expand Down Expand Up @@ -1446,8 +1457,6 @@ public function is_plugin_active( $plugin_name ) {

return $is_active;
}


}


Expand Down

0 comments on commit 4689185

Please sign in to comment.