Skip to content

Commit cb79463

Browse files
authored
Merge pull request #1782 from WordPress/update/od-docs
Improve Optimization Detective documentation
2 parents 1f8265d + 3f62502 commit cb79463

19 files changed

+148
-23
lines changed

plugins/image-prioritizer/readme.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ This plugin optimizes the loading of images (and videos) with prioritization to
1515

1616
The current optimizations include:
1717

18-
1. Add breakpoint-specific `fetchpriority=high` preload links (`LINK[rel=preload]`) for image URLs of LCP elements:
18+
1. Add breakpoint-specific `fetchpriority=high` preload links (both as `LINK[rel=preload]` elements and `Link` response headers) for image URLs of LCP elements:
1919
1. An `IMG` element, including the `srcset`/`sizes` attributes supplied as `imagesrcset`/`imagesizes` on the `LINK`.
2020
2. The first `SOURCE` element with a `type` attribute in a `PICTURE` element. (Art-directed `PICTURE` elements using media queries are not supported.)
2121
3. An element with a CSS `background-image` inline `style` attribute.

plugins/optimization-detective/class-od-data-validation-exception.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,5 @@
1616
* Exception thrown when failing to validate URL Metrics data.
1717
*
1818
* @since 0.1.0
19-
* @access private
2019
*/
2120
final class OD_Data_Validation_Exception extends Exception {}

