Skip to content

Conversation

@jrfnl
Copy link
Member

@jrfnl jrfnl commented Jul 5, 2025

Since the release of PHPCS 3.12.2, one test is failing on older PHP versions.
Since the release of PHPCSUtils 1.1.0, another two tests are failing.

This PR is intended to unblock contributors by fixing these CI failures.

Other updates which can/should be made for the more recent PHPCS versions and related to PHPCSUtils 1.1.0 will follow in separate PRs.


Composer: raise the minimum supported PHPCSUtils version to 1.1.0

... to benefit from new functionality related to PHP 8.3, 8.4 and PHPCS 4.0.

As the minimum supported PHPCS version for PHPCSUtils 1.1.0 is PHPCS 3.13.0, the minimum PHPCS version has also been raised.

Refs:

Miscellaneous/NewPHPOpenTagEOF: remove work-arounds which are no longer needed

PHPCS 3.12.2 fixed a PHP tokenization inconsistency directly related to what this sniff is detecting.

  • Tokenizer/PHP: a PHP open tag at the very end of a file will now always be tokenized as T_OPEN_TAG, independently of the PHP version.
    Previously, a PHP open tag at the end of a file was not tokenized as an open tag on PHP < 7.4 and the tokenization would depend on the short_open_tag setting.

As the PHPCS tokenization will now be the same PHP cross-version, we can remove the work-arounds which were in place to accommodate the previous difference in tokenization.

Ref:

FunctionDeclarations/ForbiddenVariableNamesInClosureUse: catch potential exception

The following PHPCSUtils 1.1.0 change was causing the tests to fail:

UseStatements::getType() will now handle unfinished closure use statements (parse errors) more consistently and return 'closure' for those cases.

This change means that during live coding, in specific cases where a closure declaration is incomplete, the UseStatements::getType() method will still correctly detect the use as a closure use.
However, the FunctionDeclarations::getParameters() method will not handle such incomplete code and will throw an exception as the parameters imported via the closure use cannot be reliably retrieved.

Fixed now by catching this potential exception.

PHP 8.4 | NewNamedParameters: handle named params passed to exit/die

. The exit (and die) language constructs now behave more like a function.
They can be passed liked callables, are affected by the strict_types
declare statement, and now perform the usual type coercions instead of
casting any non-integer value to a string.
As such, passing invalid types to exit/die may now result in a TypeError
being thrown.
RFC: https://wiki.php.net/rfc/exit-as-function

This commit adds detection of the use of named arguments passed to exit()/die() to the NewNamedParameters sniff.

Includes tests.

Note: sniff updates for the other aspects of this PHP 8.4 feature will be pulled separately.

Refs:

Related to #1731

jrfnl added 4 commits July 5, 2025 23:02
... to benefit from new functionality related to PHP 8.3, 8.4 and PHPCS 4.0.

As the minimum supported PHPCS version for PHPCSUtils 1.1.0 is PHPCS 3.13.0, the minimum PHPCS version has also been raised.

Refs:
* https://github.com/PHPCSStandards/PHPCSUtils/releases/tag/1.1.0
…er needed

PHPCS 3.12.2 fixed a PHP tokenization inconsistency directly related to what this sniff is detecting.

> - Tokenizer/PHP: a PHP open tag at the very end of a file will now always be tokenized as T_OPEN_TAG, independently of the PHP version.
>     Previously, a PHP open tag at the end of a file was not tokenized as an open tag on PHP < 7.4 and the tokenization would depend on the short_open_tag setting.

As the PHPCS tokenization will now be the same PHP cross-version, we can remove the work-arounds which were in place to accommodate the previous difference in tokenization.

Ref:
* PHPCSStandards/PHP_CodeSniffer 937
…ial exception

The following PHPCSUtils 1.1.0 change was causing the tests to fail:

> `UseStatements::getType()` will now handle unfinished closure `use` statements (parse errors) more consistently and return `'closure'` for those cases.

This change means that during live coding, in specific cases where a closure declaration is incomplete, the `UseStatements::getType()` method will still correctly detect the `use` as a closure `use`.
However, the `FunctionDeclarations::getParameters()` method will not handle such incomplete code and will throw an exception as the parameters imported via the closure `use` cannot be reliably retrieved.

Fixed now by catching this potential exception.
> . The exit (and die) language constructs now behave more like a function.
>   They can be passed liked callables, are affected by the strict_types
>   declare statement, and now perform the usual type coercions instead of
>   casting any non-integer value to a string.
>   As such, passing invalid types to exit/die may now result in a TypeError
>   being thrown.
>   RFC: https://wiki.php.net/rfc/exit-as-function

This commit adds detection of the use of named arguments passed to `exit()`/`die()` to the `NewNamedParameters` sniff.

Includes tests.

Note: sniff updates for the other aspects of this PHP 8.4 feature will be pulled separately.

Refs:
* https://wiki.php.net/rfc/exit-as-function
* https://github.com/php/php-src/blob/8853cf3ae950a1658054f286117bc8f77f724f00/UPGRADING#L40-L46
* php/php-src 13486
* php/php-src@a79c70f
* php/php-src 15433
* php/php-src@4c5767f

Related to 1731
@wimg wimg merged commit 80e5d8d into develop Jul 6, 2025
46 checks passed
@wimg wimg deleted the feature/composer-update-for-phpcsutils-1.1.0 branch July 6, 2025 13:28
@github-actions github-actions bot removed PR: quick merge PR only contains relatively simple changes PR: ready for review labels Jul 6, 2025
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.

3 participants