Problem/Motivation
Since PHP 8.0 we can omit the exception variable in catch blocks if the variable is unused.
Steps to reproduce
Proposed resolution
Add SlevomatCodingStandard.Exceptions.RequireNonCapturingCatch to phpcs.xml.dist and run composer phpcbf.
Remaining tasks
Discuss coding standards
User interface changes
API changes
Data model changes
Release notes snippet
Issue fork drupal-3421809
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
- 3421809-require-non-capturing-catch
changes, plain diff MR !6636
Comments
Comment #3
mstrelan commentedComment #4
spokjeDrupal\KernelTests\Core\Plugin\DefaultPluginManagerTestdisagrees ;)Comment #5
mstrelan commentedSo apparently this sniff doesn't detect use of the variable in
finallyclauses. That seems like a bug with the sniff. That said, it seems weird to access the exception from the finally clause, because it's not guaranteed to be set.Comment #6
mstrelan commentedLooked closer at the test.
$eis set toNULLin thetryclause and should become aThrowablein thecatch, so it should definitely exist infinally.I guess this is postponed on False positive SlevomatCodingStandard.Exceptions.RequireNonCapturingCatch.NonCapturingCatchRequired.
Comment #7
spokjeThanks for the Sherlocking @mrstrelan!
Comment #8
mstrelan commentedElementary!
Comment #9
mstrelan commentedIssue mentioned in #6 is fixed now and released in slevomat/coding-standard:8.15.0
Comment #10
mstrelan commentedSlevomat coding standard was updated in #3262874: Update Coder to 8.3.15. Rebased and re-ran phpcbf. Back to Needs Review.
Comment #11
spokjeI think you've beaten Moriarty @mstrelan!
Since this adds a PHPCS-rule and might break contrib/external-CI in some places, I think we need a CR for this.
Besides that, I'm all for RTBC.
Comment #12
mstrelan commentedContrib doesn't use the phpcs file from core, but we could indeed add a CR regardless.
Comment #13
mstrelan commentedI don't see CR's for the latest 3 commits to phpcs.xml.dist, so maybe we're ok?
#2874067: Fix Drupal.Commenting.DocCommentLongArraySyntax coding standard
#3180696: Fix 'Drupal.Commenting.TodoComment' coding standard
#3427999: [PHP 8.4] Fix implicitly nullable type declarations
Also in #3180696-89: Fix 'Drupal.Commenting.TodoComment' coding standard @quietone mentioned CR is not needed.
Comment #14
spokjeThanks sherlock mstrelan, seems like it's indeed not needed.
RTBC for me.
Comment #16
catchYes core's phpcs only affects core afaik, so we don't need a CR for these. Committed/pushed to 11.x, thanks!