plugins/optimization-detective/class-od-element.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
* @todo The above implements tag should account for additional undefined keys which can be supplied by extending the element schema. May depend on <https://github.com/phpstan/phpstan/issues/8438>.
2222
*
2323
* @since 0.7.0
24-
* @access private
2524
*/
2625
class OD_Element implements ArrayAccess, JsonSerializable {
2726

plugins/optimization-detective/class-od-html-tag-processor.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
* Extension to WP_HTML_Tag_Processor that supports injecting HTML and obtaining XPath for the current tag.
1717
*
1818
* @since 0.1.1
19-
* @access private
2019
*/
2120
final class OD_HTML_Tag_Processor extends WP_HTML_Tag_Processor {
2221

plugins/optimization-detective/class-od-link-collection.php

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,20 +37,23 @@
3737
*
3838
* @since 0.3.0
3939
* @since 0.4.0 Renamed from OD_Preload_Link_Collection.
40-
* @access private
4140
*/
4241
final class OD_Link_Collection implements Countable {
4342

4443
/**
4544
* Links grouped by rel type.
4645
*
46+
* @since 0.4.0
47+
*
4748
* @var array<string, Link[]>
4849
*/
4950
private $links_by_rel = array();
5051

5152
/**
5253
* Adds link.
5354
*
55+
* @since 0.3.0
56+
*
5457
* @phpstan-param LinkAttributes $attributes
5558
*
5659
* @param array $attributes Attributes.
@@ -111,6 +114,8 @@ public function add_link( array $attributes, ?int $minimum_viewport_width = null
111114
* When two links are identical except for their minimum/maximum widths which are also consecutive, then merge them
112115
* together. Also, add media attributes to the links.
113116
*
117+
* @since 0.4.0
118+
*
114119
* @return LinkAttributes[] Prepared links with adjacent-duplicates merged together and media attributes added.
115120
*/
116121
private function get_prepared_links(): array {
@@ -133,6 +138,8 @@ function ( array $links ): array {
133138
/**
134139
* Merges consecutive links.
135140
*
141+
* @since 0.4.0
142+
*
136143
* @param Link[] $links Links.
137144
* @return LinkAttributes[] Merged consecutive links.
138145
*/
@@ -228,6 +235,8 @@ static function ( array $link ): array {
228235
/**
229236
* Gets the HTML for the link tags.
230237
*
238+
* @since 0.3.0
239+
*
231240
* @return string Link tags HTML.
232241
*/
233242
public function get_html(): string {
@@ -249,6 +258,8 @@ public function get_html(): string {
249258
/**
250259
* Constructs the Link HTTP response header.
251260
*
261+
* @since 0.4.0
262+
*
252263
* @return non-empty-string|null Link HTTP response header, or null if there are none.
253264
*/
254265
public function get_response_header(): ?string {
@@ -302,6 +313,8 @@ static function ( $matches ) {
302313
/**
303314
* Counts the links.
304315
*
316+
* @since 0.3.0
317+
*
305318
* @return non-negative-int Link count.
306319
*/
307320
public function count(): int {

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

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,20 +20,23 @@
2020
* @implements IteratorAggregate<string, TagVisitorCallback>
2121
*
2222
* @since 0.3.0
23-
* @access private
2423
*/
2524
final class OD_Tag_Visitor_Registry implements Countable, IteratorAggregate {
2625

2726
/**
2827
* Visitors.
2928
*
29+
* @since 0.3.0
30+
*
3031
* @var array<non-empty-string, TagVisitorCallback>
3132
*/
3233
private $visitors = array();
3334

3435
/**
3536
* Registers a tag visitor.
3637
*
38+
* @since 0.3.0
39+
*
3740
* @phpstan-param TagVisitorCallback $tag_visitor_callback
3841
*
3942
* @param non-empty-string $id Identifier for the tag visitor.
@@ -46,6 +49,8 @@ public function register( string $id, callable $tag_visitor_callback ): void {
4649
/**
4750
* Determines if a visitor has been registered.
4851
*
52+
* @since 0.3.0
53+
*
4954
* @param non-empty-string $id Identifier for the tag visitor.
5055
* @return bool Whether registered.
5156
*/
@@ -56,6 +61,8 @@ public function is_registered( string $id ): bool {
5661
/**
5762
* Gets a registered visitor.
5863
*
64+
* @since 0.3.0
65+
*
5966
* @param non-empty-string $id Identifier for the tag visitor.
6067
* @return TagVisitorCallback|null Whether registered.
6168
*/
@@ -69,6 +76,8 @@ public function get_registered( string $id ): ?callable {
6976
/**
7077
* Unregisters a tag visitor.
7178
*
79+
* @since 0.3.0
80+
*
7281
* @param non-empty-string $id Identifier for the tag visitor.
7382
* @return bool Whether a tag visitor was unregistered.
7483
*/
@@ -83,6 +92,8 @@ public function unregister( string $id ): bool {
8392
/**
8493
* Returns an iterator for the URL Metrics in the group.
8594
*
95+
* @since 0.3.0
96+
*
8697
* @return ArrayIterator<string, TagVisitorCallback> ArrayIterator for tag visitors.
8798
*/
8899
public function getIterator(): ArrayIterator {
@@ -92,6 +103,8 @@ public function getIterator(): ArrayIterator {
92103
/**
93104
* Counts the URL Metrics in the group.
94105
*
106+
* @since 0.3.0
107+
*
95108
* @return int<0, max> URL Metric count.
96109
*/
97110
public function count(): int {

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
* @implements IteratorAggregate<int, OD_URL_Metric_Group>
1919
*
2020
* @since 0.1.0
21-
* @access private
2221
*/
2322
final class OD_URL_Metric_Group_Collection implements Countable, IteratorAggregate, JsonSerializable {
2423

@@ -31,6 +30,7 @@ final class OD_URL_Metric_Group_Collection implements Countable, IteratorAggrega
3130
* even to when there are zero breakpoints: there will still be one group
3231
* in this case, in which every single URL Metric is added.
3332
*
33+
* @since 0.1.0
3434
* @var OD_URL_Metric_Group[]
3535
* @phpstan-var non-empty-array<OD_URL_Metric_Group>
3636
*/
@@ -54,13 +54,15 @@ final class OD_URL_Metric_Group_Collection implements Countable, IteratorAggrega
5454
* 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
*
57+
* @since 0.1.0
5758
* @var positive-int[]
5859
*/
5960
private $breakpoints;
6061

6162
/**
6263
* Sample size for URL Metrics for a given breakpoint.
6364
*
65+
* @since 0.1.0
6466
* @var int<1, max>
6567
*/
6668
private $sample_size;
@@ -70,13 +72,15 @@ final class OD_URL_Metric_Group_Collection implements Countable, IteratorAggrega
7072
*
7173
* A freshness age of zero means a URL Metric will always be considered stale.
7274
*
75+
* @since 0.1.0
7376
* @var int<0, max>
7477
*/
7578
private $freshness_ttl;
7679

7780
/**
7881
* Result cache.
7982
*
83+
* @since 0.3.0
8084
* @var array{
8185
* get_group_for_viewport_width?: array<int, OD_URL_Metric_Group>,
8286
* is_every_group_populated?: bool,
@@ -94,6 +98,8 @@ final class OD_URL_Metric_Group_Collection implements Countable, IteratorAggrega
9498
/**
9599
* Constructor.
96100
*
101+
* @since 0.1.0
102+
*
97103
* @throws InvalidArgumentException When an invalid argument is supplied.
98104
*
99105
* @phpstan-param positive-int[] $breakpoints

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
* @implements IteratorAggregate<int, OD_URL_Metric>
1919
*
2020
* @since 0.1.0
21-
* @access private
2221
*/
2322
final class OD_URL_Metric_Group implements IteratorAggregate, Countable, JsonSerializable {
2423

@@ -95,6 +94,8 @@ final class OD_URL_Metric_Group implements IteratorAggregate, Countable, JsonSer
9594
*
9695
* This class should never be directly constructed. It should only be constructed by the {@see OD_URL_Metric_Group_Collection::create_groups()}.
9796
*
97+
* @since 0.1.0
98+
*
9899
* @access private
99100
* @throws InvalidArgumentException If arguments are invalid.
100101
*

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,20 +60,21 @@
6060
* }
6161
*
6262
* @since 0.1.0
63-
* @access private
6463
*/
6564
class OD_URL_Metric implements JsonSerializable {
6665

6766
/**
6867
* Data.
6968
*
69+
* @since 0.1.0
7070
* @var Data
7171
*/
7272
protected $data;
7373

7474
/**
7575
* Elements.
7676
*
77+
* @since 0.7.0
7778
* @var OD_Element[]
7879
*/
7980
protected $elements;
@@ -89,6 +90,8 @@ class OD_URL_Metric implements JsonSerializable {
8990
/**
9091
* Constructor.
9192
*
93+
* @since 0.1.0
94+
*
9295
* @phpstan-param Data|array<string, mixed> $data Valid data or invalid data (in which case an exception is thrown).
9396
*
9497
* @throws OD_Data_Validation_Exception When the input is invalid.
@@ -105,6 +108,8 @@ public function __construct( array $data ) {
105108
/**
106109
* Prepares data with validation and sanitization.
107110
*
111+
* @since 0.6.0
112+
*
108113
* @throws OD_Data_Validation_Exception When the input is invalid.
109114
*
110115
* @param array<string, mixed> $data Data to validate.
@@ -350,7 +355,6 @@ public static function get_json_schema(): array {
350355
* @param array<string, mixed> $properties_schema Properties schema to extend.
351356
* @param array<string, mixed> $additional_properties Additional properties.
352357
* @param string $filter_name Filter name used to extend.
353-
*
354358
* @return array<string, mixed> Extended schema.
355359
*/
356360
protected static function extend_schema_with_optional_properties( array $properties_schema, array $additional_properties, string $filter_name ): array {

plugins/optimization-detective/class-od-visited-tag-state.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ final class OD_Visited_Tag_State {
3030

3131
/**
3232
* Constructor.
33+
*
34+
* @since 1.0.0
3335
*/
3436
public function __construct() {
3537
$this->reset();

0 commit comments

Comments
 (0)