Skip to content

Commit

Permalink
Fix parse return type and return annotations
Browse files Browse the repository at this point in the history
  • Loading branch information
sirreal committed Nov 26, 2024
1 parent 750e9be commit e744dfc
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions src/wp-includes/html-api/class-wp-css-selectors.php
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,8 @@ protected static function parse_hash_token( string $input, int &$offset ): ?stri
* > Reconsume the current input code point. Return result.
*
* https://www.w3.org/TR/css-syntax-3/#consume-name
*
* @return string|null
*/
protected static function parse_ident( string $input, int &$offset ): ?string {
if ( ! self::check_if_three_code_points_would_start_an_ident_sequence( $input, $offset ) ) {
Expand Down Expand Up @@ -243,6 +245,8 @@ protected static function parse_ident( string $input, int &$offset ): ?string {
* This implementation will never return a <bad-string-token> because
* the <bad-string-token> is not a part of the selector grammar. That
* case is treated as failure to parse and null is returned.
*
* @return string|null
*/
protected static function parse_string( string $input, int &$offset ): ?string {
if ( $offset + 1 >= strlen( $input ) ) {
Expand Down Expand Up @@ -509,6 +513,8 @@ private function __construct( string $ident ) {
* > <id-selector> = <hash-token>
*
* https://www.w3.org/TR/selectors/#grammar
*
* @return self|null
*/
public static function parse( string $input, int &$offset ): ?self {
$ident = self::parse_hash_token( $input, $offset );
Expand All @@ -533,6 +539,8 @@ private function __construct( string $ident ) {
* > <class-selector> = '.' <ident-token>
*
* https://www.w3.org/TR/selectors/#grammar
*
* @return self|null
*/
public static function parse( string $input, int &$offset ): ?self {
if ( $offset + 1 >= strlen( $input ) || '.' !== $input[ $offset ] ) {
Expand Down Expand Up @@ -574,10 +582,12 @@ private function __construct( string $ident ) {
* so this selector effectively matches * or ident.
*
* https://www.w3.org/TR/selectors/#grammar
*
* @return self|null
*/
public static function parse( string $input, int &$offset ): ?self {
if ( $offset >= strlen( $input ) ) {
return false;
return null;
}

if ( '*' === $input[ $offset ] ) {
Expand Down Expand Up @@ -697,11 +707,13 @@ private function __construct( string $name, ?string $matcher = null, ?string $va
* Namespaces are not supported, so attribute names are effectively identifiers.
*
* https://www.w3.org/TR/selectors/#grammar
*
* @return self|null
*/
public static function parse( string $input, int &$offset ): ?self {
// Need at least 3 bytes [x]
if ( $offset + 2 >= strlen( $input ) ) {
return false;
return null;
}

$updated_offset = $offset;
Expand Down

0 comments on commit e744dfc

Please sign in to comment.