Skip to content

Add non regression tests#5110

Merged
VincentLanglet merged 1 commit intophpstan:2.1.xfrom
VincentLanglet:pr5105
Mar 1, 2026
Merged

Add non regression tests#5110
VincentLanglet merged 1 commit intophpstan:2.1.xfrom
VincentLanglet:pr5105

Conversation

@VincentLanglet
Copy link
Contributor

Related to #5105

@phpstan-bot
Copy link
Collaborator

This pull request has been marked as ready for review.

{
try {
return ReactionType::{$name};
} catch (\RuntimeException) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
} catch (\RuntimeException) {
} catch (\RuntimeException) { // will throw ERROR on invalid $name

Comment on lines +26 to +30
try {
return ReactionType::{$name};
} catch (\Error) {
return null;
}
Copy link
Contributor

@staabm staabm Mar 1, 2026

Choose a reason for hiding this comment

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

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 after the condition line 22 ?

Copy link
Contributor

@staabm staabm Mar 1, 2026

Choose a reason for hiding this comment

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

you are right.


maybe we should add a test for

	public static function tryFromInvalid(string $name): ?self
	{
		try {
			return ReactionType::XYZ;
		} catch (\Error $e) {
			return null;
		}
	}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Currently it's not supported
https://phpstan.org/r/2b645c07-0bae-4dec-b0f1-1ce3012b0e8e

And it's like any method call

try {
			return self::acceptsString(true);
		} catch (\Error $e) {
			return null;
		}

we're currently reporting the method call as an error but also reporting the dead catch (if implictThrow = false)

@VincentLanglet VincentLanglet requested a review from staabm March 1, 2026 10:32
@VincentLanglet VincentLanglet merged commit db44384 into phpstan:2.1.x Mar 1, 2026
374 of 376 checks passed
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