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

Handle constructor promotion #227

Closed
sirbrillig opened this issue Mar 8, 2021 · 1 comment · Fixed by #266
Closed

Handle constructor promotion #227

sirbrillig opened this issue Mar 8, 2021 · 1 comment · Fixed by #266

Comments

@sirbrillig
Copy link
Owner

Constructor promotion (https://stitcher.io/blog/constructor-promotion-in-php-8) allows code like the following:

class MyDTO
{
    public function __construct(
        public string $name = 'Brent',
    ) {}
}

But this sniff will mark $name unused and it is in fact used. We'll need to handle that.

This was extracted from #226

@jrfnl
Copy link
Collaborator

jrfnl commented Mar 8, 2021

For information on how support was implemented in PHPCS (via the File::getMethodParameters() method): squizlabs/PHP_CodeSniffer#3152

The same was already available via PHPCSUtils via FunctionDeclarations::getParameters() and the implementation in PHPCSUtils is backward compatible all the way back to PHPCS 2.6.0.
See: PHPCSStandards/PHPCSUtils#169

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 a pull request may close this issue.

2 participants