Skip to content

feat(Domain): add allowEmpty constructor option#8

Merged
Meldiron merged 2 commits intomainfrom
copilot/add-allow-empty-support
Apr 27, 2026
Merged

feat(Domain): add allowEmpty constructor option#8
Meldiron merged 2 commits intomainfrom
copilot/add-allow-empty-support

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 27, 2026

Domain::isValid() unconditionally rejected empty strings. This adds an opt-in allowEmpty flag (default false) that permits empty strings while still rejecting null and all other invalid values.

Changes

  • Domain.php — added bool $allowEmpty = false as third constructor parameter; early-returns true for '' when the flag is set, using strict equality so null is not implicitly allowed
  • DomainTest.php — added testAllowEmpty() covering default rejection, opt-in acceptance of '', continued rejection of null, and that normal valid/invalid domain rules are unaffected

Usage

$validator = new Domain(restrictions: [], hostnames: true, allowEmpty: true);

$validator->isValid('');            // true
$validator->isValid(null);          // false
$validator->isValid('example.com'); // true

Follows the same pattern already established in the URL validator.

@Meldiron Meldiron marked this pull request as ready for review April 27, 2026 16:20
@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented Apr 27, 2026

Greptile Summary

This PR adds an opt-in allowEmpty constructor flag to Domain that lets callers accept an empty string while still rejecting null, false, and all other invalid values. The implementation is minimal and correct: strict === equality prevents any PHP type-coercion widening, the early-return is placed before the existing empty() guard, and the new test covers the key boundary conditions. The previously-reported parse error (testRestrictions() missing its function declaration) is resolved in this revision.

Confidence Score: 5/5

Safe to merge — no logic errors, security concerns, or regressions identified.

The change is a small, isolated, additive feature with correct strict-equality guards and a default of false that preserves existing behavior. All previously-flagged issues (parse error in DomainTest.php) appear resolved.

No files require special attention.

Important Files Changed

Filename Overview
src/Validator/Domain.php Added bool $allowEmpty = false constructor parameter and a strict-equality early-return for ''; logic is correct and null/false/0 are not implicitly widened.
tests/Validator/DomainTest.php Added testAllowEmpty() covering default rejection, opt-in acceptance of '', rejection of null and integers, and valid/invalid domain rules; testRestrictions() declaration is intact (previously-reported parse error is resolved).

Reviews (2): Last reviewed commit: "Apply suggestions from code review" | Re-trigger Greptile

Comment thread tests/Validator/DomainTest.php
@Meldiron
Copy link
Copy Markdown
Contributor

@copilot I dont see your last fixes. are you sure you commited and pushed changes?

Comment thread tests/Validator/DomainTest.php
Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>
@Meldiron Meldiron merged commit 5d7d494 into main Apr 27, 2026
4 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