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

Fix deprecation warnings on PHP 8.2 #190

Merged
merged 5 commits into from
May 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
42 changes: 29 additions & 13 deletions src/Logger.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,16 @@

class Logger {

public $time = 0;
public $query_count = 0;
public $query_time = 0;
public $cache_hits = 0;
public $cache_misses = 0;
public $cache_ratio = null;
public $hook_count = 0;
public $hook_time = 0;
public $request_count = 0;
public $request_time = 0;
public $callback_count = 0;

public $time = 0;
public $query_count = 0;
public $query_time = 0;
public $cache_hits = 0;
public $cache_misses = 0;
public $cache_ratio = null;
public $hook_count = 0;
public $hook_time = 0;
public $request_count = 0;
public $request_time = 0;
private $start_time = null;
private $query_offset = null;
private $cache_hit_offset = null;
Expand All @@ -24,12 +22,30 @@ class Logger {
private $hook_depth = 0;
private $request_start_time = null;

private $definitions = array();

public static $active_loggers = array();

public function __construct( $definition = array() ) {
foreach ( $definition as $k => $v ) {
$this->$k = $v;
$this->definitions[ $k ] = $v;
}
}

public function __get( $key ) {
if ( isset( $this->definitions[ $key ] ) ) {
return $this->definitions[ $key ];
}

return null;
}

public function __set( $key, $value ) {
$this->definitions[ $key ] = $value;
}

public function __isset( $key ) {
return isset( $this->definitions[ $key ] );
}

/**
Expand Down
14 changes: 10 additions & 4 deletions src/Profiler.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,11 @@ function () {
}
}
);
if ( 'hook' === $this->type
&& ':before' === substr( $this->focus, -7, 7 ) ) {
if (
'hook' === $this->type &&
$this->focus &&
':before' === substr( $this->focus, -7, 7 )
) {
$stage_hooks = array();
foreach ( $this->stage_hooks as $hooks ) {
$stage_hooks = array_merge( $stage_hooks, $hooks );
Expand All @@ -114,8 +117,11 @@ function () {
WP_CLI::add_hook( 'after_wp_config_load', array( $this, 'wp_tick_profile_begin' ) );
}
WP_CLI::add_wp_hook( $end_hook, array( $this, 'wp_tick_profile_end' ), -9999 );
} elseif ( 'hook' === $this->type
&& ':after' === substr( $this->focus, -6, 6 ) ) {
} elseif (
'hook' === $this->type &&
$this->focus &&
':after' === substr( $this->focus, -6, 6 )
) {
$start_hook = substr( $this->focus, 0, -6 );
WP_CLI::add_wp_hook( $start_hook, array( $this, 'wp_tick_profile_begin' ), 9999 );
} else {
Expand Down