Skip to content

Commit 562361f

Browse files
committed
Fix typos and clarify grammar in documentation and comments
Updated various documentation and in-code comments to fix typos, improve grammar, and enhance clarity. These changes ensure better readability and more precise communication across the codebase, especially in user-facing docs and inline explanations. These issues were flagged via static analysis in PhpStorm.
1 parent 8a4987d commit 562361f

18 files changed

+85
-83
lines changed

plugins/optimization-detective/class-od-strict-url-metric.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
* Representation of the measurements taken from a single client's visit to a specific URL without additionalProperties allowed.
1717
*
1818
* This is used exclusively in the REST API endpoint for capturing new URL Metrics to prevent invalid additional data from being
19-
* submitted in the request. For URL Metrics which have been stored the looser OD_URL_Metric class is used instead.
19+
* submitted in the request. For URL Metrics which have been stored, the looser OD_URL_Metric class is used instead.
2020
*
2121
* @phpstan-import-type JSONSchema from OD_URL_Metric
2222
*

plugins/optimization-detective/class-od-tag-visitor-context.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ public function __get( string $name ) {
124124
throw new Error(
125125
esc_html(
126126
sprintf(
127-
/* translators: %s is class member variable name */
127+
/* translators: %s is the class member variable name */
128128
__( 'Unknown property %s.', 'optimization-detective' ),
129129
__CLASS__ . '::$' . $name
130130
)

plugins/optimization-detective/class-od-template-optimization-context.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ public function __get( string $name ) {
114114
throw new Error(
115115
esc_html(
116116
sprintf(
117-
/* translators: %s is class member variable name */
117+
/* translators: %s is the class member variable name */
118118
__( 'Unknown property %s.', 'optimization-detective' ),
119119
__CLASS__ . '::$' . $name
120120
)

plugins/optimization-detective/class-od-url-metric-group-collection.php

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ final class OD_URL_Metric_Group_Collection implements Countable, IteratorAggrega
5151
* value of 1, and the breakpoints are used as the maximum viewport widths for the viewport groups, with the addition of
5252
* a final viewport group which has a maximum viewport width of infinity.
5353
*
54-
* This array may be empty in which case there are no responsive breakpoints and all URL Metrics are collected in a
54+
* This array may be empty, in which case there are no responsive breakpoints, and all URL Metrics are collected in a
5555
* single group.
5656
*
5757
* @since 0.1.0
@@ -153,7 +153,7 @@ public function __construct( array $url_metrics, string $current_etag, array $br
153153
*/
154154
$this->breakpoints = $breakpoints;
155155

156-
// Set sample size.
156+
// Set the sample size.
157157
if ( $sample_size <= 0 ) {
158158
throw new InvalidArgumentException(
159159
esc_html(
@@ -211,7 +211,7 @@ public function get_sample_size(): int {
211211
}
212212

213213
/**
214-
* Gets the freshness age (TTL) for a given URL Metric..
214+
* Gets the freshness age (TTL) for a given URL Metric.
215215
*
216216
* @since 1.0.0
217217
*
@@ -224,7 +224,7 @@ public function get_freshness_ttl(): int {
224224
/**
225225
* Gets the first URL Metric group (with the lowest minimum viewport width, e.g. for mobile).
226226
*
227-
* This group normally represents viewports for mobile devices. This group always has a minimum viewport width of 0
227+
* This group normally represents viewports for mobile devices. This group always has a minimum viewport width of 0,
228228
* and the maximum viewport width corresponds to the smallest defined breakpoint returned by
229229
* {@see od_get_breakpoint_max_widths()}.
230230
*
@@ -241,7 +241,7 @@ public function get_first_group(): OD_URL_Metric_Group {
241241
*
242242
* This group normally represents viewports for desktop devices. This group always has a minimum viewport width
243243
* defined as one greater than the largest breakpoint returned by {@see od_get_breakpoint_max_widths()}.
244-
* The maximum viewport width of this group is always `null`, or in other words it is unbounded.
244+
* The maximum viewport width of this group is always `null`, or in other words, it is unbounded.
245245
*
246246
* @since 0.7.0
247247
*
@@ -404,7 +404,7 @@ public function is_every_group_populated(): bool {
404404
/**
405405
* Checks whether every group is complete (full sample of non-stale URL Metrics).
406406
*
407-
* Completeness means the full sample size of URL Metrics has been collected,
407+
* Completeness means the full sample size of URL Metrics has been collected;
408408
* none of the collected URL Metrics are stale (with a mismatching ETag or a
409409
* timestamp older than the freshness TTL).
410410
*
@@ -520,9 +520,9 @@ public function get_common_lcp_element(): ?OD_Element {
520520
/**
521521
* Gets all elements from all URL Metrics from all groups keyed by the elements' XPaths.
522522
*
523-
* This is an O(n^3) function so its results must be cached. This being said, the number of groups should be 4 (one
524-
* more than the default number of breakpoints) and the number of URL Metrics for each group should be 3
525-
* (the default sample size). Therefore, given the number (n) of visited elements on the page this will only
523+
* This is an O(n^3) function, so its results must be cached. This being said, the number of groups should be 4 (one
524+
* more than the default number of breakpoints), and the number of URL Metrics for each group should be 3
525+
* (the default sample size). Therefore, given the number (n) of visited elements on the page, this will only
526526
* end up running n*4*3 times.
527527
*
528528
* @since 0.7.0
@@ -584,8 +584,8 @@ public function get_all_element_max_intersection_ratios(): array {
584584
*
585585
* An element is positioned in the initial viewport if its `boundingClientRect.top` is less than the
586586
* `viewport.height` for any of its recorded URL Metrics. Note that even though the element may be positioned in the
587-
* initial viewport, it may not actually be visible. It could be occluded as a latter slide in a carousel in which
588-
* case it will have intersectionRatio of 0. Or the element may not be visible due to it or an ancestor having the
587+
* initial viewport, it may not actually be visible. It could be occluded as a latter slide in a carousel, in which
588+
* case it will have an intersectionRatio of 0. Or the element may not be visible due to it or an ancestor having the
589589
* `visibility:hidden` style, such as in the case of a dropdown navigation menu. When, for example, an IMG element
590590
* is positioned in any initial viewport, it should not get `loading=lazy` but rather `fetchpriority=low`.
591591
* Furthermore, the element may be positioned _above_ the initial viewport or to the left or right of the viewport,
@@ -624,7 +624,7 @@ public function get_all_elements_positioned_in_any_initial_viewport(): array {
624624
* @since 0.3.0
625625
*
626626
* @param string $xpath XPath for the element.
627-
* @return float|null Max intersection ratio of null if tag is unknown (not captured).
627+
* @return float|null Max intersection ratio or null if the tag is unknown (not captured).
628628
*/
629629
public function get_element_max_intersection_ratio( string $xpath ): ?float {
630630
return $this->get_all_element_max_intersection_ratios()[ $xpath ] ?? null;
@@ -636,7 +636,7 @@ public function get_element_max_intersection_ratio( string $xpath ): ?float {
636636
* @since 0.7.0
637637
*
638638
* @param string $xpath XPath for the element.
639-
* @return bool|null Whether element is positioned in any initial viewport of null if unknown.
639+
* @return bool|null Whether an element is positioned in any initial viewport or null if unknown.
640640
*/
641641
public function is_element_positioned_in_any_initial_viewport( string $xpath ): ?bool {
642642
return $this->get_all_elements_positioned_in_any_initial_viewport()[ $xpath ] ?? null;
@@ -651,8 +651,8 @@ public function is_element_positioned_in_any_initial_viewport( string $xpath ):
651651
*/
652652
public function get_flattened_url_metrics(): array {
653653
// The duplication of iterator_to_array is not a mistake. This collection is an
654-
// iterator and the collection contains iterator instances. So to flatten the
655-
// two levels of iterators we need to nest calls to iterator_to_array().
654+
// iterator, and the collection contains iterator instances. So to flatten the
655+
// two levels of iterators, we need to nest calls to iterator_to_array().
656656
return array_merge(
657657
...array_map(
658658
'iterator_to_array',

plugins/optimization-detective/class-od-url-metric-group.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ static function ( OD_URL_Metric $a, OD_URL_Metric $b ): int {
268268
/**
269269
* Determines whether the URL Metric group is complete.
270270
*
271-
* A group is complete if it has the full sample size of URL Metrics
271+
* A group is complete if it has the full sample size of URL Metrics,
272272
* and all of these URL Metrics are fresh (with a current ETag and a
273273
* timestamp that is not older than the freshness TTL).
274274
*
@@ -322,15 +322,15 @@ public function get_lcp_element(): ?OD_Element {
322322

323323
$result = ( function () {
324324

325-
// No metrics have been gathered for this group so there is no LCP element.
325+
// No metrics have been gathered for this group, so there is no LCP element.
326326
if ( count( $this->url_metrics ) === 0 ) {
327327
return null;
328328
}
329329

330330
// The following arrays all share array indices.
331331

332332
/**
333-
* Seen breadcrumbs counts.
333+
* Seen breadcrumb counts.
334334
*
335335
* @var array<int, non-empty-string> $seen_breadcrumbs
336336
*/
@@ -350,7 +350,7 @@ public function get_lcp_element(): ?OD_Element {
350350
*/
351351
$breadcrumb_element = array();
352352

353-
// Prefer to use URL Metrics which have a current ETag.
353+
// Prefer to use URL Metrics, which have a current ETag.
354354
$url_metrics = array_filter(
355355
$this->url_metrics,
356356
function ( OD_URL_Metric $url_metric ): bool {
@@ -459,7 +459,7 @@ public function get_all_element_max_intersection_ratios(): array {
459459
* @since 0.9.0
460460
*
461461
* @param string $xpath XPath for the element.
462-
* @return float|null Max intersection ratio of null if tag is unknown (not captured).
462+
* @return float|null Max intersection ratio or null if the tag is unknown (not captured).
463463
*/
464464
public function get_element_max_intersection_ratio( string $xpath ): ?float {
465465
return $this->get_all_element_max_intersection_ratios()[ $xpath ] ?? null;

plugins/optimization-detective/class-od-url-metric.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ public static function get_json_schema(): array {
208208
)
209209
);
210210

211-
// The spec allows these to be negative but this doesn't make sense in the context of intersectionRect and boundingClientRect.
211+
// The spec allows these to be negative, but this doesn't make sense in the context of intersectionRect and boundingClientRect.
212212
$dom_rect_properties['width']['minimum'] = 0.0;
213213
$dom_rect_properties['height']['minimum'] = 0.0;
214214

@@ -312,9 +312,9 @@ public static function get_json_schema(): array {
312312
),
313313
),
314314
// Additional root properties may be added to the schema via the od_url_metric_schema_root_additional_properties filter.
315-
// Therefore, additionalProperties is set to true so that additional properties defined in the extended schema may persist
315+
// Therefore, `additionalProperties` is set to true so that additional properties defined in the extended schema may persist
316316
// in a stored URL Metric even when the extension is deactivated. For REST API requests, the OD_Strict_URL_Metric
317-
// which sets this to false so that newly-submitted URL Metrics only ever include the known properties.
317+
// which sets this to false so that newly submitted URL Metrics only ever include the known properties.
318318
'additionalProperties' => true,
319319
);
320320

@@ -364,7 +364,7 @@ public static function get_json_schema(): array {
364364
protected static function extend_schema_with_optional_properties( array $properties_schema, array $additional_properties, string $filter_name ): array {
365365
$doing_it_wrong = static function ( string $message ) use ( $filter_name ): void {
366366
_doing_it_wrong(
367-
esc_html( "Filter: '{$filter_name}'" ),
367+
esc_html( "Filter: '$filter_name'" ),
368368
esc_html( $message ),
369369
'Optimization Detective 0.6.0'
370370
);

plugins/optimization-detective/deprecated.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
* @package optimization-detective
66
*
77
* @since 1.0.0
8+
*
9+
* @noinspection PhpUnused
810
*/
911

1012
// @codeCoverageIgnoreStart

plugins/optimization-detective/detect.js

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,14 @@
2727
*/
2828

2929
/**
30-
* Window reference to reduce size when script is minified.
30+
* Window reference to reduce size when the script is minified.
3131
*
3232
* @type {Window}
3333
*/
3434
const win = window;
3535

3636
/**
37-
* Document reference to reduce size when script is minified.
37+
* Document reference to reduce size when the script is minified.
3838
*
3939
* @type {Document}
4040
*/
@@ -184,7 +184,7 @@ function createLogger(
184184
/**
185185
* Attempts to get the extension name (i.e. slug for plugin or theme) from the script module URL.
186186
*
187-
* If extraction of the slug fails then the entire URL is returned.
187+
* If extraction of the slug fails, then the entire URL is returned.
188188
*
189189
* @param {string} scriptModuleUrl - Script module URL.
190190
* @return {string} Derived extension name.
@@ -509,7 +509,7 @@ function debounceCompressUrlMetric() {
509509
*/
510510

511511
/**
512-
* Detects the LCP element, loaded images, client viewport and store for future optimizations.
512+
* Detects the LCP element, loaded images, client viewport, and store for future optimizations.
513513
*
514514
* @param {Object} args - Args.
515515
* @param {string[]} args.extensionModuleUrls - URLs for extension script modules to import.
@@ -669,7 +669,7 @@ export default async function detect( {
669669
return;
670670
}
671671

672-
// Keep track of whether the window resized. If it resized, we abort sending the URLMetric.
672+
// Keep track of whether the window resized. If it was resized, we abort sending the URLMetric.
673673
let didWindowResize = false;
674674
window.addEventListener(
675675
'resize',
@@ -704,10 +704,10 @@ export default async function detect( {
704704
const breadcrumbedElementsMap = new Map(
705705
[ ...breadcrumbedElements ].map(
706706
/**
707-
* @param {HTMLElement} element
708-
* @return {[HTMLElement, string]} Tuple of element and its XPath.
707+
* @param {Element} element
708+
* @return {[Element, string]} Tuple of an element and its XPath.
709709
*/
710-
( element ) => [ element, element.dataset.odXpath ]
710+
( element ) => [ element, element.getAttribute( 'data-od-xpath' ) ]
711711
)
712712
);
713713

@@ -724,7 +724,7 @@ export default async function detect( {
724724
}
725725
}
726726

727-
// Wait for the intersection observer to report back on the initially-visible elements.
727+
// Wait for the intersection observer to report back on the initially visible elements.
728728
// Note that the first callback will include _all_ observed entries per <https://github.com/w3c/IntersectionObserver/issues/476>.
729729
if ( breadcrumbedElementsMap.size > 0 ) {
730730
await new Promise( ( resolve ) => {
@@ -756,7 +756,7 @@ export default async function detect( {
756756
/** @type {(LCPMetric|LCPMetricWithAttribution)[]} */
757757
const lcpMetricCandidates = [];
758758

759-
// Obtain at least one LCP candidate. More may be reported before the page finishes loading.
759+
// Get at least one LCP candidate. More may be reported before the page finishes loading.
760760
await new Promise( ( resolve ) => {
761761
onLCP(
762762
/**
@@ -769,15 +769,15 @@ export default async function detect( {
769769
resolve();
770770
},
771771
{
772-
// This avoids needing to click to finalize LCP candidate. While this is helpful for testing, it also
772+
// This avoids needing to click to finalize the LCP candidate. While this is helpful for testing, it also
773773
// ensures that we always get an LCP candidate reported. Otherwise, the callback may never fire if the
774774
// user never does a click or keydown, per <https://github.com/GoogleChrome/web-vitals/blob/07f6f96/src/onLCP.ts#L99-L107>.
775775
reportAllChanges: true,
776776
}
777777
);
778778
} );
779779

780-
// Stop observing initial viewport.
780+
// Stop observing the initial viewport.
781781
disconnectIntersectionObserver();
782782

783783
urlMetric = {
@@ -936,7 +936,7 @@ export default async function detect( {
936936
);
937937
} );
938938

939-
// Only proceed with submitting the URL Metric if viewport stayed the same size. Changing the viewport size (e.g. due
939+
// Only proceed with submitting the URL Metric if the viewport stayed the same size. Changing the viewport size (e.g. due
940940
// to resizing a window or changing the orientation of a device) will result in unexpected metrics being collected.
941941
if ( didWindowResize ) {
942942
log( 'Aborting URL Metric collection due to viewport size change.' );
@@ -1009,7 +1009,7 @@ export default async function detect( {
10091009
}
10101010

10111011
/*
1012-
* Now prepare the URL Metric to be sent as JSON request body.
1012+
* Now prepare the URL Metric to be sent in the JSON request body.
10131013
*/
10141014

10151015
const maxBodyLengthKiB = 64;

plugins/optimization-detective/detection.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
// @codeCoverageIgnoreEnd
1414

1515
/**
16-
* Obtains the ID for a post related to this response so that page caches can be told to invalidate their cache.
16+
* Gets the ID for a post related to this response so that page caches can be told to invalidate their cache.
1717
*
1818
* If the queried object for the response is a post, then that post's ID is used. Otherwise, it uses the ID of the first
1919
* post in The Loop.
@@ -23,15 +23,15 @@
2323
* this ID if the relevant actions are triggered for the post (e.g. clean_post_cache, save_post, transition_post_status).
2424
*
2525
* Otherwise, if the response is an archive page or the front page where show_on_front=posts (i.e. is_home), then
26-
* there is no singular post object that represents the URL. In this case, we obtain the first post in the main
27-
* loop. By triggering the relevant actions for this post ID, page caches will have their best shot at invalidating
26+
* there is no singular post object that represents the URL. In this case, we get the first post in the main
27+
* loop. By triggering the relevant actions for this post ID, page caches will be more likely able to invalidate
2828
* the related URLs. Page caching plugins which leverage surrogate keys will be the most reliable here. Otherwise,
2929
* caching plugins may just resort to automatically purging the cache for the homepage whenever any post is edited,
3030
* which is better than nothing.
3131
*
3232
* There should not be any situation by default in which a page optimized with Optimization Detective does not have such
3333
* a post available for cache purging. As seen in {@see od_can_optimize_response()}, when such a post ID is not
34-
* available for cache purging then it returns false, as it also does in another case like if is_404().
34+
* available for cache purging, then it returns false, as it also does in another case like if is_404().
3535
*
3636
* @since 0.8.0
3737
* @access private

0 commit comments

Comments
 (0)