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

Same-line inline annotations make phpcs remove comment marks, leading to invalid code #2011

Closed
melbings opened this issue May 2, 2018 · 5 comments

Comments

@melbings
Copy link

melbings commented May 2, 2018

I recently noticed this probable bug - phpcs analyzes the following snippet...

Debugger::getBar()->addPanel($this->objectFactory->make(DumperPanel::class, [
    'title' => 'SESS',
    'data' => \array_filter($_SESSION, /** @psalm-suppress MissingClosureParamType */ function (/** @noinspection PhpUnusedParameterInspection */ $value, string $key): bool {
        return $key !== 'user_password';
    }, ARRAY_FILTER_USE_BOTH)
]));

... and removes the leading /** of the second inline annotation, thus making the code invalid:

Debugger::getBar()->addPanel($this->objectFactory->make(DumperPanel::class, [
    'title' => 'SESS',
    'data' => \array_filter($_SESSION, /** @psalm-suppress MissingClosureParamType */ function (@noinspection PhpUnusedParameterInspection */ $value, string $key): bool {
        return $key !== 'user_password';
    }, ARRAY_FILTER_USE_BOTH)
]));

Unfortunately, I have not had time to analyze this in any more detail, so that I'm providing the full code snippets instead of simplifying the code beforehand.

@gsherwood
Copy link
Member

I can't replicate this with any of the included standards. Are you able to let me know what standard or sniffs you are using so I can try and replicate?

@gsherwood
Copy link
Member

Just checking in to see if you can give me more info about your standard.

@melbings
Copy link
Author

I'm sorry for keeping you waiting. I minimized the error condition down to

<?php

function(/** @demoAnnotation */ $value) {};

which outputs

<?php

function (@demoAnnotation */ $value) {
};

You can reproduce the problem by cloning https://github.com/melbings/CodeSnifferTest.

@gsherwood
Copy link
Member

Thanks for doing that. I was able to replicate this bug and determine that it has already been fixed in master. The fix for this bug will be released in version 3.3.0.

While the bug report looks a little different, the fix was made as part of this report: #2006

Thanks again for taking the time to get that test case going - it made things really clear.

@melbings
Copy link
Author

Glad it's fixed - keep up the good work 👍

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

No branches or pull requests

2 participants