Is it time to deprecate this project?
All features of this project are being ported to the phpstan itself. I don't know the current status but It looks like most features are done and we can mark this package deprecated/replaced.
I'm so happy that all users have a great and official replacement. My current project that I'm working on is not PHP-based, so I've not been focused on improving this package for a long time. And secondly, I'm not a proponent of the opinion that exceptions should be used for controlling application flow.
Either way, some people like this principle. So I welcome that they have an official way how to handle exceptions by static analysis.
Please @ondrejmirtes @VincentLanglet let me know when PHPStan will be ready. I'll add some info to the readme.
My plan was to deprecate this project indeed. I made multiple PR recently to move the DynamicThrowExtension to phpstan-src.
I wanted to try to do the migration on my project first in order to check if all the feature proposed by this library could be done in a way or another in the original phpstan repository. I just need some time ^^'
Hi, currently the rules in PHPStan are not exactly 1:1 with this package. If my plan was to copy them 1:1, i wouldn't do that and just forward people to this package :)
I thought that the remaining rules and behaviour I'm not interested in could be continued to be maintained here, maybe refactored with some help from PHPStan internals so that it doesn't do any weird magic with modifying the AST.
What I don't want to add to PHPStan core:
- https://github.com/pepakriz/phpstan-exception-rules/blob/master/tests/src/Rules/data/dead-catch-union.php - PHPStan just sees the final normalized type, it doesn't work with the types from the AST
- Unused
@throwslike here https://github.com/pepakriz/phpstan-exception-rules/blob/master/tests/src/Rules/data/method-whitelisting.php - people are free to add unchecked exceptions because it might be required for precise try-catch-finally analysis. I think it's fine to catch and rethrow unchecked exceptions. - https://github.com/pepakriz/phpstan-exception-rules/blob/master/tests/src/Rules/data/throws-in-global-scope.php
- https://github.com/pepakriz/phpstan-exception-rules/blob/master/tests/src/Rules/data/try-catch.php - this is really weird and I don't understand it, I think that "Catching checked exception RuntimeException as unchecked Throwable" is totally fine
- https://github.com/pepakriz/phpstan-exception-rules/blob/master/tests/src/Rules/data/useless-throws.php - PHPStan just sees the final normalized type
What's currently missing in PHPStan and should be added:
- https://github.com/pepakriz/phpstan-exception-rules/blob/master/tests/src/Rules/data/iterators.php (
Foreach_handling needs to be modified in NodeScopeResolver) - Checking
@throwscovariance for LSP - https://github.com/pepakriz/phpstan-exception-rules/blob/master/tests/src/Rules/data/throws-php-internal-operators.php
And about the help from internals - this package could read the ThrowPoints from MethodReturnStatementsNode and FunctionReturnStatementsNode.
What I don't want to add to PHPStan core:
- Unused @throws like here https://github.com/pepakriz/phpstan-exception-rules/blob/master/tests/src/Rules/data/method-whitelisting.php - people are free to add unchecked exceptions because it might be required for precise try-catch-finally analysis. I think it's fine to catch and rethrow unchecked exceptions.
Not a big loss, there was already some false positif with unchecked exception. So I think it's fine to catch and rethrow unchecked exceptions too.
What's currently missing in PHPStan and should be added:
- https://github.com/pepakriz/phpstan-exception-rules/blob/master/tests/src/Rules/data/iterators.php (
Foreach_handling needs to be modified in NodeScopeResolver)- Checking
@throwscovariance for LSP- https://github.com/pepakriz/phpstan-exception-rules/blob/master/tests/src/Rules/data/throws-php-internal-operators.php
IMHO after these, the librarie will lost 90% of his interest, and since there is already not a lot of maintenance, it will be better to deprecate it.
Also I'm not sure, but I think there is a big difference between phpstan and this extension, if I remember correctly.
This extension is reporting useless catch, but phpstan is considering that any exception can be throw when there is no @throws annotation. Isn't it ?
https://github.com/pepakriz/phpstan-exception-rules/blob/master/tests/src/Rules/data/unused-catches.php
that any exception can be throw when there is no
Not exactly. PHPStan detects dead @throws. But there's going to be a difference of what's reported with implicitThrows: true (the default) vs. implicitThrows: false. See: https://phpstan.org/blog/bring-your-exceptions-under-control#what-does-absent-%40throws-above-a-function-mean%3F
OK, i forgot about the implicitThrows option.
So this library was similar to phpstan with the option implicitThrows: true then.