Skip to content
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

Add support for @throws annotation #994

Merged
merged 4 commits into from May 10, 2018
Merged

Conversation

pepakriz
Copy link
Contributor

@pepakriz pepakriz commented May 8, 2018

No description provided.

public function throwRuntimeException();

/**
* @throws RuntimeException|LogicException
Copy link
Contributor

Choose a reason for hiding this comment

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

This syntax is not valid.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks, you are right. I saw this syntax in some library and phpstorm supports it too. But better to be strict...

Copy link
Contributor

Choose a reason for hiding this comment

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

@Majkl578 I don't understand. Why is it not valid? What am I missing?

Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor

@JanTvrdik JanTvrdik May 8, 2018

Choose a reason for hiding this comment

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

@Majkl578 I've read that and I don't think it disallows RuntimeException|LogicException, because it is a type that „represent an object of the class Exception or any subclass thereof.“

@Majkl578
Copy link
Contributor

Majkl578 commented May 8, 2018

I really like the idea of tracking exceptions.
But in order to make this really useful and not full of false positives, this would ned some mechanism to distinguish exceptions meant to be caught and those meant not to. Similar to checked exceptions in Java.
I am not sure whether Error/Exception and/or RuntimeException/LogicException trees would be sufficient in this task.

@pepakriz
Copy link
Contributor Author

pepakriz commented May 8, 2018

@Majkl578 Exception tracking is task for some rules. Look at my PoC https://github.com/pepakriz/phpstan-exception-rules . Over time it could be part of phpstan-strict-rules or something...

But at first, I need support for @throws annotations in MethodReflection.

@Majkl578
Copy link
Contributor

Majkl578 commented May 8, 2018

Yes I understand. :) Just thinking out loud. I.e. how to mark the exception as checked/unchecked, that would probably need some tracking too.
Would be nice in strict-rules one day.

@ondrejmirtes
Copy link
Member

ondrejmirtes commented May 8, 2018 via email

return $tag->value instanceof ThrowsTagValueNode;
}),
'value'
);
Copy link
Contributor

@JanTvrdik JanTvrdik May 8, 2018

Choose a reason for hiding this comment

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

This should use currently unavailable $phpDocNode->getThrowsTagValues(). Send PR to https://github.com/phpstan/phpdoc-parser

Copy link
Contributor Author

@pepakriz pepakriz May 9, 2018

Choose a reason for hiding this comment

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

Done: phpstan/phpdoc-parser#12

I will rebase after merge

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, it's ready

@ondrejmirtes
Copy link
Member

Thank you! I'd merge this, but there needs to be cache version bump in FileTypeMapper.php 😊 Then it will be good to go.

@pepakriz
Copy link
Contributor Author

@ondrejmirtes it's ready now, including cache bump. Thanks!

@ondrejmirtes ondrejmirtes merged commit 9788a6c into phpstan:master May 10, 2018
@ondrejmirtes
Copy link
Member

Thanks!

@pepakriz pepakriz deleted the throws branch May 11, 2018 05:20
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.

None yet

4 participants