Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,6 @@ includes:
- tests/phpstan/baselines/function.alreadyNarrowedType.neon
- tests/phpstan/baselines/function.impossibleType.neon
- tests/phpstan/baselines/function.resultUnused.neon
- tests/phpstan/baselines/greater.alwaysTrue.neon
- tests/phpstan/baselines/greaterOrEqual.alwaysFalse.neon
- tests/phpstan/baselines/greaterOrEqual.alwaysTrue.neon
- tests/phpstan/baselines/identical.alwaysFalse.neon
- tests/phpstan/baselines/identical.alwaysTrue.neon
Expand Down Expand Up @@ -152,3 +150,16 @@ parameters:
message: '#^Parameter \#4 \$length of function substr_compare expects int, null given\.$#'
path: src/wp-includes/html-api/class-wp-html-tag-processor.php
reportUnmatched: false

# HTML API:
# These errors are ignored for the sake of making it easier to keep the HTML Processor in sync with the HTML spec.
-
message: '#^Comparison operation "\>" between 999\|1000 and 0 is always true\.$#'
identifier: greater.alwaysTrue
count: 1
path: src/wp-includes/html-api/class-wp-html-processor.php
-
message: '#^Comparison operation "\>\=" between 0 and 8 is always false\.$#'
identifier: greaterOrEqual.alwaysFalse
count: 1
path: src/wp-includes/html-api/class-wp-html-processor.php
85 changes: 28 additions & 57 deletions src/wp-includes/html-api/class-wp-html-processor.php
Original file line number Diff line number Diff line change
Expand Up @@ -1585,7 +1585,6 @@ private function step_initial(): bool {
return $this->step();
}
goto initial_anything_else;
break;

/*
* > A comment token
Expand Down Expand Up @@ -1678,7 +1677,6 @@ private function step_before_html(): bool {
return $this->step();
}
goto before_html_anything_else;
break;

/*
* > A start tag whose tag name is "html"
Expand All @@ -1700,7 +1698,6 @@ private function step_before_html(): bool {
* > Act as described in the "anything else" entry below.
*/
goto before_html_anything_else;
break;
}

/*
Expand Down Expand Up @@ -1760,7 +1757,6 @@ private function step_before_head(): bool {
return $this->step();
}
goto before_head_anything_else;
break;

/*
* > A comment token
Expand Down Expand Up @@ -1805,7 +1801,6 @@ private function step_before_head(): bool {
case '-BODY':
case '-HTML':
goto before_head_anything_else;
break;
}

if ( $is_closer ) {
Expand Down Expand Up @@ -1861,7 +1856,6 @@ private function step_in_head(): bool {
}

goto in_head_anything_else;
break;

/*
* > A comment token
Expand Down Expand Up @@ -1993,7 +1987,6 @@ private function step_in_head(): bool {
* > Act as described in the "anything else" entry below.
*/
goto in_head_anything_else;
break;

/*
* > A start tag whose tag name is "template"
Expand Down Expand Up @@ -2086,7 +2079,6 @@ private function step_in_head_noscript(): bool {
}

goto in_head_noscript_anything_else;
break;

/*
* > A DOCTYPE token
Expand Down Expand Up @@ -2190,7 +2182,6 @@ private function step_after_head(): bool {
return true;
}
goto after_head_anything_else;
break;

/*
* > A comment token
Expand Down Expand Up @@ -2279,7 +2270,6 @@ private function step_after_head(): bool {
* > Act as described in the "anything else" entry below.
*/
goto after_head_anything_else;
break;
}

/*
Expand Down Expand Up @@ -2783,28 +2773,27 @@ private function step_in_body(): bool {

$this->state->stack_of_open_elements->remove_node( $node );
return true;
} else {
/*
* > If the stack of open elements does not have a form element in scope,
* > then this is a parse error; return and ignore the token.
*
* Note that unlike in the clause above, this is checking for any FORM in scope.
*/
if ( ! $this->state->stack_of_open_elements->has_element_in_scope( 'FORM' ) ) {
// Parse error: ignore the token.
return $this->step();
}
}

$this->generate_implied_end_tags();
/*
* > If the stack of open elements does not have a form element in scope,
* > then this is a parse error; return and ignore the token.
*
* Note that unlike in the clause above, this is checking for any FORM in scope.
*/
if ( ! $this->state->stack_of_open_elements->has_element_in_scope( 'FORM' ) ) {
// Parse error: ignore the token.
return $this->step();
}

if ( ! $this->state->stack_of_open_elements->current_node_is( 'FORM' ) ) {
// @todo Indicate a parse error once it's possible. This error does not impact the logic here.
}
$this->generate_implied_end_tags();

$this->state->stack_of_open_elements->pop_until( 'FORM' );
return true;
if ( ! $this->state->stack_of_open_elements->current_node_is( 'FORM' ) ) {
// @todo Indicate a parse error once it's possible. This error does not impact the logic here.
}
break;

