Skip to content

Add non-throwing tryFrom siblings for the integer constructors#129

Merged
zanbaldwin merged 1 commit into
6.xfrom
z/try-integers
Jul 3, 2026
Merged

Add non-throwing tryFrom siblings for the integer constructors#129
zanbaldwin merged 1 commit into
6.xfrom
z/try-integers

Conversation

@zanbaldwin

Copy link
Copy Markdown
Member

No description provided.

@zanbaldwin zanbaldwin self-assigned this Jul 3, 2026
@greptile-apps

greptile-apps Bot commented Jul 3, 2026

Copy link
Copy Markdown

Greptile Summary

This PR adds non-throwing factory methods for integer-based IP construction. The main changes are:

  • Adds tryFromInteger() to the IPv4 factory contract.
  • Adds tryFromIntegerString() to the shared factory contract.
  • Implements nullable try-factory wrappers for IPv4, IPv6, and Multi.
  • Adds tests for valid construction and null-on-invalid behavior.

Confidence Score: 5/5

Safe to merge with minimal risk.

The change follows the existing try-factory pattern and delegates to the current throwing constructors. Tests cover valid and invalid paths for each affected version class. No functional or security issues were identified.

No files require special attention.

T-Rex T-Rex Logs

What T-Rex did

  • T-Rex checked the base revision and confirmed that the requested methods and interface declarations were missing, with calls reported as MISSING.
  • T-Rex tested the head revision and confirmed that all requested methods and interface declarations exist, and that valid calls returned Darsyn\\IP\\Version\\IPv4, Darsyn\\IP\\Version\\IPv6, or Darsyn\\IP\\Version\\Multi instances.
  • T-Rex verified that invalid calls on the head revision returned NULL without throwing.
  • T-Rex documented that both artifacts include the script content, the command, the working directory, verbose result lines, and an exit code of 0.

View all artifacts

T-Rex Ran code and verified through T-Rex

Important Files Changed

Filename Overview
src/Contracts/Factory4Interface.php Adds the IPv4 integer tryFromInteger() factory contract with nullable failure semantics.
src/Contracts/FactoryInterface.php Adds the decimal-string tryFromIntegerString() factory contract shared by IP versions.
src/Version/IPv4.php Adds non-throwing integer and decimal-string factory wrappers that return null for invalid IP input.
src/Version/IPv6.php Adds the non-throwing decimal-string factory wrapper for IPv6 integer-string construction.
src/Version/Multi.php Adds non-throwing integer and decimal-string factory wrappers while preserving optional embedding strategy handling.
tests/Version/IPv4Test.php Covers valid and invalid IPv4 integer and integer-string try-factory behavior.
tests/Version/IPv6Test.php Covers valid and invalid IPv6 integer-string try-factory behavior.
tests/Version/MultiTest.php Covers valid and invalid multi-version integer and integer-string try-factory behavior.

Sequence Diagram

%%{init: {'theme': 'neutral'}}%%
sequenceDiagram
participant Caller
participant TryFactory as tryFromInteger*/tryFromIntegerString
participant ThrowingFactory as fromInteger*/fromIntegerString
participant Binary as Binary/fromBinary

Caller->>TryFactory: construct from integer input
TryFactory->>ThrowingFactory: delegate to existing constructor
ThrowingFactory->>Binary: validate/convert to binary
alt valid input
    Binary-->>ThrowingFactory: binary sequence
    ThrowingFactory-->>TryFactory: IP instance
    TryFactory-->>Caller: IP instance
else invalid input
    ThrowingFactory-->>TryFactory: InvalidIpAddressException
    TryFactory-->>Caller: null
end
Loading
%%{init: {'theme': 'base', 'themeVariables': {"darkMode": true, "background": "#0d1117", "primaryColor": "#21262d", "primaryTextColor": "#e6edf3", "primaryBorderColor": "#8b949e", "lineColor": "#8b949e", "textColor": "#e6edf3", "edgeLabelBackground": "#161b22", "actorBkg": "#21262d", "actorBorder": "#8b949e", "actorTextColor": "#e6edf3", "actorLineColor": "#8b949e", "signalColor": "#8b949e", "signalTextColor": "#e6edf3", "noteBkgColor": "#373320", "noteBorderColor": "#d4a72c", "noteTextColor": "#f0e6c0", "labelBoxBkgColor": "#21262d", "labelBoxBorderColor": "#8b949e", "labelTextColor": "#e6edf3", "loopTextColor": "#e6edf3", "activationBkgColor": "#30363d", "activationBorderColor": "#8b949e"}}}%%
sequenceDiagram
participant Caller
participant TryFactory as tryFromInteger*/tryFromIntegerString
participant ThrowingFactory as fromInteger*/fromIntegerString
participant Binary as Binary/fromBinary

Caller->>TryFactory: construct from integer input
TryFactory->>ThrowingFactory: delegate to existing constructor
ThrowingFactory->>Binary: validate/convert to binary
alt valid input
    Binary-->>ThrowingFactory: binary sequence
    ThrowingFactory-->>TryFactory: IP instance
    TryFactory-->>Caller: IP instance
else invalid input
    ThrowingFactory-->>TryFactory: InvalidIpAddressException
    TryFactory-->>Caller: null
end
Loading

Reviews (1): Last reviewed commit: "feature(contracts): ✨ add non-throwing t..." | Re-trigger Greptile

@zanbaldwin zanbaldwin merged commit fec0aec into 6.x Jul 3, 2026
25 checks passed
@zanbaldwin zanbaldwin deleted the z/try-integers branch July 3, 2026 12:20
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