Skip to content

Rename isPublicUse() to isGloballyReachable()#107

Open
zanbaldwin wants to merge 1 commit into
6.xfrom
z/globally-reachable
Open

Rename isPublicUse() to isGloballyReachable()#107
zanbaldwin wants to merge 1 commit into
6.xfrom
z/globally-reachable

Conversation

@zanbaldwin
Copy link
Copy Markdown
Member

Conform to official wording from the IANA special-purpose address registries; Public Use does not appear in them. Keep isPublicUse() as a deprecated alias.

Conform to official wording from the IANA special-purpose address registries; "Public Use" does not appear in them.
Keep isPublicUse() as a deprecated alias.
@zanbaldwin zanbaldwin self-assigned this Jun 4, 2026
@greptile-apps
Copy link
Copy Markdown

greptile-apps Bot commented Jun 5, 2026

Greptile Summary

This PR renames isPublicUse() to isGloballyReachable() across the interface and all three concrete implementations (IPv4, IPv6, Multi) to align with IANA's official terminology, keeping isPublicUse() as a deprecated delegating alias. The related darsyn/ip-doctrine repository does not call either method, so there is no cross-repo impact.

  • All real logic now lives in isGloballyReachable(); isPublicUse() in each class simply calls $this->isGloballyReachable(), and the interface marks it @deprecated.
  • Test data-provider constants and method names are consistently renamed (PUBLIC_USE_*GLOBALLY_REACHABLE_*), but the deprecated alias is left completely untested, and the @deprecated annotation is absent from the concrete class methods.

Confidence Score: 4/5

Safe to merge; the rename is mechanical and correct, with no logic changes to the underlying routing checks.

The delegation chain is straightforward and the bitmask values in test data are unchanged, so the core behaviour is intact. Two small gaps remain: the @deprecated docblock is missing from the three concrete class methods (only the interface carries it), and the deprecated isPublicUse() alias has no test coverage, so a future accidental breakage of the delegation would go unnoticed.

src/Version/IPv4.php, src/Version/IPv6.php, and src/Version/Multi.php each need the @deprecated annotation added to isPublicUse(); the three corresponding test files could each benefit from a small alias-coverage test.

Important Files Changed

Filename Overview
src/IpInterface.php Adds deprecated isPublicUse() and new isGloballyReachable() to the interface; docblock and URL references look correct.
src/Version/IPv4.php Logic moved correctly into isGloballyReachable(); isPublicUse() delegates properly but is missing the @deprecated docblock.
src/Version/IPv6.php Same pattern as IPv4 — delegation is correct, but @deprecated annotation absent on the concrete isPublicUse() method.
src/Version/Multi.php Correctly delegates isPublicUse() to isGloballyReachable(), and isGloballyReachable() properly routes between embedded IPv4 and parent IPv6 logic.
tests/Version/IPv4Test.php Test method renamed and updated to call isGloballyReachable(); no coverage for deprecated isPublicUse() alias remains.
tests/Version/IPv6Test.php Same as IPv4Test — alias entirely uncovered by tests after rename.
tests/Version/MultiTest.php Same as IPv4Test/IPv6Test — no remaining test for the deprecated isPublicUse() alias.
tests/DataProvider/IpDataProviderInterface.php Constants renamed from PUBLIC_USE_* to GLOBALLY_REACHABLE_*; bitmask values unchanged, so all existing test data remains correct.
tests/DataProvider/IPv4.php Data provider method and constant references renamed consistently; no logic changes.
tests/DataProvider/IPv6.php Renamed cleanly; getGloballyReachableIpAddressesExcludingMapped() helper preserved correctly.
tests/DataProvider/Multi.php Renamed correctly; still properly merges IPv4 and IPv6 (excluding mapped) data sets.

Sequence Diagram

sequenceDiagram
    participant Caller
    participant IPv4
    participant IPv6
    participant Multi

    Note over Caller,Multi: New primary method
    Caller->>IPv4: isGloballyReachable()
    IPv4-->>Caller: bool (full logic here)

    Caller->>IPv6: isGloballyReachable()
    IPv6-->>Caller: bool (full logic here)

    Caller->>Multi: isGloballyReachable()
    alt isEmbedded()
        Multi->>IPv4: isGloballyReachable()
        IPv4-->>Multi: bool
    else
        Multi->>IPv6: isGloballyReachable()
        IPv6-->>Multi: bool
    end
    Multi-->>Caller: bool

    Note over Caller,Multi: Deprecated alias
    Caller->>IPv4: isPublicUse()
    IPv4->>IPv4: isGloballyReachable()
    IPv4-->>Caller: bool

    Caller->>IPv6: isPublicUse()
    IPv6->>IPv6: isGloballyReachable()
    IPv6-->>Caller: bool

    Caller->>Multi: isPublicUse()
    Multi->>Multi: isGloballyReachable()
    Multi-->>Caller: bool
Loading

Reviews (1): Last reviewed commit: "feature: ✨ rename isPublicUse() to isGlo..." | Re-trigger Greptile

Comment thread src/Version/IPv4.php
Comment on lines 104 to +107
public function isPublicUse(): bool
{
return $this->isGloballyReachable();
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Missing @deprecated on concrete implementations

The @deprecated annotation exists on IpInterface::isPublicUse() but is absent from the concrete implementations in IPv4, IPv6, and Multi. IDEs and static analysers (PHPStan, Psalm) resolve deprecation warnings from the declared type at the call site. When user code holds a variable typed as the concrete class rather than IpInterface, the tooling will silently accept isPublicUse() calls without any deprecation notice, defeating the purpose of the annotation.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

Comment on lines 415 to 428

/**
* @test
* @dataProvider \Darsyn\IP\Tests\DataProvider\IPv4::getPublicUseIpAddresses()
* @dataProvider \Darsyn\IP\Tests\DataProvider\IPv4::getGloballyReachableIpAddresses()
*/
#[PHPUnit\Test]
#[PHPUnit\DataProviderExternal(IPv4DataProvider::class, 'getPublicUseIpAddresses')]
public function testIsPublicUse(string $value, bool $isPublicUse): void
#[PHPUnit\DataProviderExternal(IPv4DataProvider::class, 'getGloballyReachableIpAddresses')]
public function testIsGloballyReachable(string $value, bool $isGloballyReachable): void
{
$ip = IP::factory($value);
$this->assertSame($isPublicUse, $ip->isPublicUse());
$this->assertSame($isGloballyReachable, $ip->isGloballyReachable());
}

/**
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 No test coverage for the deprecated isPublicUse() alias

All three test classes (IPv4Test, IPv6Test, MultiTest) had their testIsPublicUse methods renamed to testIsGloballyReachable, which now only exercises the new method. The deprecated isPublicUse() delegate is completely untested — a future refactor that accidentally breaks the delegation (e.g., returning a hardcoded value) would go undetected. A minimal parameterised test that calls isPublicUse() and asserts it matches isGloballyReachable() would guard the alias.

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.

1 participant