Skip to content

add_cssclass: add conditional return type - #484

Merged
szepeviktor merged 1 commit into
php-stubs:masterfrom
IanDelMar:add_cssclass
Aug 24, 2026
Merged

add_cssclass: add conditional return type#484
szepeviktor merged 1 commit into
php-stubs:masterfrom
IanDelMar:add_cssclass

Conversation

@IanDelMar

Copy link
Copy Markdown
Contributor

add_cssclass():

 * @param string $class_to_add The CSS class to add.
 * @param string $classes      The string to add the CSS class to.
 * @return string The string with the CSS class added.
 */
function add_cssclass( $class_to_add, $classes ) {
	if ( empty( $classes ) ) {
		return $class_to_add;
	}

	return $classes . ' ' . $class_to_add;
}

Whenever $classes is an empty string $class_to_add is returned as is (template T). If $classes is not empty, $class_to_add is appended and returned. We therefore know, it's a non-empty-string. Further refinement would required a more complex conditional return type. The returned type depends on $classes (conditional type).

oracle-inspired

@szepeviktor
szepeviktor merged commit b6737c8 into php-stubs:master Aug 24, 2026
8 checks passed
@szepeviktor

Copy link
Copy Markdown
Member

oracle-inspired

👁️

@IanDelMar
IanDelMar deleted the add_cssclass branch August 25, 2026 08:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants