Skip to content

Commit a2cff5b

Browse files
committed
HTML API: Adjust code stying to Gutenberg's linter's preferences
1 parent 2fc7435 commit a2cff5b

3 files changed

Lines changed: 36 additions & 24 deletions

File tree

src/wp-includes/html-api/class-wp-html-active-formatting-elements.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ class WP_HTML_Active_Formatting_Elements {
5050
*
5151
* @param WP_HTML_Token $token Look for this node in the stack.
5252
* @return bool Whether the referenced node is in the stack of active formatting elements.
53-
*
5453
*/
5554
public function contains_node( $token ) {
5655
foreach ( $this->walk_up() as $item ) {
@@ -149,7 +148,7 @@ public function remove_node( $token ) {
149148
* > EM -> STRONG -> A ->
150149
*
151150
* To start with the most-recently added element and walk towards the top,
152-
* @see WP_HTML_Active_Formatting_Elements::walk_up
151+
* {@see WP_HTML_Active_Formatting_Elements::walk_up}.
153152
*
154153
* @since 6.4.0
155154
*/
@@ -176,7 +175,7 @@ public function walk_down() {
176175
* > A -> STRONG -> EM ->
177176
*
178177
* To start with the first added element and walk towards the bottom,
179-
* @see WP_HTML_Active_Formatting_Elements::walk_down
178+
* {@see WP_HTML_Active_Formatting_Elements::walk_down}.
180179
*
181180
* @since 6.4.0
182181
*/

src/wp-includes/html-api/class-wp-html-open-elements.php

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ public function current_node() {
110110
* @param string[] $termination_list List of elements that terminate the search.
111111
* @return bool Whether the element was found in a specific scope.
112112
*/
113-
public function has_element_in_specific_scope( $tag_name, $termination_list ) {
113+
public function has_element_in_specific_scope( $tag_name, $termination_list ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
114114
foreach ( $this->walk_up() as $node ) {
115115
if ( $node->node_name === $tag_name ) {
116116
return true;
@@ -134,6 +134,7 @@ public function has_element_in_scope( $tag_name ) {
134134
return $this->has_element_in_specific_scope(
135135
$tag_name,
136136
array(
137+
137138
/*
138139
* Because it's not currently possible to encounter
139140
* one of the termination elements, they don't need
@@ -152,11 +153,15 @@ public function has_element_in_scope( $tag_name ) {
152153
*
153154
* @see https://html.spec.whatwg.org/#has-an-element-in-list-item-scope
154155
*
156+
* @throws WP_HTML_Unsupported_Exception Always until this function is implemented.
157+
*
155158
* @param string $tag_name Name of tag to check.
156159
* @return bool Whether given element is in scope.
157160
*/
158-
public function has_element_in_list_item_scope( $tag_name ) {
161+
public function has_element_in_list_item_scope( $tag_name ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
159162
throw new WP_HTML_Unsupported_Exception( 'Cannot process elements depending on list item scope.' );
163+
164+
return false; // The linter requires this unreachable code until the function is implemented and can return.
160165
}
161166

162167
/**
@@ -173,6 +178,7 @@ public function has_element_in_button_scope( $tag_name ) {
173178
return $this->has_element_in_specific_scope(
174179
$tag_name,
175180
array(
181+
176182
/*
177183
* Because it's not currently possible to encounter
178184
* one of the termination elements, they don't need
@@ -191,11 +197,15 @@ public function has_element_in_button_scope( $tag_name ) {
191197
*
192198
* @see https://html.spec.whatwg.org/#has-an-element-in-table-scope
193199
*
200+
* @throws WP_HTML_Unsupported_Exception Always until this function is implemented.
201+
*
194202
* @param string $tag_name Name of tag to check.
195203
* @return bool Whether given element is in scope.
196204
*/
197-
public function has_element_in_table_scope( $tag_name ) {
205+
public function has_element_in_table_scope( $tag_name ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
198206
throw new WP_HTML_Unsupported_Exception( 'Cannot process elements depending on table scope.' );
207+
208+
return false; // The linter requires this unreachable code until the function is implemented and can return.
199209
}
200210

201211
/**
@@ -205,11 +215,15 @@ public function has_element_in_table_scope( $tag_name ) {
205215
*
206216
* @see https://html.spec.whatwg.org/#has-an-element-in-select-scope
207217
*
218+
* @throws WP_HTML_Unsupported_Exception Always until this function is implemented.
219+
*
208220
* @param string $tag_name Name of tag to check.
209221
* @return bool Whether given element is in scope.
210222
*/
211-
public function has_element_in_select_scope( $tag_name ) {
223+
public function has_element_in_select_scope( $tag_name ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
212224
throw new WP_HTML_Unsupported_Exception( 'Cannot process elements depending on select scope.' );
225+
226+
return false; // The linter requires this unreachable code until the function is implemented and can return.
213227
}
214228

215229
/**
@@ -219,7 +233,7 @@ public function has_element_in_select_scope( $tag_name ) {
219233
*
220234
* @see https://html.spec.whatwg.org/#has-an-element-in-button-scope
221235
*
222-
* @return bool
236+
* @return bool Whether a P is in BUTTON scope.
223237
*/
224238
public function has_p_in_button_scope() {
225239
return $this->has_p_in_button_scope;
@@ -320,7 +334,7 @@ public function remove_node( $token ) {
320334
* > EM -> STRONG -> A ->
321335
*
322336
* To start with the most-recently added element and walk towards the top,
323-
* @see WP_HTML_Open_Elements::walk_up
337+
* {@see WP_HTML_Open_Elements::walk_up}.
324338
*
325339
* @since 6.4.0
326340
*/
@@ -347,7 +361,7 @@ public function walk_down() {
347361
* > A -> STRONG -> EM ->
348362
*
349363
* To start with the first added element and walk towards the bottom,
350-
* @see WP_HTML_Open_Elements::walk_down
364+
* {@see WP_HTML_Open_Elements::walk_down}.
351365
*
352366
* @since 6.4.0
353367
*/

src/wp-includes/html-api/class-wp-html-processor.php

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -232,16 +232,16 @@ class WP_HTML_Processor extends WP_HTML_Tag_Processor {
232232
* @return WP_HTML_Processor|null The created processor if successful, otherwise null.
233233
*/
234234
public static function createFragment( $html, $context = '<body>', $encoding = 'UTF-8' ) {
235-
if ( '<body>' !== $context ) {
235+
if ( '<body>' !== $context || 'UTF-8' !== $encoding ) {
236236
return null;
237237
}
238238

239-
$p = new self( $html, self::CONSTRUCTOR_UNLOCK_CODE );
239+
$p = new self( $html, self::CONSTRUCTOR_UNLOCK_CODE );
240240
$p->state->context_node = array( 'BODY', array() );
241241
$p->state->insertion_mode = WP_HTML_Processor_State::INSERTION_MODE_IN_BODY;
242242

243243
// @TODO: Create "fake" bookmarks for non-existent but implied nodes.
244-
$p->bookmarks['root-node'] = new WP_HTML_Span( 0, 0 );
244+
$p->bookmarks['root-node'] = new WP_HTML_Span( 0, 0 );
245245
$p->bookmarks['context-node'] = new WP_HTML_Span( 0, 0 );
246246

247247
$p->state->stack_of_open_elements->push(
@@ -332,7 +332,7 @@ public function get_last_error() {
332332
*
333333
* @since 6.4.0
334334
*
335-
* @throws WP_HTML_Unsupported_Exception
335+
* @throws Exception When unable to allocate a bookmark for the next token in the input HTML document.
336336
*
337337
* @param array|string|null $query {
338338
* Optional. Which tag name to find, having which class, etc. Default is to find any tag.
@@ -410,7 +410,7 @@ public function next_tag( $query = null ) {
410410
*
411411
* @since 6.4.0
412412
*
413-
* @throws Exception
413+
* @throws Exception When unable to allocate a bookmark for the next token in the input HTML document.
414414
*
415415
* @see self::PROCESS_NEXT_NODE
416416
* @see self::REPROCESS_CURRENT_NODE
@@ -496,7 +496,7 @@ public function get_breadcrumbs() {
496496
*
497497
* @since 6.4.0
498498
*
499-
* @throws WP_HTML_Unsupported_Exception
499+
* @throws WP_HTML_Unsupported_Exception When encountering unsupported HTML input.
500500
*
501501
* @see https://html.spec.whatwg.org/#parsing-main-inbody
502502
* @see self::step
@@ -641,7 +641,7 @@ private function step_in_body() {
641641
*
642642
* @since 6.4.0
643643
*
644-
* @throws Exception
644+
* @throws Exception When unable to allocate requested bookmark.
645645
*
646646
* @return string|false Name of created bookmark, or false if unable to create.
647647
*/
@@ -859,7 +859,7 @@ public function set_bookmark( $bookmark_name ) {
859859
*
860860
* @since 6.4.0
861861
*
862-
* @throws WP_HTML_Unsupported_Exception
862+
* @throws WP_HTML_Unsupported_Exception When encountering unsupported HTML input.
863863
*
864864
* @see https://html.spec.whatwg.org/#close-a-p-element
865865
*/
@@ -873,8 +873,6 @@ private function close_a_p_element() {
873873
*
874874
* @since 6.4.0
875875
*
876-
* @throws Exception
877-
*
878876
* @see https://html.spec.whatwg.org/#generate-implied-end-tags
879877
*
880878
* @param string|null $except_for_this_element Perform as if this element doesn't exist in the stack of open elements.
@@ -902,7 +900,7 @@ private function generate_implied_end_tags( $except_for_this_element = null ) {
902900
*
903901
* @since 6.4.0
904902
*
905-
* @throws WP_HTML_Unsupported_Exception
903+
* @throws WP_HTML_Unsupported_Exception When encountering unsupported HTML input.
906904
*
907905
* @see https://html.spec.whatwg.org/#reconstruct-the-active-formatting-elements
908906
*
@@ -919,6 +917,7 @@ private function reconstruct_active_formatting_elements() {
919917

920918
$last_entry = $this->state->active_formatting_elements->current_node();
921919
if (
920+
922921
/*
923922
* > If the last (most recently added) entry in the list of active formatting elements is a marker;
924923
* > stop this algorithm.
@@ -944,7 +943,7 @@ private function reconstruct_active_formatting_elements() {
944943
*
945944
* @since 6.4.0
946945
*
947-
* @throws WP_HTML_Unsupported_Exception
946+
* @throws WP_HTML_Unsupported_Exception When encountering unsupported HTML input.
948947
*
949948
* @see https://html.spec.whatwg.org/#adoption-agency-algorithm
950949
*/
@@ -1165,15 +1164,15 @@ public static function is_special( $tag_name ) {
11651164
'WBR' === $tag_name ||
11661165
'XMP' === $tag_name ||
11671166

1168-
// MathML
1167+
// MathML.
11691168
'MI' === $tag_name ||
11701169
'MO' === $tag_name ||
11711170
'MN' === $tag_name ||
11721171
'MS' === $tag_name ||
11731172
'MTEXT' === $tag_name ||
11741173
'ANNOTATION-XML' === $tag_name ||
11751174

1176-
// SVG
1175+
// SVG.
11771176
'FOREIGNOBJECT' === $tag_name ||
11781177
'DESC' === $tag_name ||
11791178
'TITLE' === $tag_name

0 commit comments

Comments
 (0)