AlwaysReturnInFilter: isInsideIfConditonal() guards the conditions array after reading it
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 78/100
Research direction
Start at AlwaysReturnInFilterSniff::isInsideIfConditonal() and inspect how the token's conditions array is read. Simplify the guard and reset logic as described, then verify the sniff still reports the same cases; done means the tidy-up preserves reporting behavior.
Written by the indexing model from the issue text.
Description
This is a tidy-up. It does not change what the sniff reports.
AlwaysReturnInFilterSniff::isInsideIfConditonal() decides whether a return in a filter callback sits inside an if. It has a guard for a token that has no conditions array, but the guard comes after two end() calls that have already read that array, so it protects nothing. PHP_CodeSniffer sets conditions on every token, so the guard is not needed in the first place.
The reset() call between the two has no effect on the result either. It only undoes the array pointer move that end() made on the shared token array.
The method can read the array once, return false when the innermost condition is a function or closure, and otherwise return in_array( T_IF, $conditions, true ).
@GaryJones spotted this while reviewing #901. It was left out of that PR because that one only adds return types.
- Dominant language
- PHP
- Stars
- 261
- Forks
- 44
- PR merge metrics
- No merged PRs in 30d
Getting set up
- No Dockerfile or Docker Compose file
- No pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from Automattic/VIP-Coding-Standards
-
Bug: PreGetPosts warns when the early is_main_query() return is not the first statement in its ifPossibly taken @tomjn claimed this 4 days ago. Open
Difficulty 3/5 1-2 days Newbie friendliness 76/100
-
Suppress filters in get_posts false positivePossibly taken @tomjn claimed this 5 days ago. Open
Difficulty 3/5 1-2 days Newbie friendliness 68/100
-
Difficulty 3/5 1-2 days Newbie friendliness 48/100
-
Breaking Change Type: Maintenance
Difficulty 4/5 3-5 days Newbie friendliness 35/100
Automattic/VIP-Coding-Standards#849 · 1 comment ·
-
Difficulty 3/5 1-2 days Newbie friendliness 45/100
All issues in Automattic/VIP-Coding-Standards
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
Maintainers usually reply within 1 day
-
Awaiting Triage bug
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
Maintainers usually reply within 1 day
-
product / databases
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
Maintainers usually reply within 1 day
-
enhancement
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
VilnaCRM-Org/user-service#525 ·
Maintainers usually reply within 21 days
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
shukiv/jabali-panel#2029 ·
Maintainers usually reply within 1 day