Fix undefined array key 0 in Query/Filter isEmpty#881
Conversation
isEmpty() called $values[0] when the array was non-empty but not zero-indexed (sparse or associative), emitting Warning: Undefined array key 0. Use array_key_first() to address the first element regardless of key layout.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughFilter validator's ChangesSparse Array Index Handling
🎯 1 (Trivial) | ⏱️ ~5 minutes 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Greptile SummaryFixes a PHP warning in
Confidence Score: 5/5Safe to merge — the change is a one-line targeted fix with no functional side effects on normal zero-indexed arrays. The change is minimal and correct: array_key_first() is the idiomatic PHP solution, the prior count === 0 guard ensures the function never returns null at that call site, and the added tests directly exercise the two newly-safe code paths. No files require special attention. Important Files Changed
Reviews (1): Last reviewed commit: "Fix undefined array key 0 in Query/Filte..." | Re-trigger Greptile |
Summary
Filter::isEmpty()accesses$values[0]after only checkingcount($values) === 0. When the values array is non-empty but not zero-indexed (sparse arrays, associative arrays), PHP emitsWarning: Undefined array key 0. Replaced the direct index access witharray_key_first()so the first element is read regardless of key layout. Behaviour for zero-indexed arrays is unchanged.Test plan
tests/unit/Validator/Query/FilterTest.phpcovering sparse and associative value arrays.composer lintclean.composer check(PHPStan level 7) clean.Summary by CodeRabbit