Skip to content

Conversation

@jrfnl
Copy link
Member

@jrfnl jrfnl commented Jul 25, 2025

Just a collection of some small commits to take advantage of things which PHPCSUtils 1.1.0 brings.


PHP/YodaConditions: use new Collections::ternaryOperators() token array

Files/FileName: start using the PHPCSUtils FilePath utility

The FilePath::getName() method will strip quotes from the file name, as well as normalize the slashes to forward (*nix) slashes.

This allows for a minor simplication in the code and improves code readability.

Utils/I18nTextDomainFixer: start using the PHPCSUtils FilePath utility

The FilePath::getName() method will strip quotes from the file name, as well as normalize the slashes to forward (*nix) slashes.

This allows for a minor simplication in the code and improves code readability.

PHP 8.4 | Security/EscapeOutput: handle exit/die using named parameters

As of PHP 8.4, the internals of T_EXIT are changing in PHP itself and exit/die will internally be treated as a function call.

The net effect of this is that named parameters can now be used with exit()/die().

For the WordPress.Security.EscapeOutput sniff this would lead to false positives as the parameter name would be seen as "not escaped".

As of PHPCSUtils 1.1.0, the methods within the PassedParameters class will allow for passing a T_EXIT token. This, in turn, allows for handling exit/die with named parameters correctly in the context of the EscapeOutput sniff.

This commit implements using the PassedParameters class for parsing calls to exit/die, which fixes the issue.

Includes tests.

Ref: https://wiki.php.net/rfc/exit-as-function

PHPCSUtils 1.1.0: only catch what should be caught

PHPCSUtils 1.1.0 introduces much more modular exceptions for a variety of errors the utility methods can throw.

This commit changes the exceptions being caught in various catch statements to more specific ones.

This means that exceptions which shouldn't be able to occur are no longer caught (passing incorrect data type and such) and only the potentially expected (and acceptable) exceptions will now be caught.

jrfnl added 5 commits July 25, 2025 17:12
The `FilePath::getName()` method will strip quotes from the file name, as well as normalize the slashes to forward (*nix) slashes.

This allows for a minor simplication in the code and improves code readability.
The `FilePath::getName()` method will strip quotes from the file name, as well as normalize the slashes to forward (*nix) slashes.

This allows for a minor simplication in the code and improves code readability.
As of PHP 8.4, the internal of `T_EXIT` are changing in PHP itself and `exit`/`die` will internally be treated as a function call.

The net effect of this is that named parameters can now be used with `exit()`/`die()`.

For the `WordPress.Security.EscapeOutput` sniff this would lead to false positives as the parameter name would be seen as "not escaped".

As of PHPCSUtils 1.1.0, the methods within the `PassedParameters` class will allow for passing a `T_EXIT` token. This, in turn, allows for handling `exit`/`die` with named parameters correctly in the context of the `EscapeOutput` sniff.

This commit implements using the `PassedParameters` class for parsing calls to `exit`/`die`, which fixes the issue.

Includes tests.

Ref: https://wiki.php.net/rfc/exit-as-function
PHPCSUtils 1.1.0 introduces much more modular exceptions for a variety of errors the utility methods can throw.

This commit changes the exceptions being caught in various `catch` statements to more specific ones.

This means that exceptions which shouldn't be able to occur are no longer caught (passing incorrect data type and such) and only the potentially expected (and acceptable) exceptions will now be caught.
@dingo-d dingo-d merged commit 6b716a5 into develop Jul 29, 2025
52 checks passed
@dingo-d dingo-d deleted the feature/use-phpcsutils-1.1.0 branch July 29, 2025 04:37
@jrfnl jrfnl modified the milestones: 3.2.x, 3.3.0 Sep 16, 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.

5 participants