Skip to content

Return false from isCarrierSpecific() when no region matches - #770

Merged
giggsey merged 1 commit into
giggsey:masterfrom
youdie006:carrier-specific-null-region
Oct 2, 2026
Merged

giggsey merged 1 commit into
giggsey:masterfrom
youdie006:carrier-specific-null-region

Conversation

@youdie006

Copy link
Copy Markdown
Contributor

isCarrierSpecific() passes the nullable result of getRegionCodeForShortNumberFromRegionList() to getMetadataForRegion(string). When no region matches, e.g. +1 6502530000, that throws a TypeError before the existing $phoneMetadata !== null check runs. Java returns false, and isValidShortNumber() and getExpectedCost() 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.

The nullable region code went straight into getMetadataForRegion(),
which throws a TypeError before the existing null check could run.
@codecov

codecov Bot commented Oct 2, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 85.86%. Comparing base (e18ff52) to head (caf036f).
⚠️ Report is 3 commits behind head on master.

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@giggsey
giggsey merged commit 2b05c73 into giggsey:master Oct 2, 2026
22 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants