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

Fixer breaks PhpDoc before return #7401

Closed
f1amy opened this issue Nov 1, 2023 · 4 comments · Fixed by #7402
Closed

Fixer breaks PhpDoc before return #7401

f1amy opened this issue Nov 1, 2023 · 4 comments · Fixed by #7402
Labels

Comments

@f1amy
Copy link
Contributor

f1amy commented Nov 1, 2023

Bug report

Description

phpdoc_to_comment rule breaks PhpDoc that is used to declare returned value from within a function.

Runtime version

PHP CS Fixer 3.28.0 Jump & Run by Fabien Potencier and Dariusz Ruminski.
PHP runtime: 8.2.11

Used command

php ./vendor/bin/php-cs-fixer fix --allow-risky=yes --config=.php-cs-fixer.dist.php

Loaded config default from ".php-cs-fixer.dist.php".
Using cache file "/srv/app/var/tools/.php-cs-fixer.cache".
.........F................................................                                                                                                                                                                  58 / 58 (100%)
Legend: .-no changes, F-fixed, S-skipped (cached or empty file), I-invalid file syntax (file ignored), E-error
   1) /srv/app/src/Infrastructure/State/Order/OrderGetCollectionProvider.php (phpdoc_to_comment)

Fixed 1 of 58 files in 0.743 seconds, 16.000 MB memory used

Configuration file

<?php

$finder = (new PhpCsFixer\Finder())
    ->in(__DIR__.'/src')
    ->in(__DIR__.'/tests')
    ->in(__DIR__.'/migrations')
;

return (new PhpCsFixer\Config())
    ->setRiskyAllowed(true)
    ->setRules([
        '@Symfony' => true,
        '@Symfony:risky' => true,
        '@DoctrineAnnotation' => true,
    ])
    ->setFinder($finder)
    ->setCacheFile(__DIR__.'/var/tools/.php-cs-fixer.cache')
;

Code snippet that reproduces the problem

Expected:

<?php

function something(): object
{
    /** @var object */
    return $this->get();
}

Actual:

<?php

function something(): object
{
    /* @var object */
    return $this->get();
}
@f1amy f1amy added the kind/bug label Nov 1, 2023
@f1amy
Copy link
Contributor Author

f1amy commented Nov 1, 2023

I have reproduced this on latest version of the tool.

@Wirone
Copy link
Member

Wirone commented Nov 1, 2023

I believe we need T_RETURN support to CommentsAnalyzer::isValidLanguageConstruct(), with early return true for this token. Adding this token to static $languageStructures list does not solve the problem, because further logic checks for ] or ) and look inside the block, while using parentheses on return is discouraged. @f1amy do you want to prepare the PR with the fix?

@f1amy
Copy link
Contributor Author

f1amy commented Nov 1, 2023

@Wirone I will try

@f1amy
Copy link
Contributor Author

f1amy commented Nov 1, 2023

@Wirone done!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants