Skip to content

Refactor TryRemove/Accepts for DateTime|DateTimeImmutable and Exception|Error #3654

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 6 commits into from
Nov 22, 2024

Conversation

VincentLanglet
Copy link
Contributor

@VincentLanglet VincentLanglet commented Nov 22, 2024

public const EQUAL_UNION_CLASSES = [
DateTimeInterface::class => [DateTimeImmutable::class, DateTime::class],
Throwable::class => [Error::class, Exception::class],
Traversable::class => [IteratorAggregate::class, Iterator::class],
];
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not sure if I need to put this constant somewhere else (like UnionTypeHelper) / as a static function or with a better naming.

I support any number of classes in values, just in case.

@VincentLanglet VincentLanglet marked this pull request as draft November 22, 2024 10:06
@stof
Copy link
Contributor

stof commented Nov 22, 2024

shouldn't this be implemented through the mechanism of AllowedSubTypesClassReflectionExtension::getAllowedSubTypes instead of this special handling ?

@ondrejmirtes
Copy link
Member

@stof We tried that but it didn't work for some reason. I think that rules reading the "allowed subtypes" extensions would report some unwanted errors.

@VincentLanglet VincentLanglet marked this pull request as ready for review November 22, 2024 11:36
@phpstan-bot
Copy link
Collaborator

This pull request has been marked as ready for review.

public const EQUAL_UNION_CLASSES = [
DateTimeInterface::class => [DateTimeImmutable::class, DateTime::class],
Throwable::class => [Error::class, Exception::class], // phpcs:ignore SlevomatCodingStandard.Exceptions.ReferenceThrowableOnly.ReferencedGeneralException
Traversable::class => [IteratorAggregate::class, Iterator::class],
Copy link
Member

Choose a reason for hiding this comment

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

I'd accept part of this PR - the refactoring into this constant. Without addition of the Traversable entry.

@VincentLanglet VincentLanglet changed the title Describe Traversable as Iterator|IteratorAggregate Refactor TryRemove/Accepts for DateTime|DateTimeImmutable and Exception|Error Nov 22, 2024
@ondrejmirtes ondrejmirtes changed the base branch from 1.12.x to 2.0.x November 22, 2024 14:07
@ondrejmirtes
Copy link
Member

I changed the base to 2.0.x, please fix the confict. Thanks.

@VincentLanglet
Copy link
Contributor Author

I changed the base to 2.0.x, please fix the confict. Thanks.

Done

@ondrejmirtes ondrejmirtes merged commit c0bfae6 into phpstan:2.0.x Nov 22, 2024
425 of 426 checks passed
@ondrejmirtes
Copy link
Member

Thank you.

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.

Traversable should be considered as Iterator|IteratorAggregate
4 participants