Skip to content

Commit 205e919

Browse files
committed
Use false rather than null when a parser subtree doesn't match
1 parent 96dd467 commit 205e919

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

wp-includes/parser/class-wp-parser.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,14 @@ public function __construct( WP_Parser_Grammar $grammar, array $tokens ) {
2222
public function parse() {
2323
// @TODO: Make the starting rule lookup non-grammar-specific.
2424
$query_rule_id = $this->grammar->get_rule_id( 'query' );
25-
return $this->parse_recursive( $query_rule_id );
25+
return $this->parse_recursive( $query_rule_id ) ?: null;
2626
}
2727

2828
private function parse_recursive( $rule_id ) {
2929
$is_terminal = $rule_id <= $this->grammar->highest_terminal_id;
3030
if ( $is_terminal ) {
3131
if ( $this->position >= count( $this->tokens ) ) {
32-
return null;
32+
return false;
3333
}
3434

3535
if ( WP_Parser_Grammar::EMPTY_RULE_ID === $rule_id ) {
@@ -40,12 +40,12 @@ private function parse_recursive( $rule_id ) {
4040
++$this->position;
4141
return $this->tokens[ $this->position - 1 ];
4242
}
43-
return null;
43+
return false;
4444
}
4545

4646
$branches = $this->grammar->rules[ $rule_id ];
4747
if ( ! count( $branches ) ) {
48-
return null;
48+
return false;
4949
}
5050

5151
// Bale out from processing the current branch if none of its rules can
@@ -56,7 +56,7 @@ private function parse_recursive( $rule_id ) {
5656
! isset( $this->grammar->lookahead_is_match_possible[ $rule_id ][ $token_id ] ) &&
5757
! isset( $this->grammar->lookahead_is_match_possible[ $rule_id ][ WP_Parser_Grammar::EMPTY_RULE_ID ] )
5858
) {
59-
return null;
59+
return false;
6060
}
6161
}
6262

@@ -68,7 +68,7 @@ private function parse_recursive( $rule_id ) {
6868
$branch_matches = true;
6969
foreach ( $branch as $subrule_id ) {
7070
$subnode = $this->parse_recursive( $subrule_id );
71-
if ( null === $subnode ) {
71+
if ( false === $subnode ) {
7272
$branch_matches = false;
7373
break;
7474
} elseif ( true === $subnode ) {
@@ -111,7 +111,7 @@ private function parse_recursive( $rule_id ) {
111111

112112
if ( ! $branch_matches ) {
113113
$this->position = $starting_position;
114-
return null;
114+
return false;
115115
}
116116

117117
if ( 0 === count( $node->children ) ) {

0 commit comments

Comments
 (0)