-
Notifications
You must be signed in to change notification settings - Fork 146
Server Timing - Allow description and make duration optional #2379
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
base: trunk
Are you sure you want to change the base?
Changes from all commits
3a2eefe
c91e96c
41b677b
ca2985e
d5b4eec
83dd4e2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -37,6 +37,14 @@ class Perflab_Server_Timing_Metric { | |
| */ | ||
| private $before_value; | ||
|
|
||
| /** | ||
| * The metric description. | ||
| * | ||
| * @since n.e.x.t | ||
| * @var string|null | ||
| */ | ||
| private $description = null; | ||
|
|
||
| /** | ||
| * Constructor. | ||
| * | ||
|
|
@@ -142,4 +150,36 @@ public function measure_after(): void { | |
|
|
||
| $this->set_value( ( microtime( true ) - $this->before_value ) * 1000.0 ); | ||
| } | ||
|
|
||
| /** | ||
| * Sets the metric description. | ||
| * | ||
| * @since n.e.x.t | ||
| * | ||
| * @param non-empty-string $description The metric description. | ||
| */ | ||
| public function set_description( string $description ): void { | ||
| if ( 0 !== did_action( 'perflab_server_timing_send_header' ) && ! doing_action( 'perflab_server_timing_send_header' ) ) { | ||
| _doing_it_wrong( | ||
| __METHOD__, | ||
| /* translators: %s: WordPress action name */ | ||
| sprintf( esc_html__( 'The method must be called before or during the %s action.', 'performance-lab' ), 'perflab_server_timing_send_header' ), | ||
| '' | ||
| ); | ||
| return; | ||
| } | ||
|
|
||
| $this->description = $description; | ||
| } | ||
|
Comment on lines
+159
to
+173
|
||
|
|
||
| /** | ||
| * Gets the metric description. | ||
| * | ||
| * @since n.e.x.t | ||
| * | ||
| * @return string|null The metric description, or null if none set. | ||
| */ | ||
| public function get_description(): ?string { | ||
| return $this->description; | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
set_description()adds a new “must be called before or duringperflab_server_timing_send_header” guard (via_doing_it_wrong()and early return), but there is no test covering the late-call behavior (similar totest_set_value_prevents_late_measurement). Adding a unit test for the late-call path would help prevent regressions.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The late-call guard in
set_description()uses the exact samedid_action()/doing_action()pattern as the existingset_value()method(lines 91–99).
Adding a test for this would require calling:
However, this triggers the global singleton to re-register default metrics
(e.g., before-template), which causes test isolation failures.