Repository navigation
Return false from isCarrierSpecific() when no region matches - #770
Merged
Merged
Conversation
The nullable region code went straight into getMetadataForRegion(), which throws a TypeError before the existing null check could run.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #770 +/- ##
=========================================
Coverage 85.86% 85.86%
- Complexity 1318 1319 +1
=========================================
Files 31 31
Lines 3445 3445
=========================================
Hits 2958 2958
Misses 487 487 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Copilot review overview
🟢 Approval recommended
The focused null guard fixes the reported type error and is covered by an appropriate regression test.
Review effort: Balanced
Findings: None
What changed in this PR
Prevents isCarrierSpecific() from throwing when no short-number region matches, aligning behavior with Java libphonenumber.
Changes:
- Skips metadata lookup when the region is
null. - Adds regression coverage for a non-short NANPA number.
| File | Description |
|---|---|
src/ShortNumberInfo.php |
Safely handles a missing region. |
tests/core/ShortNumberInfoTest.php |
Verifies the fallback returns false. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
isCarrierSpecific()passes the nullable result ofgetRegionCodeForShortNumberFromRegionList()togetMetadataForRegion(string). When no region matches, e.g.+1 6502530000, that throws aTypeErrorbefore the existing$phoneMetadata !== nullcheck runs. Java returnsfalse, andisValidShortNumber()andgetExpectedCost()already handle the no-region case.This skips the lookup when there is no region and adds a test row. Compared with Java libphonenumber 9.0.40 over about 15k short-number inputs, the only change is that the inputs that threw now return Java's result. phpunit, phpstan and php-cs-fixer pass.
Written with AI assistance (Claude); I have reviewed the change.