Skip to content

[TASK] Add native type declarations for CSSList #1181

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 17, 2025
Merged

Conversation

oliverklee
Copy link
Collaborator

Part of #811

@coveralls
Copy link

coveralls commented Mar 16, 2025

Coverage Status

coverage: 56.87%. remained the same
when pulling 885b3d2 on task/types/csslist
into c9d37e7 on main.

Copy link
Collaborator

@JakeQZ JakeQZ left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm wondering of some of the array<int, Type> DocBlock types can actually be list - or is there some usage preventing that?

@@ -41,7 +41,7 @@ abstract class CSSList implements Renderable, Commentable
protected $comments = [];

/**
* @var array<int, RuleSet|CSSList|Import|Charset>
* @var array<int<0, max>, RuleSet|CSSList|Import|Charset>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could this be a list?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately not: In remove(), we unset() elements in the array, which creates gaps in the keys.

@@ -364,10 +363,10 @@ public function setContents(array $contents): void
/**
* Removes a declaration block from the CSS list if it matches all given selectors.
*
* @param DeclarationBlock|array<array-key, Selector>|string $selectors the selectors to match
* @param DeclarationBlock|array<Selector>|string $selectors the selectors to match
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess array-key is redundant so can be removed, but also wonder if the middle type could be a list...

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It could in theory. However, this being a list is not required for the method to work correctly. As this method is public API, I'd prefer to keep it as broad as possible in order to reduce hassle for the developers who use it.


/**
* Returns the stored items.
*
* @return array<int, RuleSet|Import|Charset|CSSList>
* @return array<int<0, max>, RuleSet|Import|Charset|CSSList>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can it be a list?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, as $this->contents may have gaps in the keys due to the unset() in ::remove().

@oliverklee oliverklee requested a review from JakeQZ March 17, 2025 09:42
@JakeQZ JakeQZ merged commit fcaea55 into main Mar 17, 2025
21 checks passed
@JakeQZ JakeQZ deleted the task/types/csslist branch March 17, 2025 10:25
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.

3 participants