#2824: Automatically add to DocBlock comments the thrown \Throwables.#2833
#2824: Automatically add to DocBlock comments the thrown \Throwables.#2833TomasVotruba merged 7 commits intorectorphp:masterfrom Aerendir:2824-annotate-throwables
\Throwables.#2833Conversation
|
@TomasVotruba , I did a mess trying to sync the branch with master and I recreated it from scratch. It seems that it doesn't work anymore: the tests that once passed, now don't pass anymore. It is seems that the modifications are not get by Rector. The Any ideas about why? |
|
Can you allow me to push to the branch? |
|
I don't know how to push to your external branch. |
|
I sent you an invite |
|
@TomasVotruba in the mean time I understood how to use I don't know exactly what happened, but for sure the failing of the test was related to the fact I "hardly" updated the docblock comment without using the Now I'm going to check again the other tests that once passed... |
|
Great, I was making working demo for php doc info. It's only 5 lines instead of 40 :) I'm glad you made it work! Could you push it? |
|
@TomasVotruba just pushed! |
|
Just run |
Have you run |
|
@TomasVotruba , I think the PR is complete. I'm fixing the checks in CI. Can you, please, check the code is ok? |
|
@TomasVotruba , I've fixed as much errors as I can, but there are some for which I need your guidance as they are strictly related to Rector and I think there is already a "standard" approach to fix them. I'm waiting for your feedback. |
|
@TomasVotruba , I read all your comments: I will work on them ASAP. |
|
@TomasVotruba , regarding variables and factory method the things are really complex. Imagine this code: <?php
function createHttpException(int $statusCode) {
switch ($statusCode) {
case 404:
return new NotFoundException();
case 500:
return new InternalServerErrorException();
default:
return new ConnectionException();
}
}
/**
* @param string $url
*
* @throws ... What?
*/
function connect(string $url)
{
// do connection things
$response = ...;
// Imagine is 404
$status = $response->getStatus();
if (200 !== $status) {
throw createHttpException(404);
}
}Which is the thrown exception? All? And for more complex logics? And how can we understand the code to annotate the DocBlock? I've done an example with factory methods, but the same applies also to WDYT? |
I don't use it. What is common approach? |
|
Maybe we could solve complex annotations like this in next PR, so there is smaller scope to focus on and finished work |
Ok, let me think a bit about that and so some tests with Psalm and prepare some failing tests... I'll also test the current version of the Rector on my app to see what happens. Then we will make a decision. |
|
Psalm test: https://psalm.dev/r/d74ddf52b7 |
|
We run on PHPStan, so Psalm test is useless here |
|
It is a memo to not be forced to rewrite again the code each time. PHPStan doesn't alert about missing Having the snippet linked here makes me able to edit it instead of rewriting it each time and fastly clarify what happens in different situations instead of having a project on my computer just to test a bunch of lines of code. I hope you understand my point of view. |
|
This is the same code run on PHPStan: https://phpstan.org/r/c6491906-2837-44fa-b0c7-8400338f977a No alert about missed |
|
I understand the idea. Just that you'll have to figure out how to make that work with Rector and PHPStan anyway, so Psalm might lead you astrey. |
|
@TomasVotruba , I reverted the branch to a stable state: check if it is ready to be merged. Then I will open other PRs to implement the other features... |
|
PS |
|
CI needs to pass though |
It doesn't trigger as I updated the |
|
Just change some space/file and commit |
|
Rebase on |
|
@TomasVotruba , I've fixed what I can, but there is the conflict on vendor/bin/phpstan analyse --ansi --error-format symplify
Note: Using configuration file /Users/Aerendir/Documents/JooServer/_ProjectsIContributeTo/rector/phpstan.neon.
1602/1602 [▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓] 100%
------------------------------------------------------------------------
packages/coding-style/src/Rector/Throw_/AnnotateThrowablesRector.php:110
------------------------------------------------------------------------
- '#Access to an undefined property PHPStan\\PhpDocParser\\Ast\\PhpDoc\\PhpDocTagValueNode\:\:\$type#'
------------------------------------------------------------------------There are also other similar issues... |
|
Just rebuild docs with |
|
The phpstan issue can be solved with If that's the only blocker, I can merge it and resolve |
It didn't worked: I already rebuilt docs, but there is still a conflict...
It should...
For sure you have more familiarity with the repository 😅 |
|
As told some days ago, on my local fork there are also some failing tests not related to this PR and I don't know how to solve them but, mostly, if I have to... |
|
Is it possible you didn't sync your fork first? I'll look on it |
rectorphp/rector-src@041f41f [docs] Remove post Rectors from generated docs (#2833)
#2824: Automatically add to DocBlock comments the thrown
\Throwables.Was PR #2828
Todo in next release
\Throwablesassigned to variables ($value = new \Exception())[https://github.com/#2824: Automatically add to DocBlock comments the thrown\Throwables. #2833#discussion_r377556485]\Throwablesgenerated by methods or functions (throw $this->createException()andthrow createException())