Skip to content

✨ Add IP#79

Merged
martinsoenen merged 1 commit intomainfrom
issue-78
Apr 14, 2026
Merged

✨ Add IP#79
martinsoenen merged 1 commit intomainfrom
issue-78

Conversation

@martinsoenen
Copy link
Copy Markdown
Contributor

@martinsoenen martinsoenen commented Apr 14, 2026

Summary by CodeRabbit

  • New Features

    • New IP address generator that randomly produces either IPv4 or IPv6 format addresses, providing flexibility for different network scenarios.
  • Tests

    • Added unit tests validating correct generation of both IPv4 and IPv6 formatted addresses with multiple iterations and format verification.

@martinsoenen martinsoenen requested a review from 15g-lucas April 14, 2026 16:06
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 14, 2026

📝 Walkthrough

Walkthrough

A new ip() method was added to the InternetExtension class that randomly returns either an IPv4 or IPv6 address by internally calling ipv4() or ipv6() based on a random coin flip. A corresponding unit test validates the generated IP addresses.

Changes

Cohort / File(s) Summary
IP Address Generation Feature
src/Extensions/InternetExtension.php, tests/Unit/Extensions/InternetExtensionTest.php
Added ip(): string method that randomly returns IPv4 or IPv6 addresses via randomizer coin flip, with accompanying unit test that validates 50 generated IPs against standard filters.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Poem

🐰 A coin flip in the code, heads or tails so fine,
IPv4 hops or IPv6 takes the line,
Random addresses bloom like carrots from the ground,
Testing each one to ensure they're sound!

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Add IP' is directly related to the main change: a new ip() method added to the InternetExtension class that returns either IPv4 or IPv6 addresses.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch issue-78

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@15g-lucas 15g-lucas left a comment

Choose a reason for hiding this comment

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

🔥

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
tests/Unit/Extensions/InternetExtensionTest.php (1)

63-72: Strengthen testIp() to assert both IPv4 and IPv6 are produced.

Current assertions validate format only; they won’t catch a regression where ip() always returns a single IP family.

Suggested test hardening
 public function testIp(): void
 {
     $faker = new Container(false);
+    $seenIpv4 = false;
+    $seenIpv6 = false;
 
     for ($i = 0; $i < 50; $i++) {
         $result = $faker->ip();
 
-        $this->assertNotFalse(filter_var($result, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4) || filter_var($result, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6));
+        $isIpv4 = false !== filter_var($result, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4);
+        $isIpv6 = false !== filter_var($result, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6);
+
+        $this->assertTrue($isIpv4 || $isIpv6);
+        $seenIpv4 = $seenIpv4 || $isIpv4;
+        $seenIpv6 = $seenIpv6 || $isIpv6;
     }
+
+    $this->assertTrue($seenIpv4, 'Expected at least one IPv4 address');
+    $this->assertTrue($seenIpv6, 'Expected at least one IPv6 address');
 }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@tests/Unit/Extensions/InternetExtensionTest.php` around lines 63 - 72, The
testIp() currently only checks that each Container->ip() result is a valid IP
but doesn't ensure both families are produced; modify testIp() to track whether
an IPv4 and an IPv6 have been seen across the loop (e.g., booleans ipv4Seen and
ipv6Seen), update them by checking each $result with FILTER_FLAG_IPV4 and
FILTER_FLAG_IPV6, keep the existing per-iteration validation, and after the loop
assert that both ipv4Seen and ipv6Seen are true to catch regressions where ip()
returns only one family.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@tests/Unit/Extensions/InternetExtensionTest.php`:
- Around line 63-72: The testIp() currently only checks that each
Container->ip() result is a valid IP but doesn't ensure both families are
produced; modify testIp() to track whether an IPv4 and an IPv6 have been seen
across the loop (e.g., booleans ipv4Seen and ipv6Seen), update them by checking
each $result with FILTER_FLAG_IPV4 and FILTER_FLAG_IPV6, keep the existing
per-iteration validation, and after the loop assert that both ipv4Seen and
ipv6Seen are true to catch regressions where ip() returns only one family.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 853e6828-506e-4c14-bcce-d13f7248ec2b

📥 Commits

Reviewing files that changed from the base of the PR and between f8e0042 and fda015b.

📒 Files selected for processing (2)
  • src/Extensions/InternetExtension.php
  • tests/Unit/Extensions/InternetExtensionTest.php

@martinsoenen martinsoenen merged commit d8807db into main Apr 14, 2026
6 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.

2 participants