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
feat(PhpdocToCommentFixer): Add option to handle return as valid docblock usage (#7401) #7402
feat(PhpdocToCommentFixer): Add option to handle return as valid docblock usage (#7401) #7402
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@f1amy we had some conversation between maintainers, and here's the summary: we would like to introduce new config option for this fixer, e.g. allow_before_return_statement
which should be set to false
by default, to keep current behaviour intact, as we consider this as a feature request, not a bug fix. In Fixer v4 we will make it true
by default (so you can leave such a comment there), because PHP's ecosystem supports it (like PHPStan, PHPStorm). Please introduce the config option, regenerate docs and provide test cases for both config values.
@keradus @kubawerlos FYI it was already proposed in the past (#5109), so we need to close one, but which one? This is most recent and up-to-date, but @bendavies' contribution would be rejected unfairly IMHO 🤷. |
|
@Wirone - We merge one that is ready, when it's ready, and we close the other one. |
Rebased latest changes, |
I'm not sure if static code analysis fail is caused by this PR's code, should I just wait for new commits from master? |
@f1amy The error is not related to your changes, but I can't reproduce it locally, though 🤔. Created PR with newest PHPStan, but error remains. Will investigate it later. |
I agree with #5109 (comment), such |
I agree that we should not need to correct types with |
@Wirone could you please check the status of this PR? It says that 1 change is requested, but I thought I fixed it already, is it just waiting for review? |
@@ -65,7 +65,7 @@ public function isHeaderComment(Tokens $tokens, int $index): bool | |||
* | |||
* @see https://github.com/php-fig/fig-standards/blob/master/proposed/phpdoc.md#3-definitions | |||
*/ | |||
public function isBeforeStructuralElement(Tokens $tokens, int $index): bool | |||
public function isBeforeStructuralElement(Tokens $tokens, int $index, bool $allowReturnStatement = false): bool |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From here, the new parameter does not make sense - isBeforeStructuralElement
is clear, parameter allowReturnStatement
allows cheating. Let's not do that and limit allow_before_return_statement
functionality to only PhpdocToCommentFixer
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Extracted into isBeforeReturn
method
- correct doc for method
- add tests - update docs
@kubawerlos ready for review again! |
@@ -102,6 +119,8 @@ public function configure(array $configuration = null): void | |||
static fn (string $tag): string => strtolower($tag), | |||
$this->configuration['ignored_tags'] | |||
); | |||
|
|||
$this->allowBeforeReturnStatement = (bool) $this->configuration['allow_before_return_statement']; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
$this->allowBeforeReturnStatement = (bool) $this->configuration['allow_before_return_statement']; | |
$this->allowBeforeReturnStatement = true === $this->configuration['allow_before_return_statement']; |
We have no casting for configuration in other fixers, let's use comparing to true
, or even true === $this->configuration['allow_before_return_statement']
directly in line 153.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
return false; | ||
} | ||
|
||
return $this->isValidReturnStatement($tokens, $nextIndex); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return $this->isValidReturnStatement($tokens, $nextIndex); | |
return $tokens[$nextIndex]->isGivenKind(T_RETURN); |
No need for a separate function for such a simple check.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed. fixed
Thank you @f1amy 👍🏼 |
Fixes #7401
Supersedes #5109