From 2cc95ebd586f4a2043b2049907b36035d9d425c4 Mon Sep 17 00:00:00 2001 From: Jon Surrell Date: Fri, 7 Jun 2024 11:23:13 +0200 Subject: [PATCH 01/31] Annotate types in HTML API --- .../html-api/class-wp-html-processor.php | 55 +++++++++---------- .../html-api/class-wp-html-tag-processor.php | 14 ++--- 2 files changed, 34 insertions(+), 35 deletions(-) diff --git a/src/wp-includes/html-api/class-wp-html-processor.php b/src/wp-includes/html-api/class-wp-html-processor.php index 0eb597edcd803..44dd28bb9cf2a 100644 --- a/src/wp-includes/html-api/class-wp-html-processor.php +++ b/src/wp-includes/html-api/class-wp-html-processor.php @@ -157,7 +157,7 @@ class WP_HTML_Processor extends WP_HTML_Tag_Processor { * * @since 6.4.0 * - * @var WP_HTML_Processor_State + * @var ?WP_HTML_Processor_State */ private $state = null; @@ -184,7 +184,7 @@ class WP_HTML_Processor extends WP_HTML_Tag_Processor { * * @since 6.4.0 * - * @var string|null + * @var ?string */ private $last_error = null; @@ -197,7 +197,7 @@ class WP_HTML_Processor extends WP_HTML_Tag_Processor { * * @since 6.4.0 * - * @var closure + * @var ?Closure */ private $release_internal_bookmark_on_destruct = null; @@ -283,7 +283,7 @@ class WP_HTML_Processor extends WP_HTML_Tag_Processor { * @param string $encoding Text encoding of the document; must be default of 'UTF-8'. * @return static|null The created processor if successful, otherwise null. */ - public static function create_fragment( $html, $context = '', $encoding = 'UTF-8' ) { + public static function create_fragment( string $html, string $context = '', string $encoding = 'UTF-8' ) { if ( '' !== $context || 'UTF-8' !== $encoding ) { return null; } @@ -330,7 +330,7 @@ public static function create_fragment( $html, $context = '', $encoding = * @param string $html HTML to process. * @param string|null $use_the_static_create_methods_instead This constructor should not be called manually. */ - public function __construct( $html, $use_the_static_create_methods_instead = null ) { + public function __construct( string $html, ?string $use_the_static_create_methods_instead = null ) { parent::__construct( $html ); if ( self::CONSTRUCTOR_UNLOCK_CODE !== $use_the_static_create_methods_instead ) { @@ -398,7 +398,7 @@ function ( WP_HTML_Token $token ) { * * @return string|null The last error, if one exists, otherwise null. */ - public function get_last_error() { + public function get_last_error(): ?string { return $this->last_error; } @@ -426,7 +426,7 @@ public function get_last_error() { * } * @return bool Whether a tag was matched. */ - public function next_tag( $query = null ) { + public function next_tag( $query = null ): bool { $visit_closers = isset( $query['tag_closers'] ) && 'visit' === $query['tag_closers']; if ( null === $query ) { @@ -512,7 +512,7 @@ public function next_tag( $query = null ) { * * @return bool */ - public function next_token() { + public function next_token(): bool { $this->current_element = null; if ( isset( $this->last_error ) ) { @@ -557,7 +557,6 @@ public function next_token() { return true; } - /** * Indicates if the current tag token is a tag closer. * @@ -620,7 +619,7 @@ private function is_virtual() { * May also contain the wildcard `*` which matches a single element, e.g. `array( 'SECTION', '*' )`. * @return bool Whether the currently-matched tag is found at the given nested structure. */ - public function matches_breadcrumbs( $breadcrumbs ) { + public function matches_breadcrumbs( array $breadcrumbs ): bool { // Everything matches when there are zero constraints. if ( 0 === count( $breadcrumbs ) ) { return true; @@ -669,7 +668,7 @@ public function matches_breadcrumbs( $breadcrumbs ) { * @return bool Whether to expect a closer for the currently-matched node, * or `null` if not matched on any token. */ - public function expects_closer( $node = null ) { + public function expects_closer( ?WP_HTML_Token $node = null ): ?bool { $token_name = $node->node_name ?? $this->get_token_name(); if ( ! isset( $token_name ) ) { return null; @@ -700,7 +699,7 @@ public function expects_closer( $node = null ) { * @param string $node_to_process Whether to parse the next node or reprocess the current node. * @return bool Whether a tag was matched. */ - public function step( $node_to_process = self::PROCESS_NEXT_NODE ) { + public function step( string $node_to_process = self::PROCESS_NEXT_NODE ): bool { // Refuse to proceed if there was a previous error. if ( null !== $this->last_error ) { return false; @@ -786,7 +785,7 @@ public function step( $node_to_process = self::PROCESS_NEXT_NODE ) { * * @return string[]|null Array of tag names representing path to matched node, if matched, otherwise NULL. */ - public function get_breadcrumbs() { + public function get_breadcrumbs(): ?array { $breadcrumbs = array(); foreach ( $this->state->stack_of_open_elements->walk_down() as $stack_item ) { $breadcrumbs[] = $stack_item->node_name; @@ -820,7 +819,7 @@ public function get_breadcrumbs() { * * @return int Nesting-depth of current location in the document. */ - public function get_current_depth() { + public function get_current_depth(): int { return $this->state->stack_of_open_elements->count(); } @@ -839,7 +838,7 @@ public function get_current_depth() { * * @return bool Whether an element was found. */ - private function step_in_body() { + private function step_in_body(): bool { $token_name = $this->get_token_name(); $token_type = $this->get_token_type(); $op_sigil = '#tag' === $token_type ? ( parent::is_tag_closer() ? '-' : '+' ) : ''; @@ -1456,7 +1455,7 @@ private function bookmark_token() { * * @return string|null Name of currently matched tag in input HTML, or `null` if none found. */ - public function get_tag() { + public function get_tag(): ?string { if ( null !== $this->last_error ) { return null; } @@ -1592,7 +1591,7 @@ public function get_token_type() { * @param string $name Name of attribute whose value is requested. * @return string|true|null Value of attribute or `null` if not available. Boolean attributes return `true`. */ - public function get_attribute( $name ) { + public function get_attribute( string $name ) { return $this->is_virtual() ? null : parent::get_attribute( $name ); } @@ -1653,7 +1652,7 @@ public function remove_attribute( $name ) { * @param string $prefix Prefix of requested attribute names. * @return array|null List of attribute names, or `null` when no tag opener is matched. */ - public function get_attribute_names_with_prefix( $prefix ) { + public function get_attribute_names_with_prefix( string $prefix ): ?array { return $this->is_virtual() ? null : parent::get_attribute_names_with_prefix( $prefix ); } @@ -1733,7 +1732,7 @@ public function class_list() { * * @return string */ - public function get_modifiable_text() { + public function get_modifiable_text(): string { return $this->is_virtual() ? '' : parent::get_modifiable_text(); } @@ -1771,7 +1770,7 @@ public function get_comment_type() { * @param string $bookmark_name Name of the bookmark to remove. * @return bool Whether the bookmark already existed before removal. */ - public function release_bookmark( $bookmark_name ) { + public function release_bookmark( string $bookmark_name ): bool { return parent::release_bookmark( "_{$bookmark_name}" ); } @@ -1792,7 +1791,7 @@ public function release_bookmark( $bookmark_name ) { * @param string $bookmark_name Jump to the place in the document identified by this bookmark name. * @return bool Whether the internal cursor was successfully moved to the bookmark's location. */ - public function seek( $bookmark_name ) { + public function seek( string $bookmark_name ): bool { // Flush any pending updates to the document before beginning. $this->get_updated_html(); @@ -1958,7 +1957,7 @@ public function seek( $bookmark_name ) { * @param string $bookmark_name Identifies this particular bookmark. * @return bool Whether the bookmark was successfully created. */ - public function set_bookmark( $bookmark_name ) { + public function set_bookmark( string $bookmark_name ): bool { return parent::set_bookmark( "_{$bookmark_name}" ); } @@ -1970,7 +1969,7 @@ public function set_bookmark( $bookmark_name ) { * @param string $bookmark_name Name to identify a bookmark that potentially exists. * @return bool Whether that bookmark exists. */ - public function has_bookmark( $bookmark_name ) { + public function has_bookmark( string $bookmark_name ): bool { return parent::has_bookmark( "_{$bookmark_name}" ); } @@ -2001,7 +2000,7 @@ private function close_a_p_element() { * * @param string|null $except_for_this_element Perform as if this element doesn't exist in the stack of open elements. */ - private function generate_implied_end_tags( $except_for_this_element = null ) { + private function generate_implied_end_tags( ?string $except_for_this_element = null ) { $elements_with_implied_end_tags = array( 'DD', 'DT', @@ -2057,7 +2056,7 @@ private function generate_implied_end_tags_thoroughly() { * * @return bool Whether any formatting elements needed to be reconstructed. */ - private function reconstruct_active_formatting_elements() { + private function reconstruct_active_formatting_elements(): bool { /* * > If there are no entries in the list of active formatting elements, then there is nothing * > to reconstruct; stop this algorithm. @@ -2209,7 +2208,7 @@ private function run_adoption_agency_algorithm() { * * @param WP_HTML_Token $token Name of bookmark pointing to element in original input HTML. */ - private function insert_html_element( $token ) { + private function insert_html_element( WP_HTML_Token $token ) { $this->state->stack_of_open_elements->push( $token ); } @@ -2227,7 +2226,7 @@ private function insert_html_element( $token ) { * @param string $tag_name Name of element to check. * @return bool Whether the element of the given name is in the special category. */ - public static function is_special( $tag_name ) { + public static function is_special( string $tag_name ): bool { $tag_name = strtoupper( $tag_name ); return ( @@ -2342,7 +2341,7 @@ public static function is_special( $tag_name ) { * @param string $tag_name Name of HTML tag to check. * @return bool Whether the given tag is an HTML Void Element. */ - public static function is_void( $tag_name ) { + public static function is_void( string $tag_name ): bool { $tag_name = strtoupper( $tag_name ); return ( diff --git a/src/wp-includes/html-api/class-wp-html-tag-processor.php b/src/wp-includes/html-api/class-wp-html-tag-processor.php index 8fc75938c9384..d73c692ebe46f 100644 --- a/src/wp-includes/html-api/class-wp-html-tag-processor.php +++ b/src/wp-includes/html-api/class-wp-html-tag-processor.php @@ -1209,7 +1209,7 @@ public function has_class( $wanted_class ) { * @param string $name Identifies this particular bookmark. * @return bool Whether the bookmark was successfully created. */ - public function set_bookmark( $name ) { + public function set_bookmark( string $name ): bool { // It only makes sense to set a bookmark if the parser has paused on a concrete token. if ( self::STATE_COMPLETE === $this->parser_state || @@ -1242,7 +1242,7 @@ public function set_bookmark( $name ) { * @param string $name Name of the bookmark to remove. * @return bool Whether the bookmark already existed before removal. */ - public function release_bookmark( $name ) { + public function release_bookmark( string $name ): bool { if ( ! array_key_exists( $name, $this->bookmarks ) ) { return false; } @@ -2362,7 +2362,7 @@ private function apply_attributes_updates( $shift_this_point ) { * @param string $bookmark_name Name to identify a bookmark that potentially exists. * @return bool Whether that bookmark exists. */ - public function has_bookmark( $bookmark_name ) { + public function has_bookmark( string $bookmark_name ): bool { return array_key_exists( $bookmark_name, $this->bookmarks ); } @@ -2377,7 +2377,7 @@ public function has_bookmark( $bookmark_name ) { * @param string $bookmark_name Jump to the place in the document identified by this bookmark name. * @return bool Whether the internal cursor was successfully moved to the bookmark's location. */ - public function seek( $bookmark_name ) { + public function seek( string $bookmark_name ): bool { if ( ! array_key_exists( $bookmark_name, $this->bookmarks ) ) { _doing_it_wrong( __METHOD__, @@ -2517,7 +2517,7 @@ private function get_enqueued_attribute_value( $comparable_name ) { * @param string $name Name of attribute whose value is requested. * @return string|true|null Value of attribute or `null` if not available. Boolean attributes return `true`. */ - public function get_attribute( $name ) { + public function get_attribute( string $name ) { if ( self::STATE_MATCHED_TAG !== $this->parser_state ) { return null; } @@ -2597,7 +2597,7 @@ public function get_attribute( $name ) { * @param string $prefix Prefix of requested attribute names. * @return array|null List of attribute names, or `null` when no tag opener is matched. */ - public function get_attribute_names_with_prefix( $prefix ) { + public function get_attribute_names_with_prefix( string $prefix ): ?array { if ( self::STATE_MATCHED_TAG !== $this->parser_state || $this->is_closing_tag @@ -2838,7 +2838,7 @@ public function get_comment_type() { * * @return string */ - public function get_modifiable_text() { + public function get_modifiable_text(): string { if ( null === $this->text_starts_at ) { return ''; } From a93e8645f785e5e9e6e20ce9f96836c6de6478ea Mon Sep 17 00:00:00 2001 From: Jon Surrell Date: Fri, 7 Jun 2024 11:31:09 +0200 Subject: [PATCH 02/31] Annotated decoder types --- src/wp-includes/html-api/class-wp-html-decoder.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/wp-includes/html-api/class-wp-html-decoder.php b/src/wp-includes/html-api/class-wp-html-decoder.php index 78976002b4a93..ba6d85dc6d687 100644 --- a/src/wp-includes/html-api/class-wp-html-decoder.php +++ b/src/wp-includes/html-api/class-wp-html-decoder.php @@ -31,7 +31,7 @@ class WP_HTML_Decoder { * Default 'case-sensitive'. * @return bool Whether the attribute value starts with the given string. */ - public static function attribute_starts_with( $haystack, $search_text, $case_sensitivity = 'case-sensitive' ) { + public static function attribute_starts_with( string $haystack, string $search_text, string $case_sensitivity = 'case-sensitive' ): bool { $search_length = strlen( $search_text ); $loose_case = 'ascii-case-insensitive' === $case_sensitivity; $haystack_end = strlen( $haystack ); @@ -90,7 +90,7 @@ public static function attribute_starts_with( $haystack, $search_text, $case_sen * @param string $text Text containing raw and non-decoded text node to decode. * @return string Decoded UTF-8 value of given text node. */ - public static function decode_text_node( $text ) { + public static function decode_text_node( string $text ): string { return static::decode( 'data', $text ); } @@ -110,7 +110,7 @@ public static function decode_text_node( $text ) { * @param string $text Text containing raw and non-decoded attribute value to decode. * @return string Decoded UTF-8 value of given attribute value. */ - public static function decode_attribute( $text ) { + public static function decode_attribute( string $text ): string { return static::decode( 'attribute', $text ); } @@ -133,7 +133,7 @@ public static function decode_attribute( $text ) { * @param string $text Text document containing span of text to decode. * @return string Decoded UTF-8 string. */ - public static function decode( $context, $text ) { + public static function decode( string $context, string $text ): string { $decoded = ''; $end = strlen( $text ); $at = 0; @@ -203,7 +203,7 @@ public static function decode( $context, $text ) { * is found, otherwise not set. Default null. * @return string|false Decoded character reference in UTF-8 if found, otherwise `false`. */ - public static function read_character_reference( $context, $text, $at = 0, &$match_byte_length = null ) { + public static function read_character_reference( string $context, string $text, int $at = 0, &$match_byte_length = null ) { /** * Mappings for HTML5 named character references. * @@ -421,7 +421,7 @@ public static function read_character_reference( $context, $text, $at = 0, &$mat * @param int $code_point Which code point to convert. * @return string Converted code point, or `�` if invalid. */ - public static function code_point_to_utf8_bytes( $code_point ) { + public static function code_point_to_utf8_bytes( int $code_point ): string { // Pre-check to ensure a valid code point. if ( $code_point <= 0 || From a598c3fb75e96086bcfaf223a2fcca7eaf754f33 Mon Sep 17 00:00:00 2001 From: Jon Surrell Date: Fri, 7 Jun 2024 11:38:16 +0200 Subject: [PATCH 03/31] Annotate WP_HTML_Open_Elements --- .../html-api/class-wp-html-open-elements.php | 38 +++++++++---------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/src/wp-includes/html-api/class-wp-html-open-elements.php b/src/wp-includes/html-api/class-wp-html-open-elements.php index 7f148a7af7068..cdb91d99e0264 100644 --- a/src/wp-includes/html-api/class-wp-html-open-elements.php +++ b/src/wp-includes/html-api/class-wp-html-open-elements.php @@ -58,7 +58,7 @@ class WP_HTML_Open_Elements { * * @since 6.6.0 * - * @var Closure + * @var ?Closure */ private $pop_handler = null; @@ -69,7 +69,7 @@ class WP_HTML_Open_Elements { * * @since 6.6.0 * - * @var Closure + * @var ?Closure */ private $push_handler = null; @@ -109,7 +109,7 @@ public function set_push_handler( Closure $handler ) { * @param WP_HTML_Token $token Look for this node in the stack. * @return bool Whether the referenced node is in the stack of open elements. */ - public function contains_node( $token ) { + public function contains_node( WP_HTML_Token $token ): bool { foreach ( $this->walk_up() as $item ) { if ( $token->bookmark_name === $item->bookmark_name ) { return true; @@ -126,7 +126,7 @@ public function contains_node( $token ) { * * @return int How many node are in the stack of open elements. */ - public function count() { + public function count(): int { return count( $this->stack ); } @@ -138,7 +138,7 @@ public function count() { * * @return WP_HTML_Token|null Last node in the stack of open elements, if one exists, otherwise null. */ - public function current_node() { + public function current_node(): ?WP_HTML_Token { $current_node = end( $this->stack ); return $current_node ? $current_node : null; @@ -160,7 +160,7 @@ public function current_node() { * @param string[] $termination_list List of elements that terminate the search. * @return bool Whether the element was found in a specific scope. */ - public function has_element_in_specific_scope( $tag_name, $termination_list ) { + public function has_element_in_specific_scope( string $tag_name, $termination_list ): bool { foreach ( $this->walk_up() as $node ) { if ( $node->node_name === $tag_name ) { return true; @@ -196,7 +196,7 @@ public function has_element_in_specific_scope( $tag_name, $termination_list ) { * @param string $tag_name Name of tag to check. * @return bool Whether given element is in scope. */ - public function has_element_in_scope( $tag_name ) { + public function has_element_in_scope( string $tag_name ): bool { return $this->has_element_in_specific_scope( $tag_name, array( @@ -223,7 +223,7 @@ public function has_element_in_scope( $tag_name ) { * @param string $tag_name Name of tag to check. * @return bool Whether given element is in scope. */ - public function has_element_in_list_item_scope( $tag_name ) { + public function has_element_in_list_item_scope( string $tag_name ): bool { return $this->has_element_in_specific_scope( $tag_name, array( @@ -244,7 +244,7 @@ public function has_element_in_list_item_scope( $tag_name ) { * @param string $tag_name Name of tag to check. * @return bool Whether given element is in scope. */ - public function has_element_in_button_scope( $tag_name ) { + public function has_element_in_button_scope( string $tag_name ): bool { return $this->has_element_in_specific_scope( $tag_name, array( 'BUTTON' ) ); } @@ -260,7 +260,7 @@ public function has_element_in_button_scope( $tag_name ) { * @param string $tag_name Name of tag to check. * @return bool Whether given element is in scope. */ - public function has_element_in_table_scope( $tag_name ) { + public function has_element_in_table_scope( string $tag_name ): bool { throw new WP_HTML_Unsupported_Exception( 'Cannot process elements depending on table scope.' ); return false; // The linter requires this unreachable code until the function is implemented and can return. @@ -278,7 +278,7 @@ public function has_element_in_table_scope( $tag_name ) { * @param string $tag_name Name of tag to check. * @return bool Whether given element is in scope. */ - public function has_element_in_select_scope( $tag_name ) { + public function has_element_in_select_scope( string $tag_name ): bool { throw new WP_HTML_Unsupported_Exception( 'Cannot process elements depending on select scope.' ); return false; // The linter requires this unreachable code until the function is implemented and can return. @@ -293,7 +293,7 @@ public function has_element_in_select_scope( $tag_name ) { * * @return bool Whether a P is in BUTTON scope. */ - public function has_p_in_button_scope() { + public function has_p_in_button_scope(): bool { return $this->has_p_in_button_scope; } @@ -306,7 +306,7 @@ public function has_p_in_button_scope() { * * @return bool Whether a node was popped off of the stack. */ - public function pop() { + public function pop(): bool { $item = array_pop( $this->stack ); if ( null === $item ) { @@ -327,7 +327,7 @@ public function pop() { * @param string $tag_name Name of tag that needs to be popped off of the stack of open elements. * @return bool Whether a tag of the given name was found and popped off of the stack of open elements. */ - public function pop_until( $tag_name ) { + public function pop_until( string $tag_name ): bool { foreach ( $this->walk_up() as $item ) { $this->pop(); @@ -355,7 +355,7 @@ public function pop_until( $tag_name ) { * * @param WP_HTML_Token $stack_item Item to add onto stack. */ - public function push( $stack_item ) { + public function push( WP_HTML_Token $stack_item ) { $this->stack[] = $stack_item; $this->after_element_push( $stack_item ); } @@ -368,7 +368,7 @@ public function push( $stack_item ) { * @param WP_HTML_Token $token The node to remove from the stack of open elements. * @return bool Whether the node was found and removed from the stack of open elements. */ - public function remove_node( $token ) { + public function remove_node( WP_HTML_Token $token ): bool { foreach ( $this->walk_up() as $position_from_end => $item ) { if ( $token->bookmark_name !== $item->bookmark_name ) { continue; @@ -433,7 +433,7 @@ public function walk_down() { * * @param ?WP_HTML_Token $above_this_node Start traversing above this node, if provided and if the node exists. */ - public function walk_up( $above_this_node = null ) { + public function walk_up( ?WP_HTML_Token $above_this_node = null ) { $has_found_node = null === $above_this_node; for ( $i = count( $this->stack ) - 1; $i >= 0; $i-- ) { @@ -465,7 +465,7 @@ public function walk_up( $above_this_node = null ) { * * @param WP_HTML_Token $item Element that was added to the stack of open elements. */ - public function after_element_push( $item ) { + public function after_element_push( WP_HTML_Token $item ) { /* * When adding support for new elements, expand this switch to trap * cases where the precalculated value needs to change. @@ -498,7 +498,7 @@ public function after_element_push( $item ) { * * @param WP_HTML_Token $item Element that was removed from the stack of open elements. */ - public function after_element_pop( $item ) { + public function after_element_pop( WP_HTML_Token $item ) { /* * When adding support for new elements, expand this switch to trap * cases where the precalculated value needs to change. From c93b9a15e4bcf05e9e94e45575a495d8a3e66306 Mon Sep 17 00:00:00 2001 From: Jon Surrell Date: Fri, 7 Jun 2024 11:40:47 +0200 Subject: [PATCH 04/31] Annotate WP_Token_Map --- src/wp-includes/class-wp-token-map.php | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/wp-includes/class-wp-token-map.php b/src/wp-includes/class-wp-token-map.php index a932f4cae4d27..705f3b1993209 100644 --- a/src/wp-includes/class-wp-token-map.php +++ b/src/wp-includes/class-wp-token-map.php @@ -280,7 +280,7 @@ class WP_Token_Map { * * @return WP_Token_Map|null Token map, unless unable to create it. */ - public static function from_array( $mappings, $key_length = 2 ) { + public static function from_array( array $mappings, int $key_length = 2 ): ?WP_Token_Map { $map = new WP_Token_Map(); $map->key_length = $key_length; @@ -385,7 +385,7 @@ static function ( $a, $b ) { * * @return WP_Token_Map Map with precomputed data loaded. */ - public static function from_precomputed_table( $state ) { + public static function from_precomputed_table( $state ): ?WP_Token_Map { $has_necessary_state = isset( $state['storage_version'], $state['key_length'], @@ -439,7 +439,7 @@ public static function from_precomputed_table( $state ) { * @param string $case_sensitivity Optional. Pass 'ascii-case-insensitive' to ignore ASCII case when matching. Default 'case-sensitive'. * @return bool Whether there's an entry for the given word in the map. */ - public function contains( $word, $case_sensitivity = 'case-sensitive' ) { + public function contains( string $word, string $case_sensitivity = 'case-sensitive' ): bool { $ignore_case = 'ascii-case-insensitive' === $case_sensitivity; if ( $this->key_length >= strlen( $word ) ) { @@ -526,7 +526,7 @@ public function contains( $word, $case_sensitivity = 'case-sensitive' ) { * @param string $case_sensitivity Optional. Pass 'ascii-case-insensitive' to ignore ASCII case when matching. Default 'case-sensitive'. * @return string|null Mapped value of lookup key if found, otherwise `null`. */ - public function read_token( $text, $offset = 0, &$matched_token_byte_length = null, $case_sensitivity = 'case-sensitive' ) { + public function read_token( string $text, int $offset = 0, &$matched_token_byte_length = null, $case_sensitivity = 'case-sensitive' ): ?string { $ignore_case = 'ascii-case-insensitive' === $case_sensitivity; $text_length = strlen( $text ); @@ -578,7 +578,7 @@ public function read_token( $text, $offset = 0, &$matched_token_byte_length = nu * @param string $case_sensitivity Optional. Pass 'ascii-case-insensitive' to ignore ASCII case when matching. Default 'case-sensitive'. * @return string|null Mapped value of lookup key if found, otherwise `null`. */ - private function read_small_token( $text, $offset, &$matched_token_byte_length, $case_sensitivity = 'case-sensitive' ) { + private function read_small_token( string $text, int $offset, &$matched_token_byte_length, $case_sensitivity = 'case-sensitive' ): ?string { $ignore_case = 'ascii-case-insensitive' === $case_sensitivity; $small_length = strlen( $this->small_words ); $search_text = substr( $text, $offset, $this->key_length ); @@ -633,7 +633,7 @@ private function read_small_token( $text, $offset, &$matched_token_byte_length, * * @return array The lookup key/substitution values as an associate array. */ - public function to_array() { + public function to_array(): array { $tokens = array(); $at = 0; @@ -695,7 +695,7 @@ public function to_array() { * @param string $indent Optional. Use this string for indentation, or rely on the default horizontal tab character. Default "\t". * @return string Value which can be pasted into a PHP source file for quick loading of table. */ - public function precomputed_php_source_table( $indent = "\t" ) { + public function precomputed_php_source_table( string $indent = "\t" ): string { $i1 = $indent; $i2 = $i1 . $indent; $i3 = $i2 . $indent; @@ -800,7 +800,7 @@ static function ( $match_result ) { * @param string $b Second string to compare. * @return int -1 or lower if `$a` is less than `$b`; 1 or greater if `$a` is greater than `$b`, and 0 if they are equal. */ - private static function longest_first_then_alphabetical( $a, $b ) { + private static function longest_first_then_alphabetical( string $a, string $b ): int { if ( $a === $b ) { return 0; } From 6553703ce9d2ca17b6a585cd2035bb93412898c9 Mon Sep 17 00:00:00 2001 From: Jon Surrell Date: Fri, 7 Jun 2024 11:39:26 +0200 Subject: [PATCH 05/31] Add default arguments to read_small_token --- src/wp-includes/class-wp-token-map.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wp-includes/class-wp-token-map.php b/src/wp-includes/class-wp-token-map.php index 705f3b1993209..17c485e5abef3 100644 --- a/src/wp-includes/class-wp-token-map.php +++ b/src/wp-includes/class-wp-token-map.php @@ -578,7 +578,7 @@ public function read_token( string $text, int $offset = 0, &$matched_token_byte_ * @param string $case_sensitivity Optional. Pass 'ascii-case-insensitive' to ignore ASCII case when matching. Default 'case-sensitive'. * @return string|null Mapped value of lookup key if found, otherwise `null`. */ - private function read_small_token( string $text, int $offset, &$matched_token_byte_length, $case_sensitivity = 'case-sensitive' ): ?string { + private function read_small_token( string $text, int $offset = 0, &$matched_token_byte_length = null, $case_sensitivity = 'case-sensitive' ): ?string { $ignore_case = 'ascii-case-insensitive' === $case_sensitivity; $small_length = strlen( $this->small_words ); $search_text = substr( $text, $offset, $this->key_length ); From 065bb1baa8b66da9e9d1e118995e19a50746a418 Mon Sep 17 00:00:00 2001 From: Jon Surrell Date: Fri, 7 Jun 2024 11:45:25 +0200 Subject: [PATCH 06/31] Remove default null value for state properties set in constructor These properties should not be null, their types indicate non-null. They are set in the constructor. --- src/wp-includes/html-api/class-wp-html-processor-state.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/wp-includes/html-api/class-wp-html-processor-state.php b/src/wp-includes/html-api/class-wp-html-processor-state.php index 9cf10c344107a..2ec901d5593f1 100644 --- a/src/wp-includes/html-api/class-wp-html-processor-state.php +++ b/src/wp-includes/html-api/class-wp-html-processor-state.php @@ -70,7 +70,7 @@ class WP_HTML_Processor_State { * * @var WP_HTML_Open_Elements */ - public $stack_of_open_elements = null; + public $stack_of_open_elements; /** * Tracks open formatting elements, used to handle mis-nested formatting element tags. @@ -83,7 +83,7 @@ class WP_HTML_Processor_State { * * @var WP_HTML_Active_Formatting_Elements */ - public $active_formatting_elements = null; + public $active_formatting_elements; /** * Refers to the currently-matched tag, if any. From b0faf2718af0fd7d20e66e8c8c068e788d3fad94 Mon Sep 17 00:00:00 2001 From: Jon Surrell Date: Fri, 7 Jun 2024 11:45:35 +0200 Subject: [PATCH 07/31] Annotate span types --- src/wp-includes/html-api/class-wp-html-span.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wp-includes/html-api/class-wp-html-span.php b/src/wp-includes/html-api/class-wp-html-span.php index b1ab865af3bed..04a1d5258c904 100644 --- a/src/wp-includes/html-api/class-wp-html-span.php +++ b/src/wp-includes/html-api/class-wp-html-span.php @@ -49,7 +49,7 @@ class WP_HTML_Span { * @param int $start Byte offset into document where replacement span begins. * @param int $length Byte length of span. */ - public function __construct( $start, $length ) { + public function __construct( int $start, int $length ) { $this->start = $start; $this->length = $length; } From 611e58b4918ab66c60bd054fcab6eb8f4b3fbc79 Mon Sep 17 00:00:00 2001 From: Jon Surrell Date: Fri, 7 Jun 2024 11:46:45 +0200 Subject: [PATCH 08/31] Remove nullable and default null from WP_HTML_Processor state This property is not nullable. It should always be defined. --- src/wp-includes/html-api/class-wp-html-processor.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/wp-includes/html-api/class-wp-html-processor.php b/src/wp-includes/html-api/class-wp-html-processor.php index 44dd28bb9cf2a..9d3dd0202e41e 100644 --- a/src/wp-includes/html-api/class-wp-html-processor.php +++ b/src/wp-includes/html-api/class-wp-html-processor.php @@ -157,9 +157,9 @@ class WP_HTML_Processor extends WP_HTML_Tag_Processor { * * @since 6.4.0 * - * @var ?WP_HTML_Processor_State + * @var WP_HTML_Processor_State */ - private $state = null; + private $state; /** * Used to create unique bookmark names. From 4e05ec0e82e29ca3a0d3ff9279c17e81d98cb10e Mon Sep 17 00:00:00 2001 From: Jon Surrell Date: Fri, 7 Jun 2024 11:53:11 +0200 Subject: [PATCH 09/31] Annotate stack event class --- src/wp-includes/html-api/class-wp-html-stack-event.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wp-includes/html-api/class-wp-html-stack-event.php b/src/wp-includes/html-api/class-wp-html-stack-event.php index aa4763cd399fc..dcb3c79ef1003 100644 --- a/src/wp-includes/html-api/class-wp-html-stack-event.php +++ b/src/wp-includes/html-api/class-wp-html-stack-event.php @@ -74,7 +74,7 @@ class WP_HTML_Stack_Event { * @param string $operation One of self::PUSH or self::POP. * @param string $provenance "virtual" or "real". */ - public function __construct( $token, $operation, $provenance ) { + public function __construct( WP_HTML_Token $token, string $operation, string $provenance ) { $this->token = $token; $this->operation = $operation; $this->provenance = $provenance; From 9f96827f282a71e7ff3033e1ead210cf89c35667 Mon Sep 17 00:00:00 2001 From: Jon Surrell Date: Fri, 7 Jun 2024 11:53:21 +0200 Subject: [PATCH 10/31] Annotate tag processor class --- .../html-api/class-wp-html-tag-processor.php | 54 +++++++++---------- 1 file changed, 27 insertions(+), 27 deletions(-) diff --git a/src/wp-includes/html-api/class-wp-html-tag-processor.php b/src/wp-includes/html-api/class-wp-html-tag-processor.php index d73c692ebe46f..9e00a80cedb43 100644 --- a/src/wp-includes/html-api/class-wp-html-tag-processor.php +++ b/src/wp-includes/html-api/class-wp-html-tag-processor.php @@ -762,7 +762,7 @@ class WP_HTML_Tag_Processor { * * @param string $html HTML to process. */ - public function __construct( $html ) { + public function __construct( string $html ) { $this->html = $html; } @@ -784,7 +784,7 @@ public function __construct( $html ) { * } * @return bool Whether a tag was matched. */ - public function next_tag( $query = null ) { + public function next_tag( $query = null ): bool { $this->parse_query( $query ); $already_found = 0; @@ -832,7 +832,7 @@ public function next_tag( $query = null ) { * * @return bool Whether a token was parsed. */ - public function next_token() { + public function next_token(): bool { return $this->base_class_next_token(); } @@ -851,7 +851,7 @@ public function next_token() { * * @return bool Whether a token was parsed. */ - private function base_class_next_token() { + private function base_class_next_token(): bool { $was_at = $this->bytes_already_parsed; $this->after_tag(); @@ -1033,7 +1033,7 @@ private function base_class_next_token() { * * @return bool Whether the parse paused at the start of an incomplete token. */ - public function paused_at_incomplete_token() { + public function paused_at_incomplete_token(): bool { return self::STATE_INCOMPLETE_INPUT === $this->parser_state; } @@ -1112,7 +1112,7 @@ public function class_list() { * @param string $wanted_class Look for this CSS class name, ASCII case-insensitive. * @return bool|null Whether the matched tag contains the given class name, or null if not matched. */ - public function has_class( $wanted_class ) { + public function has_class( string $wanted_class ): ?bool { if ( self::STATE_MATCHED_TAG !== $this->parser_state ) { return null; } @@ -1262,7 +1262,7 @@ public function release_bookmark( string $name ): bool { * @param string $tag_name The uppercase tag name which will close the RAWTEXT region. * @return bool Whether an end to the RAWTEXT region was found before the end of the document. */ - private function skip_rawtext( $tag_name ) { + private function skip_rawtext( string $tag_name ): bool { /* * These two functions distinguish themselves on whether character references are * decoded, and since functionality to read the inner markup isn't supported, it's @@ -1281,7 +1281,7 @@ private function skip_rawtext( $tag_name ) { * @param string $tag_name The uppercase tag name which will close the RCDATA region. * @return bool Whether an end to the RCDATA region was found before the end of the document. */ - private function skip_rcdata( $tag_name ) { + private function skip_rcdata( string $tag_name ): bool { $html = $this->html; $doc_length = strlen( $html ); $tag_length = strlen( $tag_name ); @@ -1369,7 +1369,7 @@ private function skip_rcdata( $tag_name ) { * * @return bool Whether the script tag was closed before the end of the document. */ - private function skip_script_data() { + private function skip_script_data(): bool { $state = 'unescaped'; $html = $this->html; $doc_length = strlen( $html ); @@ -1516,7 +1516,7 @@ private function skip_script_data() { * * @return bool Whether a tag was found before the end of the document. */ - private function parse_next_tag() { + private function parse_next_tag(): bool { $this->after_tag(); $html = $this->html; @@ -1921,7 +1921,7 @@ private function parse_next_tag() { * * @return bool Whether an attribute was found before the end of the document. */ - private function parse_next_attribute() { + private function parse_next_attribute(): bool { // Skip whitespace and slashes. $this->bytes_already_parsed += strspn( $this->html, " \t\f\r\n/", $this->bytes_already_parsed ); if ( $this->bytes_already_parsed >= strlen( $this->html ) ) { @@ -2265,7 +2265,7 @@ private function class_name_updates_to_attributes_updates() { * @param int $shift_this_point Accumulate and return shift for this position. * @return int How many bytes the given pointer moved in response to the updates. */ - private function apply_attributes_updates( $shift_this_point ) { + private function apply_attributes_updates( int $shift_this_point ): int { if ( ! count( $this->lexical_updates ) ) { return 0; } @@ -2414,7 +2414,7 @@ public function seek( string $bookmark_name ): bool { * @param WP_HTML_Text_Replacement $b Second attribute update. * @return int Comparison value for string order. */ - private static function sort_start_ascending( $a, $b ) { + private static function sort_start_ascending( WP_HTML_Text_Replacement $a, WP_HTML_Text_Replacement $b ): int { $by_start = $a->start - $b->start; if ( 0 !== $by_start ) { return $by_start; @@ -2446,7 +2446,7 @@ private static function sort_start_ascending( $a, $b ) { * @param string $comparable_name The attribute name in its comparable form. * @return string|boolean|null Value of enqueued update if present, otherwise false. */ - private function get_enqueued_attribute_value( $comparable_name ) { + private function get_enqueued_attribute_value( string $comparable_name ) { if ( self::STATE_MATCHED_TAG !== $this->parser_state ) { return false; } @@ -2632,7 +2632,7 @@ public function get_attribute_names_with_prefix( string $prefix ): ?array { * * @return string|null Name of currently matched tag in input HTML, or `null` if none found. */ - public function get_tag() { + public function get_tag(): ?string { if ( null === $this->tag_name_starts_at ) { return null; } @@ -2670,7 +2670,7 @@ public function get_tag() { * * @return bool Whether the currently matched tag contains the self-closing flag. */ - public function has_self_closing_flag() { + public function has_self_closing_flag(): bool { if ( self::STATE_MATCHED_TAG !== $this->parser_state ) { return false; } @@ -2702,7 +2702,7 @@ public function has_self_closing_flag() { * * @return bool Whether the current tag is a tag closer. */ - public function is_tag_closer() { + public function is_tag_closer(): bool { return ( self::STATE_MATCHED_TAG === $this->parser_state && $this->is_closing_tag @@ -2731,7 +2731,7 @@ public function is_tag_closer() { * * @return string|null What kind of token is matched, or null. */ - public function get_token_type() { + public function get_token_type(): ?string { switch ( $this->parser_state ) { case self::STATE_MATCHED_TAG: return '#tag'; @@ -2764,7 +2764,7 @@ public function get_token_type() { * * @return string|null Name of the matched token. */ - public function get_token_name() { + public function get_token_name(): ?string { switch ( $this->parser_state ) { case self::STATE_MATCHED_TAG: return $this->get_tag(); @@ -2810,7 +2810,7 @@ public function get_token_name() { * * @return string|null */ - public function get_comment_type() { + public function get_comment_type(): ?string { if ( self::STATE_COMMENT !== $this->parser_state ) { return null; } @@ -2908,7 +2908,7 @@ public function get_modifiable_text(): string { * @param string|bool $value The new attribute value. * @return bool Whether an attribute value was set. */ - public function set_attribute( $name, $value ) { + public function set_attribute( string $name, $value ): bool { if ( self::STATE_MATCHED_TAG !== $this->parser_state || $this->is_closing_tag @@ -3051,7 +3051,7 @@ public function set_attribute( $name, $value ) { * @param string $name The attribute name to remove. * @return bool Whether an attribute was removed. */ - public function remove_attribute( $name ) { + public function remove_attribute( string $name ): bool { if ( self::STATE_MATCHED_TAG !== $this->parser_state || $this->is_closing_tag @@ -3131,7 +3131,7 @@ public function remove_attribute( $name ) { * @param string $class_name The class name to add. * @return bool Whether the class was set to be added. */ - public function add_class( $class_name ) { + public function add_class( string $class_name ): bool { if ( self::STATE_MATCHED_TAG !== $this->parser_state || $this->is_closing_tag @@ -3152,7 +3152,7 @@ public function add_class( $class_name ) { * @param string $class_name The class name to remove. * @return bool Whether the class was set to be removed. */ - public function remove_class( $class_name ) { + public function remove_class( string $class_name ): bool { if ( self::STATE_MATCHED_TAG !== $this->parser_state || $this->is_closing_tag @@ -3176,7 +3176,7 @@ public function remove_class( $class_name ) { * * @return string The processed HTML. */ - public function __toString() { + public function __toString(): string { return $this->get_updated_html(); } @@ -3189,7 +3189,7 @@ public function __toString() { * * @return string The processed HTML. */ - public function get_updated_html() { + public function get_updated_html(): string { $requires_no_updating = 0 === count( $this->classname_updates ) && 0 === count( $this->lexical_updates ); /* @@ -3311,7 +3311,7 @@ private function parse_query( $query ) { * * @return bool Whether the given tag and its attribute match the search criteria. */ - private function matches() { + private function matches(): bool { if ( $this->is_closing_tag && ! $this->stop_on_tag_closers ) { return false; } From 0291d89e56febe3c9b1bcc7c579ddd4196d0c600 Mon Sep 17 00:00:00 2001 From: Jon Surrell Date: Fri, 7 Jun 2024 11:53:48 +0200 Subject: [PATCH 11/31] Annotate text replacement class --- src/wp-includes/html-api/class-wp-html-text-replacement.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wp-includes/html-api/class-wp-html-text-replacement.php b/src/wp-includes/html-api/class-wp-html-text-replacement.php index 4b8a6a6aa289d..65e17d48fdb4a 100644 --- a/src/wp-includes/html-api/class-wp-html-text-replacement.php +++ b/src/wp-includes/html-api/class-wp-html-text-replacement.php @@ -56,7 +56,7 @@ class WP_HTML_Text_Replacement { * @param int $length Byte length of span in document being replaced. * @param string $text Span of text to insert in document to replace existing content from start to end. */ - public function __construct( $start, $length, $text ) { + public function __construct( int $start, int $length, string $text ) { $this->start = $start; $this->length = $length; $this->text = $text; From 5e92ba598a0ae7c74ea3b73e1916aae37c120bf3 Mon Sep 17 00:00:00 2001 From: Jon Surrell Date: Fri, 7 Jun 2024 11:54:58 +0200 Subject: [PATCH 12/31] Annotate html token class --- src/wp-includes/html-api/class-wp-html-token.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wp-includes/html-api/class-wp-html-token.php b/src/wp-includes/html-api/class-wp-html-token.php index 86dd7658cfcee..ac3cbc5395d5f 100644 --- a/src/wp-includes/html-api/class-wp-html-token.php +++ b/src/wp-includes/html-api/class-wp-html-token.php @@ -77,7 +77,7 @@ class WP_HTML_Token { * @param bool $has_self_closing_flag Whether the source token contains the self-closing flag, regardless of whether it's valid. * @param callable $on_destroy Function to call when destroying token, useful for releasing the bookmark. */ - public function __construct( $bookmark_name, $node_name, $has_self_closing_flag, $on_destroy = null ) { + public function __construct( string $bookmark_name, string $node_name, bool $has_self_closing_flag, $on_destroy = null ) { $this->bookmark_name = $bookmark_name; $this->node_name = $node_name; $this->has_self_closing_flag = $has_self_closing_flag; From 8c9878f0ce166856de20cb6b39b0844b49269eb8 Mon Sep 17 00:00:00 2001 From: Jon Surrell Date: Fri, 7 Jun 2024 13:08:41 +0200 Subject: [PATCH 13/31] Add more token map types --- src/wp-includes/class-wp-token-map.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wp-includes/class-wp-token-map.php b/src/wp-includes/class-wp-token-map.php index 17c485e5abef3..f39c3b96e575d 100644 --- a/src/wp-includes/class-wp-token-map.php +++ b/src/wp-includes/class-wp-token-map.php @@ -328,7 +328,7 @@ public static function from_array( array $mappings, int $key_length = 2 ): ?WP_T foreach ( $groups as $group_key => $group ) { usort( $groups[ $group_key ], - static function ( $a, $b ) { + static function ( string $a, string $b ): bool { return self::longest_first_then_alphabetical( $a[0], $b[0] ); } ); From 31bee95de70643028d963d5fb942dd1264f23c1f Mon Sep 17 00:00:00 2001 From: Jon Surrell Date: Fri, 7 Jun 2024 13:09:02 +0200 Subject: [PATCH 14/31] Add void function return types This is supported by PHP 7.1 --- .../html-api/class-wp-html-open-elements.php | 10 +++++----- .../html-api/class-wp-html-processor.php | 16 ++++++++-------- .../html-api/class-wp-html-tag-processor.php | 6 +++--- 3 files changed, 16 insertions(+), 16 deletions(-) diff --git a/src/wp-includes/html-api/class-wp-html-open-elements.php b/src/wp-includes/html-api/class-wp-html-open-elements.php index cdb91d99e0264..df810afd96f3d 100644 --- a/src/wp-includes/html-api/class-wp-html-open-elements.php +++ b/src/wp-includes/html-api/class-wp-html-open-elements.php @@ -83,7 +83,7 @@ class WP_HTML_Open_Elements { * * @param Closure $handler The handler function. */ - public function set_pop_handler( Closure $handler ) { + public function set_pop_handler( Closure $handler ): void { $this->pop_handler = $handler; } @@ -97,7 +97,7 @@ public function set_pop_handler( Closure $handler ) { * * @param Closure $handler The handler function. */ - public function set_push_handler( Closure $handler ) { + public function set_push_handler( Closure $handler ): void { $this->push_handler = $handler; } @@ -355,7 +355,7 @@ public function pop_until( string $tag_name ): bool { * * @param WP_HTML_Token $stack_item Item to add onto stack. */ - public function push( WP_HTML_Token $stack_item ) { + public function push( WP_HTML_Token $stack_item ): void { $this->stack[] = $stack_item; $this->after_element_push( $stack_item ); } @@ -465,7 +465,7 @@ public function walk_up( ?WP_HTML_Token $above_this_node = null ) { * * @param WP_HTML_Token $item Element that was added to the stack of open elements. */ - public function after_element_push( WP_HTML_Token $item ) { + public function after_element_push( WP_HTML_Token $item ): void { /* * When adding support for new elements, expand this switch to trap * cases where the precalculated value needs to change. @@ -498,7 +498,7 @@ public function after_element_push( WP_HTML_Token $item ) { * * @param WP_HTML_Token $item Element that was removed from the stack of open elements. */ - public function after_element_pop( WP_HTML_Token $item ) { + public function after_element_pop( WP_HTML_Token $item ): void { /* * When adding support for new elements, expand this switch to trap * cases where the precalculated value needs to change. diff --git a/src/wp-includes/html-api/class-wp-html-processor.php b/src/wp-includes/html-api/class-wp-html-processor.php index 9d3dd0202e41e..3ca44be4d6d66 100644 --- a/src/wp-includes/html-api/class-wp-html-processor.php +++ b/src/wp-includes/html-api/class-wp-html-processor.php @@ -348,7 +348,7 @@ public function __construct( string $html, ?string $use_the_static_create_method $this->state = new WP_HTML_Processor_State(); $this->state->stack_of_open_elements->set_push_handler( - function ( WP_HTML_Token $token ) { + function ( WP_HTML_Token $token ): void { $is_virtual = ! isset( $this->state->current_token ) || $this->is_tag_closer(); $same_node = isset( $this->state->current_token ) && $token->node_name === $this->state->current_token->node_name; $provenance = ( ! $same_node || $is_virtual ) ? 'virtual' : 'real'; @@ -357,7 +357,7 @@ function ( WP_HTML_Token $token ) { ); $this->state->stack_of_open_elements->set_pop_handler( - function ( WP_HTML_Token $token ) { + function ( WP_HTML_Token $token ): void { $is_virtual = ! isset( $this->state->current_token ) || ! $this->is_tag_closer(); $same_node = isset( $this->state->current_token ) && $token->node_name === $this->state->current_token->node_name; $provenance = ( ! $same_node || $is_virtual ) ? 'virtual' : 'real'; @@ -370,7 +370,7 @@ function ( WP_HTML_Token $token ) { * a private method into WP_HTML_Token classes without * exposing it to any public API. */ - $this->release_internal_bookmark_on_destruct = function ( $name ) { + $this->release_internal_bookmark_on_destruct = function ( $name ): void { parent::release_bookmark( $name ); }; } @@ -1986,7 +1986,7 @@ public function has_bookmark( string $bookmark_name ): bool { * * @see https://html.spec.whatwg.org/#close-a-p-element */ - private function close_a_p_element() { + private function close_a_p_element(): void { $this->generate_implied_end_tags( 'P' ); $this->state->stack_of_open_elements->pop_until( 'P' ); } @@ -2000,7 +2000,7 @@ private function close_a_p_element() { * * @param string|null $except_for_this_element Perform as if this element doesn't exist in the stack of open elements. */ - private function generate_implied_end_tags( ?string $except_for_this_element = null ) { + private function generate_implied_end_tags( ?string $except_for_this_element = null ): void { $elements_with_implied_end_tags = array( 'DD', 'DT', @@ -2028,7 +2028,7 @@ private function generate_implied_end_tags( ?string $except_for_this_element = n * @see WP_HTML_Processor::generate_implied_end_tags * @see https://html.spec.whatwg.org/#generate-implied-end-tags */ - private function generate_implied_end_tags_thoroughly() { + private function generate_implied_end_tags_thoroughly(): void { $elements_with_implied_end_tags = array( 'DD', 'DT', @@ -2097,7 +2097,7 @@ private function reconstruct_active_formatting_elements(): bool { * * @see https://html.spec.whatwg.org/#adoption-agency-algorithm */ - private function run_adoption_agency_algorithm() { + private function run_adoption_agency_algorithm(): void { $budget = 1000; $subject = $this->get_tag(); $current_node = $this->state->stack_of_open_elements->current_node(); @@ -2208,7 +2208,7 @@ private function run_adoption_agency_algorithm() { * * @param WP_HTML_Token $token Name of bookmark pointing to element in original input HTML. */ - private function insert_html_element( WP_HTML_Token $token ) { + private function insert_html_element( WP_HTML_Token $token ): void { $this->state->stack_of_open_elements->push( $token ); } diff --git a/src/wp-includes/html-api/class-wp-html-tag-processor.php b/src/wp-includes/html-api/class-wp-html-tag-processor.php index 9e00a80cedb43..e7de874e921cb 100644 --- a/src/wp-includes/html-api/class-wp-html-tag-processor.php +++ b/src/wp-includes/html-api/class-wp-html-tag-processor.php @@ -2052,7 +2052,7 @@ private function parse_next_attribute(): bool { * * @since 6.2.0 */ - private function skip_whitespace() { + private function skip_whitespace(): void { $this->bytes_already_parsed += strspn( $this->html, " \t\f\r\n", $this->bytes_already_parsed ); } @@ -2061,7 +2061,7 @@ private function skip_whitespace() { * * @since 6.2.0 */ - private function after_tag() { + private function after_tag(): void { /* * There could be lexical updates enqueued for an attribute that * also exists on the next tag. In order to avoid conflating the @@ -2122,7 +2122,7 @@ private function after_tag() { * @see WP_HTML_Tag_Processor::$lexical_updates * @see WP_HTML_Tag_Processor::$classname_updates */ - private function class_name_updates_to_attributes_updates() { + private function class_name_updates_to_attributes_updates(): void { if ( count( $this->classname_updates ) === 0 ) { return; } From a0974b43000c537d2d1ba6c8ae196d39207a7dd5 Mon Sep 17 00:00:00 2001 From: Jon Surrell Date: Mon, 24 Jun 2024 17:02:38 +0200 Subject: [PATCH 15/31] Fix token map usort closure types --- src/wp-includes/class-wp-token-map.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wp-includes/class-wp-token-map.php b/src/wp-includes/class-wp-token-map.php index f39c3b96e575d..77d74a02324a4 100644 --- a/src/wp-includes/class-wp-token-map.php +++ b/src/wp-includes/class-wp-token-map.php @@ -328,7 +328,7 @@ public static function from_array( array $mappings, int $key_length = 2 ): ?WP_T foreach ( $groups as $group_key => $group ) { usort( $groups[ $group_key ], - static function ( string $a, string $b ): bool { + static function ( array $a, array $b ): int { return self::longest_first_then_alphabetical( $a[0], $b[0] ); } ); From 64eaca2b0ef232bd984e6589e1c1b648e6355cb9 Mon Sep 17 00:00:00 2001 From: Jon Surrell Date: Wed, 26 Jun 2024 13:24:39 +0200 Subject: [PATCH 16/31] Annotate new is_virtual method --- src/wp-includes/html-api/class-wp-html-processor.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wp-includes/html-api/class-wp-html-processor.php b/src/wp-includes/html-api/class-wp-html-processor.php index 3ca44be4d6d66..ea1492636dfca 100644 --- a/src/wp-includes/html-api/class-wp-html-processor.php +++ b/src/wp-includes/html-api/class-wp-html-processor.php @@ -587,7 +587,7 @@ public function is_tag_closer() { * * @return bool Whether the current token is virtual. */ - private function is_virtual() { + private function is_virtual(): bool { return ( isset( $this->current_element->provenance ) && 'virtual' === $this->current_element->provenance From a2393b69b378d9e0330d3c19da7ec3944b3092fd Mon Sep 17 00:00:00 2001 From: Jon Surrell Date: Mon, 24 Jun 2024 15:04:01 +0200 Subject: [PATCH 17/31] Annotate types in additional HTML Processor subclassed methods --- .../html-api/class-wp-html-processor.php | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/wp-includes/html-api/class-wp-html-processor.php b/src/wp-includes/html-api/class-wp-html-processor.php index ea1492636dfca..53ec630d97afc 100644 --- a/src/wp-includes/html-api/class-wp-html-processor.php +++ b/src/wp-includes/html-api/class-wp-html-processor.php @@ -1496,7 +1496,7 @@ public function get_tag(): ?string { * * @return bool Whether the currently matched tag contains the self-closing flag. */ - public function has_self_closing_flag() { + public function has_self_closing_flag(): bool { return $this->is_virtual() ? false : parent::has_self_closing_flag(); } @@ -1610,7 +1610,7 @@ public function get_attribute( string $name ) { * @param string|bool $value The new attribute value. * @return bool Whether an attribute value was set. */ - public function set_attribute( $name, $value ) { + public function set_attribute( $name, $value ): bool { return $this->is_virtual() ? false : parent::set_attribute( $name, $value ); } @@ -1622,7 +1622,7 @@ public function set_attribute( $name, $value ) { * @param string $name The attribute name to remove. * @return bool Whether an attribute was removed. */ - public function remove_attribute( $name ) { + public function remove_attribute( $name ): bool { return $this->is_virtual() ? false : parent::remove_attribute( $name ); } @@ -1664,7 +1664,7 @@ public function get_attribute_names_with_prefix( string $prefix ): ?array { * @param string $class_name The class name to add. * @return bool Whether the class was set to be added. */ - public function add_class( $class_name ) { + public function add_class( $class_name ): bool { return $this->is_virtual() ? false : parent::add_class( $class_name ); } @@ -1676,7 +1676,7 @@ public function add_class( $class_name ) { * @param string $class_name The class name to remove. * @return bool Whether the class was set to be removed. */ - public function remove_class( $class_name ) { + public function remove_class( $class_name ): bool { return $this->is_virtual() ? false : parent::remove_class( $class_name ); } @@ -1688,7 +1688,7 @@ public function remove_class( $class_name ) { * @param string $wanted_class Look for this CSS class name, ASCII case-insensitive. * @return bool|null Whether the matched tag contains the given class name, or null if not matched. */ - public function has_class( $wanted_class ) { + public function has_class( $wanted_class ): ?bool { return $this->is_virtual() ? null : parent::has_class( $wanted_class ); } @@ -1755,7 +1755,7 @@ public function get_modifiable_text(): string { * * @return string|null */ - public function get_comment_type() { + public function get_comment_type(): ?string { return $this->is_virtual() ? null : parent::get_comment_type(); } From 1bcaf1487e43915e411345794b96e94cfba9872f Mon Sep 17 00:00:00 2001 From: Jon Surrell Date: Mon, 24 Jun 2024 15:04:01 +0200 Subject: [PATCH 18/31] Add missing annotations on subclassed methods --- src/wp-includes/html-api/class-wp-html-processor.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/wp-includes/html-api/class-wp-html-processor.php b/src/wp-includes/html-api/class-wp-html-processor.php index 53ec630d97afc..f0e8a60c3b736 100644 --- a/src/wp-includes/html-api/class-wp-html-processor.php +++ b/src/wp-includes/html-api/class-wp-html-processor.php @@ -573,7 +573,7 @@ public function next_token(): bool { * * @return bool Whether the current tag is a tag closer. */ - public function is_tag_closer() { + public function is_tag_closer(): bool { return $this->is_virtual() ? ( WP_HTML_Stack_Event::POP === $this->current_element->operation && '#tag' === $this->get_token_type() ) : parent::is_tag_closer(); @@ -1520,7 +1520,7 @@ public function has_self_closing_flag(): bool { * * @return string|null Name of the matched token. */ - public function get_token_name() { + public function get_token_name(): ?string { return $this->is_virtual() ? $this->current_element->token->node_name : parent::get_token_name(); @@ -1548,7 +1548,7 @@ public function get_token_name() { * * @return string|null What kind of token is matched, or null. */ - public function get_token_type() { + public function get_token_type(): ?string { if ( $this->is_virtual() ) { /* * This logic comes from the Tag Processor. From 8c898deed233443ad3d7f870fca131d8104dfeee Mon Sep 17 00:00:00 2001 From: Jon Surrell Date: Wed, 26 Jun 2024 13:51:08 +0200 Subject: [PATCH 19/31] Add callable annotation to token constructor --- src/wp-includes/html-api/class-wp-html-token.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/wp-includes/html-api/class-wp-html-token.php b/src/wp-includes/html-api/class-wp-html-token.php index ac3cbc5395d5f..cbd3d8c108006 100644 --- a/src/wp-includes/html-api/class-wp-html-token.php +++ b/src/wp-includes/html-api/class-wp-html-token.php @@ -72,12 +72,12 @@ class WP_HTML_Token { * * @since 6.4.0 * - * @param string $bookmark_name Name of bookmark corresponding to location in HTML where token is found. - * @param string $node_name Name of node token represents; if uppercase, an HTML element; if lowercase, a special value like "marker". - * @param bool $has_self_closing_flag Whether the source token contains the self-closing flag, regardless of whether it's valid. - * @param callable $on_destroy Function to call when destroying token, useful for releasing the bookmark. + * @param string $bookmark_name Name of bookmark corresponding to location in HTML where token is found. + * @param string $node_name Name of node token represents; if uppercase, an HTML element; if lowercase, a special value like "marker". + * @param bool $has_self_closing_flag Whether the source token contains the self-closing flag, regardless of whether it's valid. + * @param ?callable $on_destroy Optional. Function to call when destroying token, useful for releasing the bookmark. */ - public function __construct( string $bookmark_name, string $node_name, bool $has_self_closing_flag, $on_destroy = null ) { + public function __construct( string $bookmark_name, string $node_name, bool $has_self_closing_flag, ?callable $on_destroy = null ) { $this->bookmark_name = $bookmark_name; $this->node_name = $node_name; $this->has_self_closing_flag = $has_self_closing_flag; From 386bb68e2b9da8525beccc07dd8ac560153d2c01 Mon Sep 17 00:00:00 2001 From: Jon Surrell Date: Mon, 15 Jul 2024 19:22:52 +0200 Subject: [PATCH 20/31] Replace invalid phpdoc ?nullable with T|null --- src/wp-includes/class-wp-token-map.php | 9 +++++---- src/wp-includes/functions.php | 2 +- src/wp-includes/html-api/class-wp-html-open-elements.php | 2 +- src/wp-includes/html-api/class-wp-html-processor.php | 4 ++-- tests/phpunit/tests/html-api/wpHtmlProcessorHtml5lib.php | 2 +- 5 files changed, 10 insertions(+), 9 deletions(-) diff --git a/src/wp-includes/class-wp-token-map.php b/src/wp-includes/class-wp-token-map.php index a932f4cae4d27..524ab57fd4587 100644 --- a/src/wp-includes/class-wp-token-map.php +++ b/src/wp-includes/class-wp-token-map.php @@ -520,10 +520,11 @@ public function contains( $word, $case_sensitivity = 'case-sensitive' ) { * * @since 6.6.0 * - * @param string $text String in which to search for a lookup key. - * @param int $offset Optional. How many bytes into the string where the lookup key ought to start. Default 0. - * @param ?int &$matched_token_byte_length Optional. Holds byte-length of found token matched, otherwise not set. Default null. - * @param string $case_sensitivity Optional. Pass 'ascii-case-insensitive' to ignore ASCII case when matching. Default 'case-sensitive'. + * @param string $text String in which to search for a lookup key. + * @param int $offset Optional. How many bytes into the string where the lookup key ought to start. Default 0. + * @param int|null &$matched_token_byte_length Optional. Holds byte-length of found token matched, otherwise not set. Default null. + * @param string $case_sensitivity Optional. Pass 'ascii-case-insensitive' to ignore ASCII case when matching. Default 'case-sensitive'. + * * @return string|null Mapped value of lookup key if found, otherwise `null`. */ public function read_token( $text, $offset = 0, &$matched_token_byte_length = null, $case_sensitivity = 'case-sensitive' ) { diff --git a/src/wp-includes/functions.php b/src/wp-includes/functions.php index e99a93b80db71..d32fc0b7e1c84 100644 --- a/src/wp-includes/functions.php +++ b/src/wp-includes/functions.php @@ -7497,7 +7497,7 @@ function get_tag_regex( $tag ) { * * @since 6.6.0 * - * @param ?string $blog_charset Slug representing a text character encoding, or "charset". + * @param string|null $blog_charset Slug representing a text character encoding, or "charset". * E.g. "UTF-8", "Windows-1252", "ISO-8859-1", "SJIS". * @return bool Whether the slug represents the UTF-8 encoding. */ diff --git a/src/wp-includes/html-api/class-wp-html-open-elements.php b/src/wp-includes/html-api/class-wp-html-open-elements.php index d1585cdea5bf5..f4ac3b68e8d70 100644 --- a/src/wp-includes/html-api/class-wp-html-open-elements.php +++ b/src/wp-includes/html-api/class-wp-html-open-elements.php @@ -499,7 +499,7 @@ public function walk_down() { * @since 6.4.0 * @since 6.5.0 Accepts $above_this_node to start traversal above a given node, if it exists. * - * @param ?WP_HTML_Token $above_this_node Start traversing above this node, if provided and if the node exists. + * @param WP_HTML_Token|null $above_this_node Start traversing above this node, if provided and if the node exists. */ public function walk_up( $above_this_node = null ) { $has_found_node = null === $above_this_node; diff --git a/src/wp-includes/html-api/class-wp-html-processor.php b/src/wp-includes/html-api/class-wp-html-processor.php index 04c387c003d8f..06f91180e97d8 100644 --- a/src/wp-includes/html-api/class-wp-html-processor.php +++ b/src/wp-includes/html-api/class-wp-html-processor.php @@ -241,14 +241,14 @@ class WP_HTML_Processor extends WP_HTML_Tag_Processor { * * @since 6.6.0 * - * @var ?WP_HTML_Stack_Event + * @var WP_HTML_Stack_Event|null */ private $current_element = null; /** * Context node if created as a fragment parser. * - * @var ?WP_HTML_Token + * @var WP_HTML_Token|null */ private $context_node = null; diff --git a/tests/phpunit/tests/html-api/wpHtmlProcessorHtml5lib.php b/tests/phpunit/tests/html-api/wpHtmlProcessorHtml5lib.php index 86abe7f5aeffb..80fbc63f363d5 100644 --- a/tests/phpunit/tests/html-api/wpHtmlProcessorHtml5lib.php +++ b/tests/phpunit/tests/html-api/wpHtmlProcessorHtml5lib.php @@ -275,7 +275,7 @@ public static function parse_html5_dat_testfile( $filename ) { /** * Represents which section of the test case is being parsed. * - * @var ?string + * @var string|null */ $state = null; From 5bc56aec214ca2b7981afe542644d58867210cd3 Mon Sep 17 00:00:00 2001 From: Jon Surrell Date: Mon, 15 Jul 2024 19:51:27 +0200 Subject: [PATCH 21/31] Fix nullable type annotations PHPDoc types should be T|null not ?T. Confusing since PHP supports ?T as a nullable type. --- src/wp-includes/class-wp-token-map.php | 9 +++++---- src/wp-includes/html-api/class-wp-html-open-elements.php | 4 ++-- src/wp-includes/html-api/class-wp-html-processor.php | 4 ++-- src/wp-includes/html-api/class-wp-html-token.php | 8 ++++---- 4 files changed, 13 insertions(+), 12 deletions(-) diff --git a/src/wp-includes/class-wp-token-map.php b/src/wp-includes/class-wp-token-map.php index 4d24bd527c69a..29d15ab125a13 100644 --- a/src/wp-includes/class-wp-token-map.php +++ b/src/wp-includes/class-wp-token-map.php @@ -573,10 +573,11 @@ public function read_token( string $text, int $offset = 0, &$matched_token_byte_ * * @since 6.6.0. * - * @param string $text String in which to search for a lookup key. - * @param int $offset Optional. How many bytes into the string where the lookup key ought to start. Default 0. - * @param ?int &$matched_token_byte_length Optional. Holds byte-length of found lookup key if matched, otherwise not set. Default null. - * @param string $case_sensitivity Optional. Pass 'ascii-case-insensitive' to ignore ASCII case when matching. Default 'case-sensitive'. + * @param string $text String in which to search for a lookup key. + * @param int $offset Optional. How many bytes into the string where the lookup key ought to start. Default 0. + * @param int|null &$matched_token_byte_length Optional. Holds byte-length of found lookup key if matched, otherwise not set. Default null. + * @param string $case_sensitivity Optional. Pass 'ascii-case-insensitive' to ignore ASCII case when matching. Default 'case-sensitive'. + * * @return string|null Mapped value of lookup key if found, otherwise `null`. */ private function read_small_token( string $text, int $offset = 0, &$matched_token_byte_length = null, $case_sensitivity = 'case-sensitive' ): ?string { diff --git a/src/wp-includes/html-api/class-wp-html-open-elements.php b/src/wp-includes/html-api/class-wp-html-open-elements.php index f338cafbc9bd2..161e5e223870b 100644 --- a/src/wp-includes/html-api/class-wp-html-open-elements.php +++ b/src/wp-includes/html-api/class-wp-html-open-elements.php @@ -58,7 +58,7 @@ class WP_HTML_Open_Elements { * * @since 6.6.0 * - * @var ?Closure + * @var Closure|null */ private $pop_handler = null; @@ -69,7 +69,7 @@ class WP_HTML_Open_Elements { * * @since 6.6.0 * - * @var ?Closure + * @var Closure|null */ private $push_handler = null; diff --git a/src/wp-includes/html-api/class-wp-html-processor.php b/src/wp-includes/html-api/class-wp-html-processor.php index b7707e7adfd71..8e2646009c3ab 100644 --- a/src/wp-includes/html-api/class-wp-html-processor.php +++ b/src/wp-includes/html-api/class-wp-html-processor.php @@ -184,7 +184,7 @@ class WP_HTML_Processor extends WP_HTML_Tag_Processor { * * @since 6.4.0 * - * @var ?string + * @var string|null */ private $last_error = null; @@ -208,7 +208,7 @@ class WP_HTML_Processor extends WP_HTML_Tag_Processor { * * @since 6.4.0 * - * @var ?Closure + * @var Closure|null */ private $release_internal_bookmark_on_destruct = null; diff --git a/src/wp-includes/html-api/class-wp-html-token.php b/src/wp-includes/html-api/class-wp-html-token.php index cbd3d8c108006..fe8636fb5e164 100644 --- a/src/wp-includes/html-api/class-wp-html-token.php +++ b/src/wp-includes/html-api/class-wp-html-token.php @@ -72,10 +72,10 @@ class WP_HTML_Token { * * @since 6.4.0 * - * @param string $bookmark_name Name of bookmark corresponding to location in HTML where token is found. - * @param string $node_name Name of node token represents; if uppercase, an HTML element; if lowercase, a special value like "marker". - * @param bool $has_self_closing_flag Whether the source token contains the self-closing flag, regardless of whether it's valid. - * @param ?callable $on_destroy Optional. Function to call when destroying token, useful for releasing the bookmark. + * @param string $bookmark_name Name of bookmark corresponding to location in HTML where token is found. + * @param string $node_name Name of node token represents; if uppercase, an HTML element; if lowercase, a special value like "marker". + * @param bool $has_self_closing_flag Whether the source token contains the self-closing flag, regardless of whether it's valid. + * @param callable|null $on_destroy Optional. Function to call when destroying token, useful for releasing the bookmark. */ public function __construct( string $bookmark_name, string $node_name, bool $has_self_closing_flag, ?callable $on_destroy = null ) { $this->bookmark_name = $bookmark_name; From 731c51919a41b827583978859c1efe04bea4f59a Mon Sep 17 00:00:00 2001 From: Jon Surrell Date: Mon, 15 Jul 2024 19:53:23 +0200 Subject: [PATCH 22/31] Remove trailing dot from simple since tag The convention is to omit a period when since tags only include a version number --- src/wp-includes/class-wp-token-map.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wp-includes/class-wp-token-map.php b/src/wp-includes/class-wp-token-map.php index 29d15ab125a13..09a0b9303b452 100644 --- a/src/wp-includes/class-wp-token-map.php +++ b/src/wp-includes/class-wp-token-map.php @@ -571,7 +571,7 @@ public function read_token( string $text, int $offset = 0, &$matched_token_byte_ /** * Finds a match for a short word at the index. * - * @since 6.6.0. + * @since 6.6.0 * * @param string $text String in which to search for a lookup key. * @param int $offset Optional. How many bytes into the string where the lookup key ought to start. Default 0. From ef6ae92fc1d85717299f3ec18019a4ee56c4e260 Mon Sep 17 00:00:00 2001 From: Jon Surrell Date: Mon, 15 Jul 2024 19:58:59 +0200 Subject: [PATCH 23/31] Remove type annotations from public APIs These changes could produce new runtime errors that are undesirable. For example, it's easy to unintentionally pass null to a function. If that function expects a string, this is now a type error instead of the previous behavior. --- .../html-api/class-wp-html-processor.php | 24 +++++++++---------- .../html-api/class-wp-html-tag-processor.php | 24 +++++++++---------- 2 files changed, 24 insertions(+), 24 deletions(-) diff --git a/src/wp-includes/html-api/class-wp-html-processor.php b/src/wp-includes/html-api/class-wp-html-processor.php index 8e2646009c3ab..933d64b4f10cd 100644 --- a/src/wp-includes/html-api/class-wp-html-processor.php +++ b/src/wp-includes/html-api/class-wp-html-processor.php @@ -303,7 +303,7 @@ class WP_HTML_Processor extends WP_HTML_Tag_Processor { * @param string $encoding Text encoding of the document; must be default of 'UTF-8'. * @return static|null The created processor if successful, otherwise null. */ - public static function create_fragment( string $html, string $context = '', string $encoding = 'UTF-8' ) { + public static function create_fragment( $html, $context = '', $encoding = 'UTF-8' ) { if ( '' !== $context || 'UTF-8' !== $encoding ) { return null; } @@ -705,7 +705,7 @@ private function is_virtual(): bool { * May also contain the wildcard `*` which matches a single element, e.g. `array( 'SECTION', '*' )`. * @return bool Whether the currently-matched tag is found at the given nested structure. */ - public function matches_breadcrumbs( array $breadcrumbs ): bool { + public function matches_breadcrumbs( $breadcrumbs ): bool { // Everything matches when there are zero constraints. if ( 0 === count( $breadcrumbs ) ) { return true; @@ -755,7 +755,7 @@ public function matches_breadcrumbs( array $breadcrumbs ): bool { * @return bool Whether to expect a closer for the currently-matched node, * or `null` if not matched on any token. */ - public function expects_closer( ?WP_HTML_Token $node = null ): ?bool { + public function expects_closer( $node = null ): ?bool { $token_name = $node->node_name ?? $this->get_token_name(); if ( ! isset( $token_name ) ) { return null; @@ -786,7 +786,7 @@ public function expects_closer( ?WP_HTML_Token $node = null ): ?bool { * @param string $node_to_process Whether to parse the next node or reprocess the current node. * @return bool Whether a tag was matched. */ - public function step( string $node_to_process = self::PROCESS_NEXT_NODE ): bool { + public function step( $node_to_process = self::PROCESS_NEXT_NODE ): bool { // Refuse to proceed if there was a previous error. if ( null !== $this->last_error ) { return false; @@ -2357,7 +2357,7 @@ public function get_token_type(): ?string { * @param string $name Name of attribute whose value is requested. * @return string|true|null Value of attribute or `null` if not available. Boolean attributes return `true`. */ - public function get_attribute( string $name ) { + public function get_attribute( $name ) { return $this->is_virtual() ? null : parent::get_attribute( $name ); } @@ -2418,7 +2418,7 @@ public function remove_attribute( $name ): bool { * @param string $prefix Prefix of requested attribute names. * @return array|null List of attribute names, or `null` when no tag opener is matched. */ - public function get_attribute_names_with_prefix( string $prefix ): ?array { + public function get_attribute_names_with_prefix( $prefix ): ?array { return $this->is_virtual() ? null : parent::get_attribute_names_with_prefix( $prefix ); } @@ -2536,7 +2536,7 @@ public function get_comment_type(): ?string { * @param string $bookmark_name Name of the bookmark to remove. * @return bool Whether the bookmark already existed before removal. */ - public function release_bookmark( string $bookmark_name ): bool { + public function release_bookmark( $bookmark_name ): bool { return parent::release_bookmark( "_{$bookmark_name}" ); } @@ -2557,7 +2557,7 @@ public function release_bookmark( string $bookmark_name ): bool { * @param string $bookmark_name Jump to the place in the document identified by this bookmark name. * @return bool Whether the internal cursor was successfully moved to the bookmark's location. */ - public function seek( string $bookmark_name ): bool { + public function seek( $bookmark_name ): bool { // Flush any pending updates to the document before beginning. $this->get_updated_html(); @@ -2728,7 +2728,7 @@ public function seek( string $bookmark_name ): bool { * @param string $bookmark_name Identifies this particular bookmark. * @return bool Whether the bookmark was successfully created. */ - public function set_bookmark( string $bookmark_name ): bool { + public function set_bookmark( $bookmark_name ): bool { return parent::set_bookmark( "_{$bookmark_name}" ); } @@ -2740,7 +2740,7 @@ public function set_bookmark( string $bookmark_name ): bool { * @param string $bookmark_name Name to identify a bookmark that potentially exists. * @return bool Whether that bookmark exists. */ - public function has_bookmark( string $bookmark_name ): bool { + public function has_bookmark( $bookmark_name ): bool { return parent::has_bookmark( "_{$bookmark_name}" ); } @@ -3199,7 +3199,7 @@ private function insert_html_element( WP_HTML_Token $token ): void { * @param string $tag_name Name of element to check. * @return bool Whether the element of the given name is in the special category. */ - public static function is_special( string $tag_name ): bool { + public static function is_special( $tag_name ): bool { $tag_name = strtoupper( $tag_name ); return ( @@ -3314,7 +3314,7 @@ public static function is_special( string $tag_name ): bool { * @param string $tag_name Name of HTML tag to check. * @return bool Whether the given tag is an HTML Void Element. */ - public static function is_void( string $tag_name ): bool { + public static function is_void( $tag_name ): bool { $tag_name = strtoupper( $tag_name ); return ( diff --git a/src/wp-includes/html-api/class-wp-html-tag-processor.php b/src/wp-includes/html-api/class-wp-html-tag-processor.php index 9685d767abf68..b8a451ea7671a 100644 --- a/src/wp-includes/html-api/class-wp-html-tag-processor.php +++ b/src/wp-includes/html-api/class-wp-html-tag-processor.php @@ -762,7 +762,7 @@ class WP_HTML_Tag_Processor { * * @param string $html HTML to process. */ - public function __construct( string $html ) { + public function __construct( $html ) { $this->html = $html; } @@ -1112,7 +1112,7 @@ public function class_list() { * @param string $wanted_class Look for this CSS class name, ASCII case-insensitive. * @return bool|null Whether the matched tag contains the given class name, or null if not matched. */ - public function has_class( string $wanted_class ): ?bool { + public function has_class( $wanted_class ): ?bool { if ( self::STATE_MATCHED_TAG !== $this->parser_state ) { return null; } @@ -1209,7 +1209,7 @@ public function has_class( string $wanted_class ): ?bool { * @param string $name Identifies this particular bookmark. * @return bool Whether the bookmark was successfully created. */ - public function set_bookmark( string $name ): bool { + public function set_bookmark( $name ): bool { // It only makes sense to set a bookmark if the parser has paused on a concrete token. if ( self::STATE_COMPLETE === $this->parser_state || @@ -1242,7 +1242,7 @@ public function set_bookmark( string $name ): bool { * @param string $name Name of the bookmark to remove. * @return bool Whether the bookmark already existed before removal. */ - public function release_bookmark( string $name ): bool { + public function release_bookmark( $name ): bool { if ( ! array_key_exists( $name, $this->bookmarks ) ) { return false; } @@ -2351,7 +2351,7 @@ private function apply_attributes_updates( int $shift_this_point ): int { * @param string $bookmark_name Name to identify a bookmark that potentially exists. * @return bool Whether that bookmark exists. */ - public function has_bookmark( string $bookmark_name ): bool { + public function has_bookmark( $bookmark_name ): bool { return array_key_exists( $bookmark_name, $this->bookmarks ); } @@ -2366,7 +2366,7 @@ public function has_bookmark( string $bookmark_name ): bool { * @param string $bookmark_name Jump to the place in the document identified by this bookmark name. * @return bool Whether the internal cursor was successfully moved to the bookmark's location. */ - public function seek( string $bookmark_name ): bool { + public function seek( $bookmark_name ): bool { if ( ! array_key_exists( $bookmark_name, $this->bookmarks ) ) { _doing_it_wrong( __METHOD__, @@ -2506,7 +2506,7 @@ private function get_enqueued_attribute_value( string $comparable_name ) { * @param string $name Name of attribute whose value is requested. * @return string|true|null Value of attribute or `null` if not available. Boolean attributes return `true`. */ - public function get_attribute( string $name ) { + public function get_attribute( $name ) { if ( self::STATE_MATCHED_TAG !== $this->parser_state ) { return null; } @@ -2586,7 +2586,7 @@ public function get_attribute( string $name ) { * @param string $prefix Prefix of requested attribute names. * @return array|null List of attribute names, or `null` when no tag opener is matched. */ - public function get_attribute_names_with_prefix( string $prefix ): ?array { + public function get_attribute_names_with_prefix( $prefix ): ?array { if ( self::STATE_MATCHED_TAG !== $this->parser_state || $this->is_closing_tag @@ -2897,7 +2897,7 @@ public function get_modifiable_text(): string { * @param string|bool $value The new attribute value. * @return bool Whether an attribute value was set. */ - public function set_attribute( string $name, $value ): bool { + public function set_attribute( $name, $value ): bool { if ( self::STATE_MATCHED_TAG !== $this->parser_state || $this->is_closing_tag @@ -3040,7 +3040,7 @@ public function set_attribute( string $name, $value ): bool { * @param string $name The attribute name to remove. * @return bool Whether an attribute was removed. */ - public function remove_attribute( string $name ): bool { + public function remove_attribute( $name ): bool { if ( self::STATE_MATCHED_TAG !== $this->parser_state || $this->is_closing_tag @@ -3118,7 +3118,7 @@ public function remove_attribute( string $name ): bool { * @param string $class_name The class name to add. * @return bool Whether the class was set to be added. */ - public function add_class( string $class_name ): bool { + public function add_class( $class_name ): bool { if ( self::STATE_MATCHED_TAG !== $this->parser_state || $this->is_closing_tag @@ -3139,7 +3139,7 @@ public function add_class( string $class_name ): bool { * @param string $class_name The class name to remove. * @return bool Whether the class was set to be removed. */ - public function remove_class( string $class_name ): bool { + public function remove_class( $class_name ): bool { if ( self::STATE_MATCHED_TAG !== $this->parser_state || $this->is_closing_tag From b9bc16004502d75c735faf40e15dbade2715a948 Mon Sep 17 00:00:00 2001 From: Jon Surrell Date: Mon, 15 Jul 2024 20:03:03 +0200 Subject: [PATCH 24/31] Annotate active formatting elements classes --- .../html-api/class-wp-html-active-formatting-elements.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/wp-includes/html-api/class-wp-html-active-formatting-elements.php b/src/wp-includes/html-api/class-wp-html-active-formatting-elements.php index 9f7fee9076243..69e34dca498c1 100644 --- a/src/wp-includes/html-api/class-wp-html-active-formatting-elements.php +++ b/src/wp-includes/html-api/class-wp-html-active-formatting-elements.php @@ -51,7 +51,7 @@ class WP_HTML_Active_Formatting_Elements { * @param WP_HTML_Token $token Look for this node in the stack. * @return bool Whether the referenced node is in the stack of active formatting elements. */ - public function contains_node( $token ) { + public function contains_node( WP_HTML_Token $token ) { foreach ( $this->walk_up() as $item ) { if ( $token->bookmark_name === $item->bookmark_name ) { return true; @@ -95,7 +95,7 @@ public function current_node() { * * @param WP_HTML_Token $token Push this node onto the stack. */ - public function push( $token ) { + public function push( WP_HTML_Token $token ) { /* * > If there are already three elements in the list of active formatting elements after the last marker, * > if any, or anywhere in the list if there are no markers, that have the same tag name, namespace, and @@ -119,7 +119,7 @@ public function push( $token ) { * @param WP_HTML_Token $token Remove this node from the stack, if it's there already. * @return bool Whether the node was found and removed from the stack of active formatting elements. */ - public function remove_node( $token ) { + public function remove_node( WP_HTML_Token $token ) { foreach ( $this->walk_up() as $position_from_end => $item ) { if ( $token->bookmark_name !== $item->bookmark_name ) { continue; From d4f50112ed11111ca22c9bb87b20ba7794a7296e Mon Sep 17 00:00:00 2001 From: Jon Surrell Date: Mon, 15 Jul 2024 20:05:55 +0200 Subject: [PATCH 25/31] Fix another nullable type annotation --- src/wp-includes/html-api/class-wp-html-processor.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/wp-includes/html-api/class-wp-html-processor.php b/src/wp-includes/html-api/class-wp-html-processor.php index 933d64b4f10cd..fd72760fb75cb 100644 --- a/src/wp-includes/html-api/class-wp-html-processor.php +++ b/src/wp-includes/html-api/class-wp-html-processor.php @@ -751,9 +751,10 @@ public function matches_breadcrumbs( $breadcrumbs ): bool { * this returns false for self-closing elements in the * SVG and MathML namespace. * - * @param ?WP_HTML_Token $node Node to examine instead of current node, if provided. - * @return bool Whether to expect a closer for the currently-matched node, - * or `null` if not matched on any token. + * @param WP_HTML_Token $node Node to examine instead of current node, if provided. + * + * @return bool|null Whether to expect a closer for the currently-matched node, + * or `null` if not matched on any token. */ public function expects_closer( $node = null ): ?bool { $token_name = $node->node_name ?? $this->get_token_name(); From 63e235f76dafc0f75c358aef7ed5f9c6d8fffb40 Mon Sep 17 00:00:00 2001 From: Jon Surrell Date: Mon, 15 Jul 2024 20:08:36 +0200 Subject: [PATCH 26/31] fixup! Merge remote-tracking branch 'upstream/trunk' into html-api/annotate-types --- src/wp-includes/html-api/class-wp-html-processor.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/wp-includes/html-api/class-wp-html-processor.php b/src/wp-includes/html-api/class-wp-html-processor.php index fd72760fb75cb..dda9907d425d9 100644 --- a/src/wp-includes/html-api/class-wp-html-processor.php +++ b/src/wp-includes/html-api/class-wp-html-processor.php @@ -1082,7 +1082,6 @@ private function step_in_head_noscript() { */ private function step_after_head() { $this->bail( "No support for parsing in the '{$this->state->insertion_mode}' state." ); ->>>>>>> upstream/trunk } /** From 22671eeb1adb5c783f6626364b61c3491de6d86c Mon Sep 17 00:00:00 2001 From: Jon Surrell Date: Mon, 15 Jul 2024 20:12:16 +0200 Subject: [PATCH 27/31] Fix updated phpdoc alignment --- src/wp-includes/functions.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wp-includes/functions.php b/src/wp-includes/functions.php index d32fc0b7e1c84..071300b35a6ed 100644 --- a/src/wp-includes/functions.php +++ b/src/wp-includes/functions.php @@ -7498,7 +7498,7 @@ function get_tag_regex( $tag ) { * @since 6.6.0 * * @param string|null $blog_charset Slug representing a text character encoding, or "charset". - * E.g. "UTF-8", "Windows-1252", "ISO-8859-1", "SJIS". + * E.g. "UTF-8", "Windows-1252", "ISO-8859-1", "SJIS". * @return bool Whether the slug represents the UTF-8 encoding. */ function is_utf8_charset( $blog_charset = null ) { From 26978707a72561152ea3301bef7a607a3b4797f4 Mon Sep 17 00:00:00 2001 From: Jon Surrell Date: Mon, 15 Jul 2024 20:18:13 +0200 Subject: [PATCH 28/31] Remove public function param types from html decoder class --- src/wp-includes/html-api/class-wp-html-decoder.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/wp-includes/html-api/class-wp-html-decoder.php b/src/wp-includes/html-api/class-wp-html-decoder.php index 04e38218b0200..793c7cb2a0137 100644 --- a/src/wp-includes/html-api/class-wp-html-decoder.php +++ b/src/wp-includes/html-api/class-wp-html-decoder.php @@ -31,7 +31,7 @@ class WP_HTML_Decoder { * Default 'case-sensitive'. * @return bool Whether the attribute value starts with the given string. */ - public static function attribute_starts_with( string $haystack, string $search_text, string $case_sensitivity = 'case-sensitive' ): bool { + public static function attribute_starts_with( $haystack, $search_text, $case_sensitivity = 'case-sensitive' ): bool { $search_length = strlen( $search_text ); $loose_case = 'ascii-case-insensitive' === $case_sensitivity; $haystack_end = strlen( $haystack ); @@ -90,7 +90,7 @@ public static function attribute_starts_with( string $haystack, string $search_t * @param string $text Text containing raw and non-decoded text node to decode. * @return string Decoded UTF-8 value of given text node. */ - public static function decode_text_node( string $text ): string { + public static function decode_text_node( $text ): string { return static::decode( 'data', $text ); } @@ -110,7 +110,7 @@ public static function decode_text_node( string $text ): string { * @param string $text Text containing raw and non-decoded attribute value to decode. * @return string Decoded UTF-8 value of given attribute value. */ - public static function decode_attribute( string $text ): string { + public static function decode_attribute( $text ): string { return static::decode( 'attribute', $text ); } @@ -133,7 +133,7 @@ public static function decode_attribute( string $text ): string { * @param string $text Text document containing span of text to decode. * @return string Decoded UTF-8 string. */ - public static function decode( string $context, string $text ): string { + public static function decode( $context, $text ): string { $decoded = ''; $end = strlen( $text ); $at = 0; @@ -203,7 +203,7 @@ public static function decode( string $context, string $text ): string { * is found, otherwise not set. Default null. * @return string|false Decoded character reference in UTF-8 if found, otherwise `false`. */ - public static function read_character_reference( string $context, string $text, int $at = 0, &$match_byte_length = null ) { + public static function read_character_reference( $context, $text, $at = 0, &$match_byte_length = null ) { /** * Mappings for HTML5 named character references. * @@ -421,7 +421,7 @@ public static function read_character_reference( string $context, string $text, * @param int $code_point Which code point to convert. * @return string Converted code point, or `�` if invalid. */ - public static function code_point_to_utf8_bytes( int $code_point ): string { + public static function code_point_to_utf8_bytes( $code_point ): string { // Pre-check to ensure a valid code point. if ( $code_point <= 0 || From 024e4ff328a67697557656e21dff3687e9dd5c00 Mon Sep 17 00:00:00 2001 From: Jon Surrell Date: Mon, 15 Jul 2024 20:22:22 +0200 Subject: [PATCH 29/31] Remove type annotations from HTML processor constructor --- src/wp-includes/html-api/class-wp-html-processor.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wp-includes/html-api/class-wp-html-processor.php b/src/wp-includes/html-api/class-wp-html-processor.php index dda9907d425d9..740b8977b3395 100644 --- a/src/wp-includes/html-api/class-wp-html-processor.php +++ b/src/wp-includes/html-api/class-wp-html-processor.php @@ -350,7 +350,7 @@ public static function create_fragment( $html, $context = '', $encoding = * @param string $html HTML to process. * @param string|null $use_the_static_create_methods_instead This constructor should not be called manually. */ - public function __construct( string $html, ?string $use_the_static_create_methods_instead = null ) { + public function __construct( $html, $use_the_static_create_methods_instead = null ) { parent::__construct( $html ); if ( self::CONSTRUCTOR_UNLOCK_CODE !== $use_the_static_create_methods_instead ) { From aefa85ad06cf9231d79e3eb425c349d5f3ab1d04 Mon Sep 17 00:00:00 2001 From: Jon Surrell Date: Mon, 15 Jul 2024 20:24:23 +0200 Subject: [PATCH 30/31] Annotate param type on internal bookmark distructor --- src/wp-includes/html-api/class-wp-html-processor.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wp-includes/html-api/class-wp-html-processor.php b/src/wp-includes/html-api/class-wp-html-processor.php index 740b8977b3395..19360ed1c6bdd 100644 --- a/src/wp-includes/html-api/class-wp-html-processor.php +++ b/src/wp-includes/html-api/class-wp-html-processor.php @@ -390,7 +390,7 @@ function ( WP_HTML_Token $token ): void { * a private method into WP_HTML_Token classes without * exposing it to any public API. */ - $this->release_internal_bookmark_on_destruct = function ( $name ): void { + $this->release_internal_bookmark_on_destruct = function ( string $name ): void { parent::release_bookmark( $name ); }; } From c102b5733ffd24301593ed06623af5633df6d9ee Mon Sep 17 00:00:00 2001 From: Jon Surrell Date: Mon, 15 Jul 2024 20:31:40 +0200 Subject: [PATCH 31/31] Annotate the new step_in_ functions --- .../html-api/class-wp-html-processor.php | 46 +++++++++---------- 1 file changed, 22 insertions(+), 24 deletions(-) diff --git a/src/wp-includes/html-api/class-wp-html-processor.php b/src/wp-includes/html-api/class-wp-html-processor.php index 19360ed1c6bdd..6f3b43d723367 100644 --- a/src/wp-includes/html-api/class-wp-html-processor.php +++ b/src/wp-includes/html-api/class-wp-html-processor.php @@ -403,8 +403,6 @@ function ( WP_HTML_Token $token ): void { * @since 6.7.0 * * @param string $message Explains support is missing in order to parse the current node. - * - * @return mixed */ private function bail( string $message ) { $here = $this->bookmarks[ $this->state->current_token->bookmark_name ]; @@ -985,7 +983,7 @@ public function get_current_depth(): int { * * @return bool Whether an element was found. */ - private function step_initial() { + private function step_initial(): bool { $this->bail( "No support for parsing in the '{$this->state->insertion_mode}' state." ); } @@ -1004,7 +1002,7 @@ private function step_initial() { * * @return bool Whether an element was found. */ - private function step_before_html() { + private function step_before_html(): bool { $this->bail( "No support for parsing in the '{$this->state->insertion_mode}' state." ); } @@ -1023,7 +1021,7 @@ private function step_before_html() { * * @return bool Whether an element was found. */ - private function step_before_head() { + private function step_before_head(): bool { $this->bail( "No support for parsing in the '{$this->state->insertion_mode}' state." ); } @@ -1042,7 +1040,7 @@ private function step_before_head() { * * @return bool Whether an element was found. */ - private function step_in_head() { + private function step_in_head(): bool { $this->bail( "No support for parsing in the '{$this->state->insertion_mode}' state." ); } @@ -1061,7 +1059,7 @@ private function step_in_head() { * * @return bool Whether an element was found. */ - private function step_in_head_noscript() { + private function step_in_head_noscript(): bool { $this->bail( "No support for parsing in the '{$this->state->insertion_mode}' state." ); } @@ -1080,7 +1078,7 @@ private function step_in_head_noscript() { * * @return bool Whether an element was found. */ - private function step_after_head() { + private function step_after_head(): bool { $this->bail( "No support for parsing in the '{$this->state->insertion_mode}' state." ); } @@ -1722,7 +1720,7 @@ private function step_in_body(): bool { * * @return bool Whether an element was found. */ - private function step_in_table() { + private function step_in_table(): bool { $this->bail( "No support for parsing in the '{$this->state->insertion_mode}' state." ); } @@ -1741,7 +1739,7 @@ private function step_in_table() { * * @return bool Whether an element was found. */ - private function step_in_table_text() { + private function step_in_table_text(): bool { $this->bail( "No support for parsing in the '{$this->state->insertion_mode}' state." ); } @@ -1760,7 +1758,7 @@ private function step_in_table_text() { * * @return bool Whether an element was found. */ - private function step_in_caption() { + private function step_in_caption(): bool { $this->bail( "No support for parsing in the '{$this->state->insertion_mode}' state." ); } @@ -1779,7 +1777,7 @@ private function step_in_caption() { * * @return bool Whether an element was found. */ - private function step_in_column_group() { + private function step_in_column_group(): bool { $this->bail( "No support for parsing in the '{$this->state->insertion_mode}' state." ); } @@ -1798,7 +1796,7 @@ private function step_in_column_group() { * * @return bool Whether an element was found. */ - private function step_in_table_body() { + private function step_in_table_body(): bool { $this->bail( "No support for parsing in the '{$this->state->insertion_mode}' state." ); } @@ -1817,7 +1815,7 @@ private function step_in_table_body() { * * @return bool Whether an element was found. */ - private function step_in_row() { + private function step_in_row(): bool { $this->bail( "No support for parsing in the '{$this->state->insertion_mode}' state." ); } @@ -1836,7 +1834,7 @@ private function step_in_row() { * * @return bool Whether an element was found. */ - private function step_in_cell() { + private function step_in_cell(): bool { $this->bail( "No support for parsing in the '{$this->state->insertion_mode}' state." ); } @@ -1855,7 +1853,7 @@ private function step_in_cell() { * * @return bool Whether an element was found. */ - private function step_in_select() { + private function step_in_select(): bool { $token_name = $this->get_token_name(); $token_type = $this->get_token_type(); $op_sigil = '#tag' === $token_type ? ( parent::is_tag_closer() ? '-' : '+' ) : ''; @@ -2036,7 +2034,7 @@ private function step_in_select() { * * @return bool Whether an element was found. */ - private function step_in_select_in_table() { + private function step_in_select_in_table(): bool { $this->bail( "No support for parsing in the '{$this->state->insertion_mode}' state." ); } @@ -2055,7 +2053,7 @@ private function step_in_select_in_table() { * * @return bool Whether an element was found. */ - private function step_in_template() { + private function step_in_template(): bool { $this->bail( "No support for parsing in the '{$this->state->insertion_mode}' state." ); } @@ -2074,7 +2072,7 @@ private function step_in_template() { * * @return bool Whether an element was found. */ - private function step_after_body() { + private function step_after_body(): bool { $this->bail( "No support for parsing in the '{$this->state->insertion_mode}' state." ); } @@ -2093,7 +2091,7 @@ private function step_after_body() { * * @return bool Whether an element was found. */ - private function step_in_frameset() { + private function step_in_frameset(): bool { $this->bail( "No support for parsing in the '{$this->state->insertion_mode}' state." ); } @@ -2112,7 +2110,7 @@ private function step_in_frameset() { * * @return bool Whether an element was found. */ - private function step_after_frameset() { + private function step_after_frameset(): bool { $this->bail( "No support for parsing in the '{$this->state->insertion_mode}' state." ); } @@ -2131,7 +2129,7 @@ private function step_after_frameset() { * * @return bool Whether an element was found. */ - private function step_after_after_body() { + private function step_after_after_body(): bool { $this->bail( "No support for parsing in the '{$this->state->insertion_mode}' state." ); } @@ -2150,7 +2148,7 @@ private function step_after_after_body() { * * @return bool Whether an element was found. */ - private function step_after_after_frameset() { + private function step_after_after_frameset(): bool { $this->bail( "No support for parsing in the '{$this->state->insertion_mode}' state." ); } @@ -2169,7 +2167,7 @@ private function step_after_after_frameset() { * * @return bool Whether an element was found. */ - private function step_in_foreign_content() { + private function step_in_foreign_content(): bool { $this->bail( "No support for parsing in the '{$this->state->insertion_mode}' state." ); }