Skip to content

Commit

Permalink
Document complex selector class
Browse files Browse the repository at this point in the history
  • Loading branch information
sirreal committed Dec 9, 2024
1 parent ca1a129 commit 71fd62a
Showing 1 changed file with 20 additions and 10 deletions.
30 changes: 20 additions & 10 deletions src/wp-includes/html-api/class-wp-css-complex-selector.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@
/**
* CSS complex selector.
*
* This class implements a CSS complex selector and is used to test for matching HTML tags
* in a {@see WP_HTML_Tag_Processor}.
* This class is used to test for matching HTML tags in a {@see WP_HTML_Processor}.
*
* A complex selector is a selector with zero or more combinator-selector pairs.
* A compound selector is at least a single compound selector. There may be additional selectors
* with combinators.
*
* @since TBD
*
Expand Down Expand Up @@ -106,8 +106,10 @@ final class WP_CSS_Complex_Selector implements WP_CSS_HTML_Processor_Matcher {
public $context_selectors;

/**
* @param WP_CSS_Compound_Selector $self_selector
* @param array{WP_CSS_Type_Selector, string}[]|null $selectors
* Constructor.
*
* @param WP_CSS_Compound_Selector $self_selector The selector in the final position.
* @param array{WP_CSS_Type_Selector, string}[]|null $selectors The context selectors.
*/
public function __construct(
WP_CSS_Compound_Selector $self_selector,
Expand All @@ -133,16 +135,15 @@ public function matches( WP_HTML_Processor $processor ): bool {
return true;
}

/** @var string[] */
$breadcrumbs = array_slice( array_reverse( $processor->get_breadcrumbs() ), 1 );
return $this->explore_matches( $this->context_selectors, $breadcrumbs );
}

/**
* Checks for matches recursively comparing context selectors with breadcrumbs.
* Checks for matches by recursively comparing context selectors with breadcrumbs.
*
* @param array{WP_CSS_Type_Selector, string}[] $selectors
* @param string[] $breadcrumbs
* @param array{WP_CSS_Type_Selector, string}[] $selectors Selectors to match.
* @param string[] $breadcrumbs Breadcrumbs.
* @return bool True if a match is found, otherwise false.
*/
private function explore_matches( array $selectors, array $breadcrumbs ): bool {
Expand Down Expand Up @@ -176,7 +177,16 @@ private function explore_matches( array $selectors, array $breadcrumbs ): bool {
return false;

default:
throw new Exception( "Unsupported combinator '{$combinator}' found." );
_doing_it_wrong(
__METHOD__,
sprintf(
// translators: %s: A CSS selector combinator like ">" or "+".
__( 'Unsupported combinator "%s" found.' ),
$combinator
),
'6.8.0'
);
return false;
}
}
}

0 comments on commit 71fd62a

Please sign in to comment.