PHP_CodeSniffer
PHP_CodeSniffer copied to clipboard
Generic/InlineControlStructure: fix two bugs and improve code coverage
Description
This PR makes a few changes to the Generic.ControlStructures.InlineControlStructure sniff:
- Fixes a bug when handling
else if
statements (daa1940b80f6de71d3233f17c59e7d47bfb25960) and another one when handlingelseif/if/foreach
without a body (716cbf6f257fddec19c2e162f6458c038ca16220). - Removes two unreachable conditions (2371f216f7826cf570ebb4ceccf1112639d447ff and 42e2f04d267d2453b2a2d5c599464bd8affcfe52).
- Removes a redundant condition (42e2f04d267d2453b2a2d5c599464bd8affcfe52).
- Removes
T_SWITCH
from the list of tokens that this sniff listens to (3db1049adc9aaf3b5d4f13064e3311e89362f029). - Improves the code coverage for this sniff (62637cae5238c1b18527ddae0d126a3abf702e11)
While working on this PR, I noticed that the sniff does not handle well a few syntax errors related to the do-while
control structure. I will open a separate issue describing what I found.
Suggested changelog entry
Generic.ControlStructures.InlineControlStructure: properly handle else if
statements where there is a comment between else
and if
Generic.ControlStructures.InlineControlStructure: fix false positives when handling elseif
, if
, and foreach
without a body
Related issues/external references
Part of https://github.com/PHPCSStandards/PHP_CodeSniffer/issues/146
Types of changes
- [x] Bug fix (non-breaking change which fixes an issue)
- [ ] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing functionality to change)
- [ ] This change is only breaking for integrators, not for external standards or end-users.
- [ ] Documentation improvement
PR checklist
- [x] I have checked there is no other PR open for the same change.
- [x] I have read the Contribution Guidelines.
- [x] I grant the project the right to include and distribute the code under the BSD-3-Clause license (and I have the right to grant these rights).
- [x] I have added tests to cover my changes.
- [x] I have verified that the code complies with the projects coding standards.
- [ ] [Required for new sniffs] I have added XML documentation for the sniff.