Skip to content
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

Uncaught assertions causing fatal errors on PHP 8+ #706

Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Add assert helper method with logging
  • Loading branch information
nmolham-godaddy committed Aug 29, 2024
commit 468918502c34a106f321686e64afd74c1adcecd8
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