- Timestamp:
- 07/19/2024 11:42:14 PM (17 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/html-api/class-wp-html-processor.php
r58742 r58769 160 160 * @var WP_HTML_Processor_State 161 161 */ 162 private $state = null;162 private $state; 163 163 164 164 /** … … 209 209 * @since 6.4.0 210 210 * 211 * @var closure211 * @var Closure|null 212 212 */ 213 213 private $release_internal_bookmark_on_destruct = null; … … 369 369 370 370 $this->state->stack_of_open_elements->set_push_handler( 371 function ( WP_HTML_Token $token ) {371 function ( WP_HTML_Token $token ): void { 372 372 $is_virtual = ! isset( $this->state->current_token ) || $this->is_tag_closer(); 373 373 $same_node = isset( $this->state->current_token ) && $token->node_name === $this->state->current_token->node_name; … … 378 378 379 379 $this->state->stack_of_open_elements->set_pop_handler( 380 function ( WP_HTML_Token $token ) {380 function ( WP_HTML_Token $token ): void { 381 381 $is_virtual = ! isset( $this->state->current_token ) || ! $this->is_tag_closer(); 382 382 $same_node = isset( $this->state->current_token ) && $token->node_name === $this->state->current_token->node_name; … … 391 391 * exposing it to any public API. 392 392 */ 393 $this->release_internal_bookmark_on_destruct = function ( $name ){393 $this->release_internal_bookmark_on_destruct = function ( string $name ): void { 394 394 parent::release_bookmark( $name ); 395 395 }; … … 404 404 * 405 405 * @param string $message Explains support is missing in order to parse the current node. 406 *407 * @return mixed408 406 */ 409 407 private function bail( string $message ) { … … 458 456 * @return string|null The last error, if one exists, otherwise null. 459 457 */ 460 public function get_last_error() {458 public function get_last_error(): ?string { 461 459 return $this->last_error; 462 460 } … … 501 499 * @return bool Whether a tag was matched. 502 500 */ 503 public function next_tag( $query = null ) {501 public function next_tag( $query = null ): bool { 504 502 $visit_closers = isset( $query['tag_closers'] ) && 'visit' === $query['tag_closers']; 505 503 … … 591 589 * @return bool 592 590 */ 593 public function next_token() {591 public function next_token(): bool { 594 592 $this->current_element = null; 595 593 … … 644 642 } 645 643 646 647 644 /** 648 645 * Indicates if the current tag token is a tag closer. … … 661 658 * @return bool Whether the current tag is a tag closer. 662 659 */ 663 public function is_tag_closer() {660 public function is_tag_closer(): bool { 664 661 return $this->is_virtual() 665 662 ? ( WP_HTML_Stack_Event::POP === $this->current_element->operation && '#tag' === $this->get_token_type() ) … … 675 672 * @return bool Whether the current token is virtual. 676 673 */ 677 private function is_virtual() {674 private function is_virtual(): bool { 678 675 return ( 679 676 isset( $this->current_element->provenance ) && … … 707 704 * @return bool Whether the currently-matched tag is found at the given nested structure. 708 705 */ 709 public function matches_breadcrumbs( $breadcrumbs ) {706 public function matches_breadcrumbs( $breadcrumbs ): bool { 710 707 // Everything matches when there are zero constraints. 711 708 if ( 0 === count( $breadcrumbs ) ) { … … 758 755 * or `null` if not matched on any token. 759 756 */ 760 public function expects_closer( $node = null ) {757 public function expects_closer( $node = null ): ?bool { 761 758 $token_name = $node->node_name ?? $this->get_token_name(); 762 759 if ( ! isset( $token_name ) ) { … … 789 786 * @return bool Whether a tag was matched. 790 787 */ 791 public function step( $node_to_process = self::PROCESS_NEXT_NODE ) {788 public function step( $node_to_process = self::PROCESS_NEXT_NODE ): bool { 792 789 // Refuse to proceed if there was a previous error. 793 790 if ( null !== $this->last_error ) { … … 939 936 * @return string[]|null Array of tag names representing path to matched node, if matched, otherwise NULL. 940 937 */ 941 public function get_breadcrumbs() {938 public function get_breadcrumbs(): ?array { 942 939 return $this->breadcrumbs; 943 940 } … … 968 965 * @return int Nesting-depth of current location in the document. 969 966 */ 970 public function get_current_depth() {967 public function get_current_depth(): int { 971 968 return count( $this->breadcrumbs ); 972 969 } … … 987 984 * @return bool Whether an element was found. 988 985 */ 989 private function step_initial() {986 private function step_initial(): bool { 990 987 $this->bail( "No support for parsing in the '{$this->state->insertion_mode}' state." ); 991 988 } … … 1006 1003 * @return bool Whether an element was found. 1007 1004 */ 1008 private function step_before_html() {1005 private function step_before_html(): bool { 1009 1006 $this->bail( "No support for parsing in the '{$this->state->insertion_mode}' state." ); 1010 1007 } … … 1025 1022 * @return bool Whether an element was found. 1026 1023 */ 1027 private function step_before_head() {1024 private function step_before_head(): bool { 1028 1025 $this->bail( "No support for parsing in the '{$this->state->insertion_mode}' state." ); 1029 1026 } … … 1044 1041 * @return bool Whether an element was found. 1045 1042 */ 1046 private function step_in_head() {1043 private function step_in_head(): bool { 1047 1044 $this->bail( "No support for parsing in the '{$this->state->insertion_mode}' state." ); 1048 1045 } … … 1063 1060 * @return bool Whether an element was found. 1064 1061 */ 1065 private function step_in_head_noscript() {1062 private function step_in_head_noscript(): bool { 1066 1063 $this->bail( "No support for parsing in the '{$this->state->insertion_mode}' state." ); 1067 1064 } … … 1082 1079 * @return bool Whether an element was found. 1083 1080 */ 1084 private function step_after_head() {1081 private function step_after_head(): bool { 1085 1082 $this->bail( "No support for parsing in the '{$this->state->insertion_mode}' state." ); 1086 1083 } … … 1101 1098 * @return bool Whether an element was found. 1102 1099 */ 1103 private function step_in_body() {1100 private function step_in_body(): bool { 1104 1101 $token_name = $this->get_token_name(); 1105 1102 $token_type = $this->get_token_type(); … … 1724 1721 * @return bool Whether an element was found. 1725 1722 */ 1726 private function step_in_table() {1723 private function step_in_table(): bool { 1727 1724 $this->bail( "No support for parsing in the '{$this->state->insertion_mode}' state." ); 1728 1725 } … … 1743 1740 * @return bool Whether an element was found. 1744 1741 */ 1745 private function step_in_table_text() {1742 private function step_in_table_text(): bool { 1746 1743 $this->bail( "No support for parsing in the '{$this->state->insertion_mode}' state." ); 1747 1744 } … … 1762 1759 * @return bool Whether an element was found. 1763 1760 */ 1764 private function step_in_caption() {1761 private function step_in_caption(): bool { 1765 1762 $this->bail( "No support for parsing in the '{$this->state->insertion_mode}' state." ); 1766 1763 } … … 1781 1778 * @return bool Whether an element was found. 1782 1779 */ 1783 private function step_in_column_group() {1780 private function step_in_column_group(): bool { 1784 1781 $this->bail( "No support for parsing in the '{$this->state->insertion_mode}' state." ); 1785 1782 } … … 1800 1797 * @return bool Whether an element was found. 1801 1798 */ 1802 private function step_in_table_body() {1799 private function step_in_table_body(): bool { 1803 1800 $this->bail( "No support for parsing in the '{$this->state->insertion_mode}' state." ); 1804 1801 } … … 1819 1816 * @return bool Whether an element was found. 1820 1817 */ 1821 private function step_in_row() {1818 private function step_in_row(): bool { 1822 1819 $this->bail( "No support for parsing in the '{$this->state->insertion_mode}' state." ); 1823 1820 } … … 1838 1835 * @return bool Whether an element was found. 1839 1836 */ 1840 private function step_in_cell() {1837 private function step_in_cell(): bool { 1841 1838 $this->bail( "No support for parsing in the '{$this->state->insertion_mode}' state." ); 1842 1839 } … … 1857 1854 * @return bool Whether an element was found. 1858 1855 */ 1859 private function step_in_select() {1856 private function step_in_select(): bool { 1860 1857 $token_name = $this->get_token_name(); 1861 1858 $token_type = $this->get_token_type(); … … 2038 2035 * @return bool Whether an element was found. 2039 2036 */ 2040 private function step_in_select_in_table() {2037 private function step_in_select_in_table(): bool { 2041 2038 $this->bail( "No support for parsing in the '{$this->state->insertion_mode}' state." ); 2042 2039 } … … 2057 2054 * @return bool Whether an element was found. 2058 2055 */ 2059 private function step_in_template() {2056 private function step_in_template(): bool { 2060 2057 $this->bail( "No support for parsing in the '{$this->state->insertion_mode}' state." ); 2061 2058 } … … 2076 2073 * @return bool Whether an element was found. 2077 2074 */ 2078 private function step_after_body() {2075 private function step_after_body(): bool { 2079 2076 $this->bail( "No support for parsing in the '{$this->state->insertion_mode}' state." ); 2080 2077 } … … 2095 2092 * @return bool Whether an element was found. 2096 2093 */ 2097 private function step_in_frameset() {2094 private function step_in_frameset(): bool { 2098 2095 $this->bail( "No support for parsing in the '{$this->state->insertion_mode}' state." ); 2099 2096 } … … 2114 2111 * @return bool Whether an element was found. 2115 2112 */ 2116 private function step_after_frameset() {2113 private function step_after_frameset(): bool { 2117 2114 $this->bail( "No support for parsing in the '{$this->state->insertion_mode}' state." ); 2118 2115 } … … 2133 2130 * @return bool Whether an element was found. 2134 2131 */ 2135 private function step_after_after_body() {2132 private function step_after_after_body(): bool { 2136 2133 $this->bail( "No support for parsing in the '{$this->state->insertion_mode}' state." ); 2137 2134 } … … 2152 2149 * @return bool Whether an element was found. 2153 2150 */ 2154 private function step_after_after_frameset() {2151 private function step_after_after_frameset(): bool { 2155 2152 $this->bail( "No support for parsing in the '{$this->state->insertion_mode}' state." ); 2156 2153 } … … 2171 2168 * @return bool Whether an element was found. 2172 2169 */ 2173 private function step_in_foreign_content() {2170 private function step_in_foreign_content(): bool { 2174 2171 $this->bail( "No support for parsing in the '{$this->state->insertion_mode}' state." ); 2175 2172 } … … 2223 2220 * @return string|null Name of currently matched tag in input HTML, or `null` if none found. 2224 2221 */ 2225 public function get_tag() {2222 public function get_tag(): ?string { 2226 2223 if ( null !== $this->last_error ) { 2227 2224 return null; … … 2264 2261 * @return bool Whether the currently matched tag contains the self-closing flag. 2265 2262 */ 2266 public function has_self_closing_flag() {2263 public function has_self_closing_flag(): bool { 2267 2264 return $this->is_virtual() ? false : parent::has_self_closing_flag(); 2268 2265 } … … 2288 2285 * @return string|null Name of the matched token. 2289 2286 */ 2290 public function get_token_name() {2287 public function get_token_name(): ?string { 2291 2288 return $this->is_virtual() 2292 2289 ? $this->current_element->token->node_name … … 2316 2313 * @return string|null What kind of token is matched, or null. 2317 2314 */ 2318 public function get_token_type() {2315 public function get_token_type(): ?string { 2319 2316 if ( $this->is_virtual() ) { 2320 2317 /* … … 2378 2375 * @return bool Whether an attribute value was set. 2379 2376 */ 2380 public function set_attribute( $name, $value ) {2377 public function set_attribute( $name, $value ): bool { 2381 2378 return $this->is_virtual() ? false : parent::set_attribute( $name, $value ); 2382 2379 } … … 2390 2387 * @return bool Whether an attribute was removed. 2391 2388 */ 2392 public function remove_attribute( $name ) {2389 public function remove_attribute( $name ): bool { 2393 2390 return $this->is_virtual() ? false : parent::remove_attribute( $name ); 2394 2391 } … … 2420 2417 * @return array|null List of attribute names, or `null` when no tag opener is matched. 2421 2418 */ 2422 public function get_attribute_names_with_prefix( $prefix ) {2419 public function get_attribute_names_with_prefix( $prefix ): ?array { 2423 2420 return $this->is_virtual() ? null : parent::get_attribute_names_with_prefix( $prefix ); 2424 2421 } … … 2432 2429 * @return bool Whether the class was set to be added. 2433 2430 */ 2434 public function add_class( $class_name ) {2431 public function add_class( $class_name ): bool { 2435 2432 return $this->is_virtual() ? false : parent::add_class( $class_name ); 2436 2433 } … … 2444 2441 * @return bool Whether the class was set to be removed. 2445 2442 */ 2446 public function remove_class( $class_name ) {2443 public function remove_class( $class_name ): bool { 2447 2444 return $this->is_virtual() ? false : parent::remove_class( $class_name ); 2448 2445 } … … 2456 2453 * @return bool|null Whether the matched tag contains the given class name, or null if not matched. 2457 2454 */ 2458 public function has_class( $wanted_class ) {2455 public function has_class( $wanted_class ): ?bool { 2459 2456 return $this->is_virtual() ? null : parent::has_class( $wanted_class ); 2460 2457 } … … 2500 2497 * @return string 2501 2498 */ 2502 public function get_modifiable_text() {2499 public function get_modifiable_text(): string { 2503 2500 return $this->is_virtual() ? '' : parent::get_modifiable_text(); 2504 2501 } … … 2523 2520 * @return string|null 2524 2521 */ 2525 public function get_comment_type() {2522 public function get_comment_type(): ?string { 2526 2523 return $this->is_virtual() ? null : parent::get_comment_type(); 2527 2524 } … … 2538 2535 * @return bool Whether the bookmark already existed before removal. 2539 2536 */ 2540 public function release_bookmark( $bookmark_name ) {2537 public function release_bookmark( $bookmark_name ): bool { 2541 2538 return parent::release_bookmark( "_{$bookmark_name}" ); 2542 2539 } … … 2559 2556 * @return bool Whether the internal cursor was successfully moved to the bookmark's location. 2560 2557 */ 2561 public function seek( $bookmark_name ) {2558 public function seek( $bookmark_name ): bool { 2562 2559 // Flush any pending updates to the document before beginning. 2563 2560 $this->get_updated_html(); … … 2730 2727 * @return bool Whether the bookmark was successfully created. 2731 2728 */ 2732 public function set_bookmark( $bookmark_name ) {2729 public function set_bookmark( $bookmark_name ): bool { 2733 2730 return parent::set_bookmark( "_{$bookmark_name}" ); 2734 2731 } … … 2742 2739 * @return bool Whether that bookmark exists. 2743 2740 */ 2744 public function has_bookmark( $bookmark_name ) {2741 public function has_bookmark( $bookmark_name ): bool { 2745 2742 return parent::has_bookmark( "_{$bookmark_name}" ); 2746 2743 } … … 2759 2756 * @see https://html.spec.whatwg.org/#close-a-p-element 2760 2757 */ 2761 private function close_a_p_element() {2758 private function close_a_p_element(): void { 2762 2759 $this->generate_implied_end_tags( 'P' ); 2763 2760 $this->state->stack_of_open_elements->pop_until( 'P' ); … … 2774 2771 * @param string|null $except_for_this_element Perform as if this element doesn't exist in the stack of open elements. 2775 2772 */ 2776 private function generate_implied_end_tags( $except_for_this_element = null ){2773 private function generate_implied_end_tags( ?string $except_for_this_element = null ): void { 2777 2774 $elements_with_implied_end_tags = array( 2778 2775 'DD', … … 2810 2807 * @see https://html.spec.whatwg.org/#generate-implied-end-tags 2811 2808 */ 2812 private function generate_implied_end_tags_thoroughly() {2809 private function generate_implied_end_tags_thoroughly(): void { 2813 2810 $elements_with_implied_end_tags = array( 2814 2811 'CAPTION', … … 2852 2849 * @return bool Whether any formatting elements needed to be reconstructed. 2853 2850 */ 2854 private function reconstruct_active_formatting_elements() {2851 private function reconstruct_active_formatting_elements(): bool { 2855 2852 /* 2856 2853 * > If there are no entries in the list of active formatting elements, then there is nothing … … 3075 3072 * @see https://html.spec.whatwg.org/#adoption-agency-algorithm 3076 3073 */ 3077 private function run_adoption_agency_algorithm() {3074 private function run_adoption_agency_algorithm(): void { 3078 3075 $budget = 1000; 3079 3076 $subject = $this->get_tag(); … … 3183 3180 * @param WP_HTML_Token $token Name of bookmark pointing to element in original input HTML. 3184 3181 */ 3185 private function insert_html_element( $token ){3182 private function insert_html_element( WP_HTML_Token $token ): void { 3186 3183 $this->state->stack_of_open_elements->push( $token ); 3187 3184 } … … 3201 3198 * @return bool Whether the element of the given name is in the special category. 3202 3199 */ 3203 public static function is_special( $tag_name ) {3200 public static function is_special( $tag_name ): bool { 3204 3201 $tag_name = strtoupper( $tag_name ); 3205 3202 … … 3316 3313 * @return bool Whether the given tag is an HTML Void Element. 3317 3314 */ 3318 public static function is_void( $tag_name ) {3315 public static function is_void( $tag_name ): bool { 3319 3316 $tag_name = strtoupper( $tag_name ); 3320 3317
Note: See TracChangeset
for help on using the changeset viewer.