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

✨ PHP 8.0 | New NewNamedParametersSniff sniff #1423

Merged
merged 1 commit into from
Dec 5, 2022

Conversation

jrfnl
Copy link
Member

@jrfnl jrfnl commented Dec 5, 2022

PHP 8.0 introduces named function call parameters:

array_fill(start_index: 0, count: 100, value: 50);

// Using reserved keywords as names is allowed.
array_foobar(array: $array, switch: $switch, class: $class);

Ref: https://wiki.php.net/rfc/named_params

This new sniff will detect the use of named parameters based on the support for this in PHPCSUtils as added in PHPCSStandards/PHPCSUtils#235 and PHPCSStandards/PHPCSUtils#383.

Includes unit tests.

Related to #809

Open question: should this sniff live in the FunctionUse category or in the Syntax category ?

PHP 8.0 introduces named function call parameters:
```php
array_fill(start_index: 0, count: 100, value: 50);

// Using reserved keywords as names is allowed.
array_foobar(array: $array, switch: $switch, class: $class);
```

Ref: https://wiki.php.net/rfc/named_params

This new sniff will detect the use of named parameters based on the support for this in PHPCSUtils as added in PHPCSStandards/PHPCSUtils 235 and PHPCSStandards/PHPCSUtils 383.

Includes unit tests.

**Open question**: should this sniff live in the `FunctionUse` category or in the `Syntax` category ?
Copy link
Member

@wimg wimg left a comment

Choose a reason for hiding this comment

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

What a super list of test cases :-D

@wimg wimg merged commit 06a4776 into develop Dec 5, 2022
@wimg wimg deleted the php-8.0/new-namedparameters-sniff branch December 5, 2022 12:08
@jrfnl
Copy link
Member Author

jrfnl commented Dec 5, 2022

Argh... just now thinking the sniff can be much simpler...

I wrote this before we dropped support for PHPCS < 3.7.1, so that meant that for the majority of PHPCS versions supported, we'd need to work out whether something contained a parameter name ourselves (by using the PHPCSUtils functionality).

Parameter names are supported in PHPCS since PHPCS 3.6.0 and are retokenized to ta separate token T_PARAM_NAME....

I'll put it on my todo list to check if we can just sniff for T_PARAM_NAME instead....

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

Successfully merging this pull request may close these issues.

2 participants