$this->state->stack_of_open_elements->pop_until( 'FORM' );
return true;

/*
* > An end tag whose tag name is "p"
Expand Down Expand Up @@ -3366,10 +3355,6 @@ private function step_in_body(): bool {
*/
return $this->in_body_any_other_end_tag();
}

$this->bail( 'Should not have been able to reach end of IN BODY processing. Check HTML API code.' );
// This unnecessary return prevents tools from inaccurately reporting type errors.
return false;
}

/**
Expand Down Expand Up @@ -3418,8 +3403,6 @@ private function in_body_any_other_end_tag(): bool {
}

$this->bail( 'Should not have been able to reach end of "any other end tag" IN BODY processing. Check HTML API code.' );
// This unnecessary return prevents tools from inaccurately reporting type errors.
return false;
}

/**
Expand Down Expand Up @@ -3496,7 +3479,6 @@ private function step_in_table(): bool {

// Non-whitespace would trigger fostering, unsupported at this time.
$this->bail( 'Foster parenting is not supported.' );
break;
}
break;

Expand Down Expand Up @@ -3821,7 +3803,6 @@ private function step_in_column_group(): bool {
}

goto in_column_group_anything_else;
break;

/*
* > A comment token
Expand Down Expand Up @@ -4382,7 +4363,6 @@ private function step_after_body(): bool {
return $this->step_in_body();
}
goto after_body_anything_else;
break;

/*
* > A comment token
Expand Down Expand Up @@ -4705,7 +4685,6 @@ private function step_after_after_body(): bool {
return $this->step_in_body();
}
goto after_after_body_anything_else;
break;
}

/*
Expand Down Expand Up @@ -4984,20 +4963,18 @@ private function step_in_foreign_content(): bool {
$this->state->stack_of_open_elements->pop();
}
return true;
}

/*
* > An end tag whose name is "script", if the current node is an SVG script element.
*/
if ( $this->is_tag_closer() && 'SCRIPT' === $this->state->current_token->node_name && 'svg' === $this->state->current_token->namespace ) {
$this->state->stack_of_open_elements->pop();
return true;
}
} else {
/*
* > An end tag whose name is "script", if the current node is an SVG script element.
*/
if ( 'SCRIPT' === $this->state->current_token->node_name && 'svg' === $this->state->current_token->namespace ) {
$this->state->stack_of_open_elements->pop();
return true;
}

/*
* > Any other end tag
*/
if ( $this->is_tag_closer() ) {
/*
* > Any other end tag
*/
$node = $this->state->stack_of_open_elements->current_node();
if ( $tag_name !== $node->node_name ) {
// @todo Indicate a parse error once it's possible.
Expand Down Expand Up @@ -5097,10 +5074,6 @@ private function step_in_foreign_content(): bool {
$this->bail( "Unaware of the requested parsing mode: '{$this->state->insertion_mode}'." );
}
}

$this->bail( 'Should not have been able to reach end of IN FOREIGN CONTENT processing. Check HTML API code.' );
// This unnecessary return prevents tools from inaccurately reporting type errors.
return false;
}

/*
Expand Down Expand Up @@ -6388,8 +6361,6 @@ private function is_html_integration_point(): bool {
}

$this->bail( 'Should not have reached end of HTML Integration Point detection: check HTML API code.' );
// This unnecessary return prevents tools from inaccurately reporting type errors.
return false;
}

/**
Expand Down
5 changes: 0 additions & 5 deletions tests/phpstan/baselines/booleanAnd.leftAlwaysTrue.neon
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,3 @@ parameters:
identifier: booleanAnd.leftAlwaysTrue
count: 1
path: ../../../src/wp-includes/canonical.php
-
message: '#^Left side of && is always true\.$#'
identifier: booleanAnd.leftAlwaysTrue
count: 1
path: ../../../src/wp-includes/html-api/class-wp-html-processor.php
2 changes: 1 addition & 1 deletion tests/phpstan/baselines/deadCode.unreachable.neon
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ parameters:
-
message: '#^Unreachable statement \- code above always terminates\.$#'
identifier: deadCode.unreachable
count: 31
count: 12
path: ../../../src/wp-includes/html-api/class-wp-html-processor.php
-
message: '#^Unreachable statement \- code above always terminates\.$#'
Expand Down
25 changes: 0 additions & 25 deletions tests/phpstan/baselines/greater.alwaysTrue.neon

This file was deleted.

25 changes: 0 additions & 25 deletions tests/phpstan/baselines/greaterOrEqual.alwaysFalse.neon

This file was deleted.

2 changes: 1 addition & 1 deletion tests/phpstan/baselines/if.alwaysTrue.neon
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,5 @@ parameters:
-
message: '#^If condition is always true\.$#'
identifier: if.alwaysTrue
count: 2
count: 1
path: ../../../src/wp-includes/html-api/class-wp-html-processor.php
Loading