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

[FEATURE] Output changelog url in OutputFormatterInterface #6073

Merged
merged 4 commits into from
Apr 10, 2021

Conversation

sabbelasichon
Copy link
Contributor

Resolves: #6072

@sabbelasichon
Copy link
Contributor Author

I am cheating here. I don´t know why or how i should use the phpstan ClassReflection here. Any ideas?

{
$rectorClass = get_class($this->rector);

/* @phpstan-ignore-next-line */
Copy link
Member

@TomasVotruba TomasVotruba Apr 10, 2021

Choose a reason for hiding this comment

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

I am cheating here. I don´t know why or how i should use the phpstan ClassReflection here. Any ideas?

That is false positive, because it's Rector internal class the reflection is used on. But using the ClassReflection class on some projects class. e.g. Typo3\...\Form would disable static reflection. I'll try to update it, so it won't bother contributors in the future :) thanks for feedback.


We put ignores to phsptan.neon, to keep track on them and avoid code polution with tool ignores. Could you move it there?

Copy link
Member

Choose a reason for hiding this comment

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

Fixed by: #6078

@TomasVotruba
Copy link
Member

Thanks for the PR!

I have troubles understanding, because "changelog" reminds me CHANGELOG.md, but I guess this is probably just showing @link in the output after list of affeted rules?


Could you provide some real life example how you use it and what happens? Gif is worth thousand words :)

vendor/bin/rector ...
↓
output (screenshot)

@sabbelasichon
Copy link
Contributor Author

Screenshot 2021-04-10 at 12 19 29

@sabbelasichon
Copy link
Contributor Author

sabbelasichon commented Apr 10, 2021

Changelog has nothing to do in our case with the Changelog.md file. We are creating for every change in TYPO3 a really nice changelog file in the rst format transformed to html. Example: https://docs.typo3.org/c/typo3/cms-core/master/en-us/Changelog/9.4/Deprecation-85793-SeveralConstantsFromSystemEnvironmentBuilder.html. In TYPO3 Rector i add for every rector a nice @link block to reference to this url. This is really nice for the consumer to see why a certain rule is applied.

@sabbelasichon
Copy link
Contributor Author

Screenshot 2021-04-10 at 12 30 32

That´s the json output

@TomasVotruba
Copy link
Member

TomasVotruba commented Apr 10, 2021

I see. So this way we can learn more detailed desription of the change in particular framework?

We actually do something like this in implicit way:

* @see https://wiki.php.net/rfc/deprecations_php_7_4 (not confirmed yet)


We could enable this by default, as there is no reason to hide this information. No configuration option is needed.


One more thing. Currently the JSON output is working with classes only in "applied_rectors". That way it can be used in Rector demo page to link exact rule:


To keep the original value and add a new one, there should be a new value:

{
    "applied_rules": ["SomeRule"],
    "applied_rules_with_changelog": {
        "SomeRule": "https://project/change/link.md"
    }
}

@sabbelasichon
Copy link
Contributor Author

@TomasVotruba I am not 100% sure about the tests. I have introduced some tests to verify the behaviour. Am i right, that no tests exists before to ensure the desired behaviour? Do i miss something?

Comment on lines 59 to 80
$rectorClass = get_class($this->rector);

$rectorReflection = new ReflectionClass($rectorClass);

$docComment = $rectorReflection->getDocComment();

if (! is_string($docComment)) {
return null;
}

$pattern = "#@link\s*(?<url>[a-zA-Z0-9, ()_].*)#";
preg_match($pattern, $docComment, $matches);

if (! array_key_exists('url', $matches)) {
return null;
}

if (! filter_var($matches['url'], FILTER_VALIDATE_URL)) {
return null;
}

return trim((string) $matches['url']);
Copy link
Member

@TomasVotruba TomasVotruba Apr 10, 2021

Choose a reason for hiding this comment

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

This seems quite a complext logic for simple value object.
Could you extract this to own service and cover it with simple test?

$extractedValue = $this->extractAnnotationFromClass('SomeRector::class', '@link');
$this->assertSame('...', $extractedValue);

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Where should this service be located? Is there not already something similar we could use?

Copy link
Member

Choose a reason for hiding this comment

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

I'll trust your choice 👍

@TomasVotruba
Copy link
Member

These are the first test to covert this part, so I think it's ok 👍

It's getting into good shape 👍

I wonder about last think - the annotation name, @see, @link and @source seems a bit unclear. Now that you explained the purpose, maybe the name @changelog would be better name. In most of Symfony/Nette/Laravel/CakePHP rules it would actually link a headline in changelog where the change is described. What do you think?

This feature would be a big addition to understand what rules do and why 👍

@sabbelasichon
Copy link
Contributor Author

sabbelasichon commented Apr 10, 2021

Is @changelog a de-facto official docblock? But, maybe we should not care about it and invent our own.

@TomasVotruba
Copy link
Member

But, maybe we should not care about it and invent our own.

👍 I think it's good name for what is does

@sabbelasichon
Copy link
Contributor Author

If i run the phpstan analysis locally everything is fine. Weird.

@TomasVotruba
Copy link
Member

That's because I've just added this rule into main branch. Just ignore it in phpstan.neon, I'll handle it later.

@TomasVotruba
Copy link
Member

Thank you 👍 Let's 🚢 it :)

@TomasVotruba TomasVotruba merged commit 2b671a2 into rectorphp:main Apr 10, 2021
TomasVotruba added a commit that referenced this pull request Jun 28, 2024
rectorphp/rector-src@f2d4be8 [FileSystem] Move filter <?= on last for files filter to make consistent with filter in directories for performance (#6073)
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.

Output changelog url in OutputFormatterInterface
2 participants